@motion-studio/cli 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +309 -2
- package/dist/main.js +57589 -0
- package/dist/mcp-studio.mjs +213 -0
- package/dist/runtime/clock.js +1 -0
- package/dist/runtime/index.html +14 -0
- package/dist/runtime/layer.js +1 -0
- package/dist/runtime/preview.js +62 -0
- package/dist/runtime/runtime.js +1 -0
- package/dist/web/apple-touch-icon.png +0 -0
- package/dist/web/assets/index-CNoW5Xwv.js +34 -0
- package/dist/web/assets/index-DRjYoSZ9.css +1 -0
- package/dist/web/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-cyrillic-400-normal-ugxPyKxw.woff +0 -0
- package/dist/web/assets/jetbrains-mono-cyrillic-500-normal-DJqRU3vO.woff +0 -0
- package/dist/web/assets/jetbrains-mono-cyrillic-500-normal-DmUKJPL_.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-greek-400-normal-B9oWc5Lo.woff +0 -0
- package/dist/web/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-greek-500-normal-D7SFKleX.woff +0 -0
- package/dist/web/assets/jetbrains-mono-greek-500-normal-JpySY46c.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
- package/dist/web/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-500-normal-CJOVTJB7.woff +0 -0
- package/dist/web/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-ext-400-normal-fXTG6kC5.woff +0 -0
- package/dist/web/assets/jetbrains-mono-latin-ext-500-normal-Cut-4mMH.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-ext-500-normal-ckzbgY84.woff +0 -0
- package/dist/web/assets/jetbrains-mono-vietnamese-400-normal-CqNFfHCs.woff +0 -0
- package/dist/web/assets/jetbrains-mono-vietnamese-500-normal-DNRqzVM1.woff +0 -0
- package/dist/web/assets/logo-Dd9VMLzB.svg +3 -0
- package/dist/web/assets/logo-dark-Yi8yb5WJ.svg +3 -0
- package/dist/web/assets/logo-horizontal-Blb7HKgj.svg +3 -0
- package/dist/web/assets/logo-horizontal-dark-B16it8f0.svg +3 -0
- package/dist/web/assets/react-VlNyIE0d.js +9 -0
- package/dist/web/assets/schibsted-grotesk-latin-400-normal-BkiRe4WW.woff +0 -0
- package/dist/web/assets/schibsted-grotesk-latin-400-normal-DPhJBilQ.woff2 +0 -0
- package/dist/web/assets/schibsted-grotesk-latin-500-normal-Ba39e-CX.woff +0 -0
- package/dist/web/assets/schibsted-grotesk-latin-500-normal-rf9C4Thp.woff2 +0 -0
- package/dist/web/assets/schibsted-grotesk-latin-600-normal-BieE9YjJ.woff +0 -0
- package/dist/web/assets/schibsted-grotesk-latin-600-normal-Czv9Obfv.woff2 +0 -0
- package/dist/web/assets/schibsted-grotesk-latin-700-normal-BkH0uJ1o.woff2 +0 -0
- package/dist/web/assets/schibsted-grotesk-latin-700-normal-Dz-okVa0.woff +0 -0
- package/dist/web/assets/schibsted-grotesk-latin-ext-400-normal-DHVTfbSM.woff2 +0 -0
- package/dist/web/assets/schibsted-grotesk-latin-ext-400-normal-DUPvg9bQ.woff +0 -0
- package/dist/web/assets/schibsted-grotesk-latin-ext-500-normal-BjmYCtCC.woff +0 -0
- package/dist/web/assets/schibsted-grotesk-latin-ext-500-normal-Ch1izu81.woff2 +0 -0
- package/dist/web/assets/schibsted-grotesk-latin-ext-600-normal-C5pQPdUJ.woff2 +0 -0
- package/dist/web/assets/schibsted-grotesk-latin-ext-600-normal-DQsnXf5q.woff +0 -0
- package/dist/web/assets/schibsted-grotesk-latin-ext-700-normal-DDW2aNyx.woff +0 -0
- package/dist/web/assets/schibsted-grotesk-latin-ext-700-normal-o210KhU4.woff2 +0 -0
- package/dist/web/assets/shared-DLFCfgVy.js +29 -0
- package/dist/web/assets/vendor-CfFIcVU3.css +1 -0
- package/dist/web/assets/vendor-IQO2I6nB.js +57 -0
- package/dist/web/favicon.ico +0 -0
- package/dist/web/favicon.svg +3 -0
- package/dist/web/icon-192.png +0 -0
- package/dist/web/icon-512-maskable.png +0 -0
- package/dist/web/icon-512.png +0 -0
- package/dist/web/index.html +22 -0
- package/dist/web/site.webmanifest +15 -0
- package/package.json +51 -4
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import{r as i,j as s,a as ma,c as sj}from"./react-VlNyIE0d.js";import{h as tj,i as nj,j as aj,k as rj,m as lj,q as ij,t as oj,v as cj}from"./vendor-IQO2I6nB.js";import{m as al,r as dj,e as uj,i as mj,s as _n,L as nc,K as hj,a as uh,b as Zi,c as nx,f as Su,p as kt,S as ei,d as fj,g as ac,h as Cu,R as pj,j as xj,Q as Pr,k as gj,l as vj,n as bj,o as rc,q as ax,t as rx,u as Bl,v as jj,w as lc,x as Eu,y as jo,z as Dn,A as yj,D as Tu,B as wj,C as _c,E as yo,F as wo,G as kj,H as Nj,I as Sj,J as qc,M as mh,N as ko,O as Cj,P as lx,T as ix,U as Ej,V as Rl,W as Od,X as ox,Y as cx,Z as Tj,_ as Rj,$ as Mj,a0 as Ar,a1 as $j,a2 as Fj,a3 as hh,a4 as Pj,a5 as Aj,a6 as ic,a7 as dx,a8 as Ul,a9 as Lj,aa as ji,ab as fh,ac as yi,ad as Ij,ae as zj,af as Oj,ag as ux,ah as Dj,ai as No,aj as mx,ak as Bj,al as Uj,am as _j,an as qj,ao as Vj,ap as Kj,aq as Wj,ar as ph,as as pl,at as Hj,au as Gj,av as Xj,aw as Zj,ax as So,ay as Jj,az as Yj,aA as Qj,aB as xh,aC as hx,aD as si,aE as fx,aF as ey,aG as sy,aH as ty,aI as rl,aJ as _l,aK as Ru,aL as ny,aM as ur,aN as ay,aO as ry,aP as ly,aQ as iy,aR as px,aS as xx,aT as gx,aU as oy,aV as cy,aW as dy,aX as Ja,aY as vx,aZ as uy,a_ as gh,a$ as my,b0 as hy,b1 as fy,b2 as bx,b3 as py,b4 as xy,b5 as ql,b6 as gy,b7 as jx,b8 as yx,b9 as vy,ba as by,bb as jy,bc as wi,bd as yy,be as Dd,bf as Bd,bg as wy,bh as vh,bi as ky,bj as Ny,bk as Br,bl as Sy,bm as Ga,bn as Cy,bo as Ey,bp as Ty,bq as Ry,br as My,bs as $y,bt as Fy}from"./shared-DLFCfgVy.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))a(r);new MutationObserver(r=>{for(const l of r)if(l.type==="childList")for(const o of l.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&a(o)}).observe(document,{childList:!0,subtree:!0});function n(r){const l={};return r.integrity&&(l.integrity=r.integrity),r.referrerPolicy&&(l.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?l.credentials="include":r.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function a(r){if(r.ep)return;r.ep=!0;const l=n(r);fetch(r.href,l)}})();const Mu=()=>dj("system",typeof navigator>"u"?[]:navigator.languages);let Ji=null;const wx=i.createContext(null);function Py({locale:e,children:t}){return Ji=e,i.useEffect(()=>(document.documentElement.lang=e,Ji=e,()=>{Ji=null}),[e]),s.jsx(wx.Provider,{value:e,children:t})}function rs(){return i.useContext(wx)??Mu()}function V(){return al(rs())}function Ay(){return al(Ji??Mu())}function bh(){return Mu()}const Wr={hour:"2-digit",minute:"2-digit"};function ca(e,t,n){const a=new Date(t);return Number.isNaN(a.getTime())?t:new Intl.DateTimeFormat(e,n).format(a)}function Vs(e,t,n){return new Intl.NumberFormat(e,n).format(t)}function $u(e,t,n=Date.now()){const a=new Date(t);if(Number.isNaN(a.getTime()))return t;const r=d=>new Date(d.getFullYear(),d.getMonth(),d.getDate()).getTime(),l=new Date(n),o=Math.round((r(l)-r(a))/864e5),c=new Intl.RelativeTimeFormat(e,{numeric:"auto"});return o<=0?`${c.format(0,"day")} ${new Intl.DateTimeFormat(e,{hour:"2-digit",minute:"2-digit",hour12:!1}).format(a)}`:o===1?c.format(-1,"day"):ca(e,t,a.getFullYear()===l.getFullYear()?{day:"numeric",month:"short"}:{day:"numeric",month:"short",year:"numeric"})}const Ly=[["second",60],["minute",60],["hour",24],["day",7]];function ll(e,t,n=Date.now()){const a=new Date(t).getTime();if(Number.isNaN(a))return t;const r=new Intl.RelativeTimeFormat(e,{numeric:"auto",style:"short"});let l=Math.max(0,(n-a)/1e3);if(l<45)return r.format(0,"second");for(const[o,c]of Ly){if(l<c)return r.format(-Math.round(l),o);l/=c}return ca(e,t)}const kx="motion-studio-ui-token",Iy=/^#t=([0-9a-f]{64})/;let fr=null,xr=!1;const Vl=new Set,Co=new Set,Kl=e=>{for(const t of[...e])t()};function Nx(){const e=Iy.exec(location.hash);return e?(fr=e[1],Fu(fr),history.replaceState(null,"","#/"),Kl(Co),xr&&(xr=!1,Kl(Vl)),!0):!1}function zy(){const e=()=>{Nx()};return addEventListener("hashchange",e),()=>removeEventListener("hashchange",e)}const Oy=/^[0-9a-f]{64}$/,Sx=()=>{try{return localStorage.getItem(kx)}catch{return null}},Fu=e=>{try{localStorage.setItem(kx,e)}catch{}};function Cx(){const e=window.motionStudio;if(e?.isDesktop!==!0||typeof e.uiToken!="function")return null;try{const t=e.uiToken();return typeof t=="string"&&Oy.test(t)?t:null}catch{return null}}function Pu(){if(fr)return fr;const e=Cx();return e?(fr=e,Fu(e),e):Sx()}function Ex(e){const t=Cx()??Sx();return!t||t===e?!1:(t!==fr&&(fr=t,Fu(t),Kl(Co)),xr&&(xr=!1,Kl(Vl)),!0)}function Dy(e){return Co.add(e),()=>{Co.delete(e)}}function jh(){xr||(xr=!0,Kl(Vl))}const Tx=()=>xr;function By(){return i.useSyncExternalStore(e=>(Vl.add(e),()=>{Vl.delete(e)}),Tx)}class lt extends Error{constructor(t,n,a,r,l,o){super(n),this.status=t,this.code=a,this.retryAfterSec=r,this.problems=l,this.dropped=o,this.name="ApiError"}status;code;retryAfterSec;problems;dropped}function Uy(e){const t=e.headers?.get?.("retry-after");if(!(!t||!/^\d{1,6}$/.test(t.trim())))return Number(t.trim())}function Au(e={}){const t=Pu();return t?{...e,"x-motion-studio-ui":t}:e}const yh=async e=>e.status!==401?!1:(await(typeof e.clone=="function"?e.clone():e).json().catch(()=>({}))).code==="ui-token";async function Lu(e){const t=Pu(),n=await e();if(!await yh(n))return n;if(Ex(t)){const a=await e();return await yh(a)&&jh(),a}return jh(),n}async function Iu(e){const t=await e.json().catch(()=>({}));if(!e.ok){const n=t.code,a=t.problems,r=t.dropped;throw new lt(e.status,t.error??Ay().web.api.httpError({status:e.status}),typeof n=="string"?n:void 0,Uy(e),Array.isArray(a)?a.filter(l=>typeof l=="string"):void 0,typeof r=="number"?r:void 0)}return t}async function ve(e,t,n,a={}){const r=await Lu(()=>fetch(t,{method:e,headers:Au(n===void 0?{}:{"content-type":"application/json"}),body:n===void 0?void 0:JSON.stringify(n),...a.keepalive?{keepalive:!0}:{}}));return Iu(r)}async function _y(e){const t=await Lu(()=>fetch(e,{headers:Au()}));return t.ok||await Iu(t),t.blob()}const dr=e=>e.split("/").map(encodeURIComponent).join("/");async function qy(e,t){const n=new FormData;for(const r of t)n.append("files",r,r.name);const a=await Lu(()=>fetch(e,{method:"POST",body:n,headers:Au()}));return Iu(a)}const Fs=e=>`/api/projects/${encodeURIComponent(e)}`,ws=(e,t)=>`${Fs(e)}/creatives/${encodeURIComponent(t)}`,ra=(e,t)=>`${ws(e,t)}/subtitles`,Vy=(e,t,n,a)=>`${ra(e,t)}/${encodeURIComponent(n)}/file.${a}`,q={getUpdatesState:()=>ve("GET","/api/updates"),getDoctor:()=>ve("GET","/api/doctor"),getSetup:()=>ve("GET","/api/setup"),setupInstallClaude:()=>ve("POST","/api/setup/claude/install",{consent:!0}),setupSignIn:()=>ve("POST","/api/setup/claude/login",{consent:!0}),setupInstallFfmpeg:()=>ve("POST","/api/setup/ffmpeg/install",{consent:!0}),setupCancel:e=>ve("POST",`/api/setup/${e}/cancel`),getUsage:(e={})=>{const t=new URLSearchParams(Object.entries(e).filter(n=>typeof n[1]=="string"&&n[1]!=="")).toString();return ve("GET",`/api/usage${t?`?${t}`:""}`)},getProposalActivity:(e,t)=>ve("GET",`${Fs(e)}/brand/proposals/${encodeURIComponent(t)}/activity`),getFirstGenerations:(e=90)=>ve("GET",`/api/usage/first-generations?days=${e}`),getWorkspace:()=>ve("GET","/api/workspace"),setWorkspace:e=>ve("PUT","/api/workspace",{path:e}),updateSettings:e=>ve("PUT","/api/settings",e),setLanguage:e=>ve("PUT","/api/settings/language",{language:e}),getSecrets:()=>ve("GET","/api/secrets"),setSecret:(e,t)=>ve("PUT",`/api/secrets/${e}`,{value:t,check:!1}),checkSecret:e=>ve("POST",`/api/secrets/${e}/check`),getKeyChecks:()=>ve("GET","/api/secrets/checks"),deleteSecret:e=>ve("DELETE",`/api/secrets/${e}`),getApprovals:()=>ve("GET","/api/approvals"),decideApproval:(e,t)=>ve("POST",`/api/approvals/${encodeURIComponent(e)}`,{decision:t}),answerQuestion:(e,t)=>ve("POST",`/api/approvals/${encodeURIComponent(e)}/answer`,{answers:t}),getPermissions:e=>ve("GET",`${Fs(e)}/permissions`),deletePermission:(e,t)=>ve("DELETE",`${Fs(e)}/permissions`,{rule:t}),listProjects:()=>ve("GET","/api/projects"),createProject:(e,t)=>ve("POST","/api/projects",{name:e,description:t}),getProject:e=>ve("GET",`/api/projects/${encodeURIComponent(e)}`),getIntegrity:e=>ve("GET",`${Fs(e)}/integrity`),acceptIntegrity:(e,t)=>ve("POST",`${Fs(e)}/integrity/accept`,{token:t}),updateProject:(e,t)=>ve("PUT",Fs(e),t),getCodebases:e=>ve("GET",`${Fs(e)}/codebases`),getBrand:e=>ve("GET",`${Fs(e)}/brand`),saveBrandKit:(e,t)=>ve("PUT",`${Fs(e)}/brand/kit`,{kit:t}),saveGuidelines:(e,t)=>ve("PUT",`${Fs(e)}/brand/guidelines`,{text:t}),addBrandSource:(e,t)=>ve("POST",`${Fs(e)}/brand/sources`,t),removeBrandSource:(e,t,n)=>ve("DELETE",`${Fs(e)}/brand/sources/${encodeURIComponent(t)}`,void 0,n),analyzeBrand:(e,t)=>ve("POST",`${Fs(e)}/brand/analyze`,{sourceIds:t}),applyProposal:(e,t,n,a)=>ve("POST",`${Fs(e)}/brand/proposals/${encodeURIComponent(t)}/apply`,{acceptedIds:n,applyGuidelines:a}),discardProposal:(e,t)=>ve("POST",`${Fs(e)}/brand/proposals/${encodeURIComponent(t)}/discard`),listAssets:e=>ve("GET",`${Fs(e)}/assets`),uploadFiles:(e,t,n,a={})=>qy(`${Fs(e)}/${t}${t==="assets"&&a.reference?"?scope=reference":""}`,n),setAssetReference:(e,t,n)=>ve("PATCH",`${Fs(e)}/assets/item/${dr(t)}`,{reference:n}),registerAssets:(e,t)=>ve("POST",`${Fs(e)}/assets/register`,{files:t}),describeAssets:(e,t)=>ve("POST",`${Fs(e)}/assets/describe`,{files:t}),updateAsset:(e,t,n)=>ve("PATCH",`${Fs(e)}/assets/item/${dr(t)}`,n),assetWaveform:(e,t)=>ve("GET",`${Fs(e)}/assets/item/${dr(t)}/waveform`),deleteAsset:(e,t,n)=>ve("DELETE",`${Fs(e)}/assets/item/${dr(t)}`,void 0,n),listReferences:e=>ve("GET",`${Fs(e)}/references`),updateReference:(e,t,n)=>ve("PATCH",`${Fs(e)}/references/item/${dr(t)}`,n),deleteReference:(e,t,n)=>ve("DELETE",`${Fs(e)}/references/item/${dr(t)}`,void 0,n),searchGoogleFonts:e=>{const t=new URLSearchParams;return e.q&&t.set("q",e.q),e.category&&t.set("category",e.category),e.limit&&t.set("limit",String(e.limit)),ve("GET",`/api/fonts/google?${t.toString()}`)},listVoices:e=>{const t=new URLSearchParams({provider:e.provider});return e.q&&t.set("q",e.q),ve("GET",`/api/voices?${t.toString()}`)},addGoogleFont:(e,t)=>ve("POST",`${Fs(e)}/brand/fonts/google`,t),projectFileUrl:(e,t)=>`${Fs(e)}/files/${dr(t)}`,generateAsset:(e,t)=>ve("POST",`${Fs(e)}/generate`,t),cancelJob:e=>ve("POST",`/api/jobs/${encodeURIComponent(e)}/cancel`),getAgentCapabilities:()=>ve("GET","/api/agent/capabilities"),stopJob:e=>ve("POST",`/api/jobs/${encodeURIComponent(e)}/stop`),redirectJob:(e,t)=>ve("POST",`/api/jobs/${encodeURIComponent(e)}/redirect`,t),sendConsoleMessage:(e,t)=>ve("POST",`/api/console/${encodeURIComponent(e)}/messages`,t),getBriefSession:e=>ve("GET",`${Fs(e)}/brief-session`),startBriefSession:(e,t)=>ve("POST",`${Fs(e)}/brief-session`,t),getBriefConversation:(e,t)=>ve("GET",`${Fs(e)}/brief-session/${encodeURIComponent(t)}/conversation`),sendBriefMessage:(e,t,n)=>ve("POST",`${Fs(e)}/brief-session/${encodeURIComponent(t)}/messages`,n),saveBriefForm:(e,t,n)=>ve("PUT",`${Fs(e)}/brief-session/${encodeURIComponent(t)}/form`,n),setBriefContext:(e,t,n)=>ve("PUT",`${Fs(e)}/brief-session/${encodeURIComponent(t)}/context`,n),removeBriefQueued:(e,t,n)=>ve("DELETE",`${Fs(e)}/brief-session/${encodeURIComponent(t)}/queue/${encodeURIComponent(n)}`),discardBriefSession:(e,t)=>ve("DELETE",`${Fs(e)}/brief-session/${encodeURIComponent(t)}`),getFormats:()=>ve("GET","/api/formats"),addCustomFormat:e=>ve("POST","/api/formats/custom",e),editCustomFormat:(e,t)=>ve("PUT",`/api/formats/custom/${encodeURIComponent(e)}`,t),deleteCustomFormat:e=>ve("DELETE",`/api/formats/custom/${encodeURIComponent(e)}`),customFormatUsage:e=>ve("GET",`/api/formats/custom/${encodeURIComponent(e)}/usage`),recentCreatives:e=>ve("GET",`/api/recent-creatives${e===void 0?"":`?limit=${e}`}`),listCreatives:e=>ve("GET",`${Fs(e)}/creatives`),listArchivedCreatives:e=>ve("GET",`${Fs(e)}/creatives?archived=1`),creativeRemoval:(e,t)=>ve("GET",`${ws(e,t)}/removal`),archiveCreative:(e,t,n=!1)=>ve("POST",`${ws(e,t)}/archive${n?"?all=1":""}`),unarchiveCreative:(e,t)=>ve("POST",`${ws(e,t)}/unarchive`),deleteCreative:(e,t,n=!1)=>ve("DELETE",`${ws(e,t)}${n?"?all=1":""}`),createCreative:(e,t)=>ve("POST",`${Fs(e)}/creatives`,t),addVariants:(e,t,n)=>ve("POST",`${ws(e,t)}/variants`,n),runVariants:(e,t,n)=>ve("POST",`${ws(e,t)}/variants/run`,n),discardVariant:(e,t,n)=>ve("POST",`${ws(e,t)}/variants/${n}/discard`),restoreVariant:(e,t,n)=>ve("POST",`${ws(e,t)}/variants/${n}/restore`),useVariantForAll:(e,t,n)=>ve("POST",`${ws(e,t)}/variants/${n}/use-for-all`),setVariantPick:(e,t,n,a)=>ve("PUT",`${ws(e,t)}/variants/picks/${encodeURIComponent(n)}`,a),setVariantLayout:(e,t,n)=>ve("PUT",`${ws(e,t)}/variants/layout`,{layout:n}),setVariantDirection:(e,t,n,a)=>ve("PUT",`${ws(e,t)}/variants/${n}/direction`,{direction:a}),createStorePack:(e,t)=>ve("POST",`${Fs(e)}/creatives/store-pack`,t),exportStorePack:(e,t,n,a)=>ve("POST",`${ws(e,t)}/versions/${n}/store-pack/export`,a),getCreative:(e,t)=>ve("GET",ws(e,t)),updateCreative:(e,t,n)=>ve("PUT",ws(e,t),n),duplicateFormat:(e,t,n,a)=>ve("POST",`${ws(e,t)}/versions/${n}/duplicate-format`,a),setExportPick:(e,t,n,a)=>ve("PUT",`${ws(e,t)}/export-picks`,{format:n,version:a}),setFormatLink:(e,t,n,a)=>ve("PUT",`${ws(e,t)}/links`,{follower:n,primary:a}),getConversation:(e,t)=>ve("GET",`${ws(e,t)}/conversation`),sendCreativeTurn:(e,t,n)=>ve("POST",`${ws(e,t)}/turns`,n),postLiveMessage:(e,t,n)=>ve("POST",`${ws(e,t)}/messages`,n),removeQueued:(e,t,n)=>ve("DELETE",`${ws(e,t)}/queue/${encodeURIComponent(n)}`),editQueued:(e,t,n,a)=>ve("PUT",`${ws(e,t)}/queue/${encodeURIComponent(n)}`,a),reorderQueue:(e,t,n)=>ve("PUT",`${ws(e,t)}/queue`,{order:n}),runNext:(e,t)=>ve("POST",`${ws(e,t)}/queue/run-next`),restoreVersion:(e,t,n)=>ve("POST",`${ws(e,t)}/versions/${n}/restore`),revealVersion:(e,t,n)=>ve("POST",`${ws(e,t)}/versions/${n}/reveal`),exportPicks:(e,t,n)=>ve("POST",`${ws(e,t)}/export`,n),exportPicksJob:(e,t,n)=>ve("POST",`${ws(e,t)}/export`,{...n,background:!0}),exportGroupJob:(e,t,n)=>ve("POST",`${ws(e,t)}/export-group`,{...n,background:!0}),groupExportPlan:(e,t)=>ve("GET",`${ws(e,t)}/export-group`),exportGroup:(e,t,n)=>ve("POST",`${ws(e,t)}/export-group`,n),storePackGroupFiles:(e,t)=>ve("GET",`${ws(e,t)}/store-pack/group-files`),exportStorePackGroup:(e,t,n)=>ve("POST",`${ws(e,t)}/store-pack/export-group`,n),prepareExport:(e,t,n)=>ve("POST",`${ws(e,t)}/export/prepare`,n),renderVersion:(e,t,n,a,r={})=>ve("POST",`${ws(e,t)}/versions/${n}/render`,{...a?{formats:a}:{},...r.locales?.length?{locales:r.locales}:{},...r.force?{force:!0}:{}}),useAsBrandLogo:(e,t,n,a,r)=>ve("POST",`${ws(e,t)}/versions/${n}/formats/${encodeURIComponent(a)}/use-as-brand-logo`,{variant:r}),getLocalizations:(e,t,n)=>ve("GET",`${ws(e,t)}/versions/${n}/localizations`),getLocalization:(e,t,n,a,r)=>ve("GET",`${ws(e,t)}/versions/${n}/localizations/${encodeURIComponent(a)}/${encodeURIComponent(r)}`),saveLocalization:(e,t,n,a,r,l)=>ve("PUT",`${ws(e,t)}/versions/${n}/localizations/${encodeURIComponent(a)}/${encodeURIComponent(r)}`,l),localize:(e,t,n,a)=>ve("POST",`${ws(e,t)}/versions/${n}/localize`,a),getLocalizedComposition:(e,t,n,a,r)=>ve("GET",`${ws(e,t)}/versions/${n}/compositions/${encodeURIComponent(a)}?locale=${encodeURIComponent(r)}`),attachLocalePreview:(e,t,n,a,r,l)=>ve("POST",`${ws(e,t)}/versions/${n}/localizations/${encodeURIComponent(a)}/${encodeURIComponent(r)}/preview-assets`,{token:l}),previewSession:(e,t,n,a,r,l)=>ve("POST",`${ws(e,t)}/versions/${n}/preview-session`,{format:a,parentOrigin:r,...l?{renewFrom:l}:{}}),getEditorComposition:(e,t,n,a)=>ve("GET",`${ws(e,t)}/versions/${n}/compositions/${encodeURIComponent(a)}`),stageEditorAsset:(e,t,n)=>ve("POST",`${ws(e,t)}/editor/stage`,n),getEditorSvg:(e,t,n,a)=>ve("GET",`${ws(e,t)}/editor/svg?token=${encodeURIComponent(n)}&path=${encodeURIComponent(a)}`),stageSvgEdit:(e,t,n)=>ve("POST",`${ws(e,t)}/editor/stage`,n),saveEdits:(e,t,n)=>ve("POST",`${ws(e,t)}/edits`,n),revokePreview:(e,t,n,a)=>ve("DELETE",`${ws(e,t)}/versions/${n}/preview-session/${encodeURIComponent(a)}`,void 0,{keepalive:!0}),getStoryboard:(e,t,n,a)=>ve("GET",`${ws(e,t)}/versions/${n}/storyboards/${encodeURIComponent(a)}`),getPinFrames:(e,t,n)=>ve("GET",`${ws(e,t)}/pin-frames/${n}`),getRenderEngine:()=>ve("GET","/api/render-engine"),getChromeDownloadInfo:()=>ve("GET","/api/render-engine/download-info"),downloadChrome:e=>ve("POST","/api/render-engine/download",{consent:!0,sizeBytes:e}),listVideoAnalyses:e=>ve("GET",`${Fs(e)}/video-analyses`),videoAnalysis:(e,t)=>ve("GET",`${Fs(e)}/video-analyses/view?file=${encodeURIComponent(t)}`),analyzeVideo:(e,t,n)=>ve("POST",`${Fs(e)}/video-analyses`,n?{file:t,overwrite:!0}:{file:t}),confirmLongVideo:(e,t,n)=>ve("POST",`${Fs(e)}/video-analyses/confirm-long`,{file:t,density:n}),saveAnalysisBody:(e,t,n)=>ve("PUT",`${Fs(e)}/video-analyses/body`,{file:t,body:n}),cancelVideoAnalysis:(e,t)=>ve("DELETE",`${Fs(e)}/video-analyses?file=${encodeURIComponent(t)}`),transcriptionChoice:(e,t)=>ve("POST",`${Fs(e)}/video-analyses/transcription-choice`,t),recheckTranscription:(e,t)=>ve("POST",`${Fs(e)}/video-analyses/transcription-recheck`,{file:t}),analysisWait:(e,t)=>ve("GET",`${ws(e,t)}/analysis-wait`),skipAnalysisWait:(e,t)=>ve("POST",`${ws(e,t)}/analysis-wait/skip`),getTranscription:()=>ve("GET","/api/transcription"),saveTranscription:e=>ve("PUT","/api/transcription",e),detectWhisper:()=>ve("POST","/api/transcription/detect"),probeWhisper:e=>ve("POST","/api/transcription/probe",e),downloadWhisperModel:(e,t)=>ve("POST",`/api/transcription/models/${e}/download`,{consent:!0,sizeBytes:t}),removeWhisperModel:e=>ve("DELETE",`/api/transcription/models/${e}`),subtitles:(e,t)=>ve("GET",ra(e,t)),startSubtitles:(e,t,n={})=>ve("POST",ra(e,t),n),subtitlesChoice:(e,t,n)=>ve("POST",`${ra(e,t)}/transcription-choice`,n),subtitlesRecheck:(e,t)=>ve("POST",`${ra(e,t)}/transcription-recheck`),subtitleWaveform:(e,t,n,a)=>ve("GET",`${ra(e,t)}/waveform?version=${n}${a?`&lang=${encodeURIComponent(a)}`:""}`),addSubtitleLanguage:(e,t,n)=>ve("POST",`${ra(e,t)}/languages`,{lang:n}),retranslateSubtitles:(e,t,n,a)=>ve("POST",`${ra(e,t)}/${encodeURIComponent(n)}/retranslate`,a),deleteSubtitleLanguage:(e,t,n)=>ve("DELETE",`${ra(e,t)}/${encodeURIComponent(n)}`),subtitleSet:(e,t,n)=>ve("GET",`${ra(e,t)}/${encodeURIComponent(n)}`),saveSubtitleSet:(e,t,n,a,r)=>ve("PUT",`${ra(e,t)}/${encodeURIComponent(n)}`,a,r),subtitleTimingChecked:(e,t,n,a)=>ve("POST",`${ra(e,t)}/${encodeURIComponent(n)}/timing-checked`,a),subtitleFile:(e,t,n,a)=>_y(Vy(e,t,n,a)),fileUrl:(e,t,n)=>`${ws(e,t)}/files/${n.split("/").map(encodeURIComponent).join("/")}`,fileBytes:async e=>{const t=await fetch(e,{method:"HEAD"}).catch(()=>null),n=t?.ok?t.headers.get("content-length"):null,a=n===null||n===""?NaN:Number(n);return Number.isFinite(a)&&a>=0?a:null}},Rx=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),wh=e=>Rx(e)&&typeof e.command=="string"?e.command:"",kh=2e3;function Ky(e){if(e.length<=kh)return e;const t=e.slice(0,kh-1),n=t.charCodeAt(t.length-1);return`${n>=55296&&n<=56319?t.slice(0,-1):t}…`}const Vc="/␀motion-studio-unknown";function Mx(e,t,n){let a=typeof e=="string"&&e.startsWith("/")?e:null;for(;a&&a.length>1&&a.endsWith("/");)a=a.slice(0,-1);a==="/"&&(a=null);const r=a?`${a}/${t}`:`${Vc}/project`,l=a?/^\/(?:Users|home)\/[^/]+/.exec(a):null;return{projectDir:r,cwd:r,home:l?l[0]:`${Vc}/home`,opaqueRoot:Vc,...n?{workDir:`${r}/creatives/${n}/work`}:{}}}const zu=i.createContext(null);function Wy(e,t){try{return uj("Bash",e,t)}catch{return null}}function $x(e,t,n){const a=new Map,r=new Map,l=new Set,o=[];let c;for(const w of e)Rx(w)&&(w.kind==="approval_decided"&&w.toolName==="Bash"&&typeof w.toolUseId=="string"?a.set(w.toolUseId,w.decision):w.kind==="tool_result"&&typeof w.toolUseId=="string"?r.set(w.toolUseId,w.isError===!0):w.kind==="tool_use"&&w.name==="Bash"&&typeof w.id=="string"?(l.add(w.id),o.push(wh(w.input))):w.kind==="session"&&typeof w.sandboxed=="boolean"&&c===void 0&&(c=w.sandboxed));const d=new Map,m=new Map,u=new Map;o.forEach((w,j)=>{const S=Ky(w),k=u.get(S);k?k.push(j):u.set(S,[j])});const h=new Map,f=new Set;let x=!1;for(const w of e)if(!(w.kind!=="auto_approved"||w.toolName!=="Bash")){if(x=!0,typeof w.toolUseId=="string"&&l.has(w.toolUseId)){d.set(w.toolUseId,w.explanation),f.add(w);continue}if(w.toolUseId===void 0&&typeof w.command=="string"){const j=u.get(w.command),S=h.get(w.command)??0;j&&S<j.length&&(h.set(w.command,S+1),m.set(j[S],w.explanation),f.add(w))}}const p=[];let g=0,b=0,v=!1,y=-1;return e.forEach((w,j)=>{const S=`c${j}`;if(w.kind==="tool_use"&&w.name==="Bash"&&typeof w.id=="string"){y++;const k=a.get(w.id),E=k==="once"||k==="always"?"approved":k==="deny"?"denied":k==="expired"||k==="cancelled"?"notRun":r.get(w.id)===!0?"error":!r.has(w.id)&&n.finished?"interrupted":"auto",N=E!=="denied"&&E!=="notRun";N&&g++,E==="approved"&&b++,E==="interrupted"&&(v=!0);const C=d.get(w.id)??m.get(y);p.push({kind:"command",key:S,command:wh(w.input),explanation:C??Wy(w.input,t),mark:E,counted:N})}else w.kind==="auto_approved"&&!f.has(w)&&(w.toolName==="Read"?p.push({kind:"read",key:S,file:typeof w.command=="string"?w.command:"",explanation:w.explanation??null}):(g++,p.push({kind:"command",key:S,command:typeof w.command=="string"?w.command:"",explanation:w.explanation??null,mark:"auto",counted:!0})))}),{rows:p,ran:g,approved:b,attempted:v,sandboxed:c??n.sandboxedHint??x}}const qs={xs:120,s:200,m:320,l:480},Vt={std:"cubic-bezier(.2,0,0,1)",out:"cubic-bezier(.16,1,.3,1)",in:"cubic-bezier(.4,0,1,1)",spring:"cubic-bezier(.34,1.56,.64,1)"};function wr(){return typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches}const oc=e=>e.finished.then(()=>!0,()=>!1);function qn(e,t,n=qs.m,a=Vt.out,r=0){return!e||wr()||typeof e.animate!="function"?Promise.resolve(!0):oc(e.animate(t,{duration:n,easing:a,delay:r,fill:"backwards"}))}function Gs(e,t={}){if(!e)return Promise.resolve();const{x:n=0,y:a=8,scale:r=1,delay:l=0,ms:o=qs.m,ease:c=Vt.out}=t;return typeof e.getAnimations=="function"&&e.getAnimations().forEach(d=>d.cancel()),qn(e,[{opacity:0,transform:`translate(${n}px,${a}px) scale(${r})`},{opacity:1,transform:"none"}],o,c,l).then(()=>{})}function gr(e,t={}){if(!e||wr()||typeof e.animate!="function")return Promise.resolve(!0);const{x:n=0,y:a=0,ms:r=qs.s}=t;return oc(e.animate([{opacity:1,transform:"none"},{opacity:0,transform:`translate(${n}px,${a}px)`}],{duration:r,easing:Vt.in,fill:"forwards"}))}function Fx(e,t=qs.m){return!e||wr()||typeof e.animate!="function"?Promise.resolve(!0):oc(e.animate([{opacity:1,transform:"none"},{opacity:0,transform:"scale(0.98)"}],{duration:t,easing:Vt.in,fill:"forwards"}))}function il(e,t=qs.m){if(!e||wr()||typeof e.animate!="function")return Promise.resolve(!0);const n=e.offsetHeight;return oc(e.animate([{height:`${n}px`,opacity:1},{height:"0px",opacity:0,paddingTop:"0px",paddingBottom:"0px",marginTop:"0px",marginBottom:"0px",borderTopWidth:"0px",borderBottomWidth:"0px"}],{duration:t,easing:Vt.in,fill:"forwards"}))}function Ud(e,t={},n=30){return Promise.all([...e].map((a,r)=>Gs(a,{...t,delay:(t.delay??0)+r*n}))).then(()=>{})}function ti(e){return qn(e,[{transform:"scale(.7)"},{transform:"scale(1.18)"},{transform:"scale(1)"}],520,Vt.spring).then(()=>{})}function cc(e){return qn(e,[{boxShadow:"0 0 0 0 rgba(255,90,31,.45)"},{boxShadow:"0 0 0 10px rgba(255,90,31,0)"}],900,Vt.out).then(()=>{})}function Yi(e){return qn(e,[{boxShadow:"inset 0 0 0 1px #FF5A1F, 0 0 0 3px rgba(255,90,31,.25)"},{boxShadow:"inset 0 0 0 1px transparent, 0 0 0 0 transparent"}],800,Vt.std).then(()=>{})}function Eo(e,t,n=qs.l){if(!e||!t||wr())return Promise.resolve();const a=e.getBoundingClientRect();if(!a.width||!a.height)return Promise.resolve();const r=t.left-a.left,l=t.top-a.top,o=t.width/a.width,c=t.height/a.height;return e.style.transformOrigin="0 0",qn(e,[{transform:`translate(${r}px,${l}px) scale(${o},${c})`},{transform:"none"}],n,Vt.out).then(()=>{})}function Hy(e,t){if(!e)return Promise.resolve();const n=e.getBoundingClientRect().width;if(!n||Math.abs(n-t)<1)return Promise.resolve();const a=n>t;return qn(e,[{width:`${t}px`},{width:`${n}px`}],a?qs.l:qs.m,a?Vt.spring:Vt.std).then(()=>{})}function Gy(e){return qn(e,[{boxShadow:"inset 0 0 0 1px var(--accent), 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent)"},{boxShadow:"inset 0 0 0 1px var(--line), 0 0 0 0 transparent"}],1600,Vt.std)}function Xy(e,t=0){return qn(e,[{transform:"scale(.94)",offset:0},{transform:"scale(1.02)",offset:.6},{transform:"none",offset:1}],qs.l,Vt.spring,t)}function Ra(e=[]){const t=i.useRef(null);return i.useLayoutEffect(()=>{const n=t.current;n&&n.querySelectorAll("[data-enter]").forEach((a,r)=>{Gs(a,{y:Number(a.dataset.y??8),x:Number(a.dataset.x??0),delay:Number(a.dataset.delay??r*30)})})},e),t}function Px({route:e,keyOf:t,depthOf:n,soft:a,modeOf:r,render:l}){const o=t(e),c=i.useRef(0),d=i.useRef({key:o,depth:n?.(e)??0,route:e}),[m,u]=i.useState(()=>[{id:0,key:o,route:e,dir:1,leaving:!1}]);i.useLayoutEffect(()=>{if(d.current.key===o){u(b=>b.map(v=>!v.leaving&&v.key===o?{...v,route:e}:v));return}const f=n?.(e)??0,x=f>=d.current.depth?1:-1,p=r?.(d.current.route,e);d.current={key:o,depth:f,route:e};const g=++c.current;u(b=>[...b.filter(v=>!v.leaving).map(v=>({...v,dir:x,mode:p,leaving:!0})),{id:g,key:o,route:e,dir:x,mode:p,leaving:!1}])},[o,e]);const h=f=>u(x=>x.filter(p=>p.id!==f));return s.jsx("div",{className:"ms-stage",children:m.map(f=>s.jsx(Zy,{leaving:f.leaving,dir:f.dir,soft:a,mode:f.mode,onGone:()=>h(f.id),children:l(f.route)},f.id))})}function Zy({leaving:e,dir:t,soft:n,mode:a,onGone:r,children:l}){const o=i.useRef(null),c=i.useRef(r);return c.current=r,i.useLayoutEffect(()=>{const d=a==="shared";e?(d?Fx(o.current,t>0?qs.m:qs.s):gr(o.current,{x:n?0:-t*16,ms:qs.s})).then(u=>{u&&c.current()}):d?Gs(o.current,{x:0,y:0,ms:t>0?qs.m:qs.s}):Gs(o.current,{x:n?0:t*24,y:n?6:0,ms:qs.m})},[e]),s.jsx("div",{className:"ms-page",ref:o,"data-page-active":e?void 0:"",style:{pointerEvents:e?"none":"auto",zIndex:e?0:1},children:l})}function Pt(){return typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent)}function Ou(e){if(!e||!e.isConnected)return!1;for(let t=e.closest(".ms-page");t;t=t.parentElement?.closest(".ms-page")??null)if(!t.hasAttribute("data-page-active"))return!1;return!0}function qt(e,t,n){const a=i.useRef({match:t,run:n});a.current={match:t,run:n},i.useEffect(()=>{const r=l=>{l.repeat||l.defaultPrevented||!a.current.match(l)||!Ou(e.current)||(l.preventDefault(),a.current.run(l))};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e])}function dc(e){return e.key!=="Enter"||e.isComposing||e.altKey?!1:Pt()?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey}const Jy=["brand","assets","references","settings"],Yy=["general","system","paid","transcription","usage","notifications","updates"],Ha="[a-z0-9][a-z0-9-]*",Qi=`${Ha}(?:~(?:[b-z]|[a-z]{2,3}))?`,Ax="[a-z0-9][a-z0-9-]{0,62}(?:(?:@|%40)(?:[2-9]|1[0-9]|20))?",Lx=new RegExp(`^#/p/(${Ha})/console$`),Qy=new RegExp(`^(#/p/${Ha}/c/${Qi}/f/${Ax})/edit$`);function ew(e){const t=e.match(Lx);if(t)return`#/p/${t[1]}`;const n=e.match(Qy);return n?n[1]:null}function Ix(e){if(e==="#/settings")return{name:"settings",section:"general"};let t=e.match(/^#\/settings\/([a-z]+)$/);if(t){const n=t[1];return Yy.includes(n)?{name:"settings",section:n}:{name:"projects"}}if(e==="#/welcome")return{name:"welcome"};if(t=e.match(/^#\/welcome\/([123])$/),t)return{name:"welcome",step:Number(t[1])};if(t=e.match(new RegExp(`^#/p/(${Ha})/c/(${Qi})/f/(${Ax})(?:/edit)?$`)),t)return{name:"format",slug:t[1],creative:t[2],format:sw(t[3])};if(t=e.match(new RegExp(`^#/p/(${Ha})/c/(${Qi})/subtitles(?:/([A-Za-z-]+))?$`)),t)return t[3]===void 0?{name:"subtitles",slug:t[1],creative:t[2]}:mj(t[3])?{name:"subtitles",slug:t[1],creative:t[2],lang:t[3]}:{name:"creative",slug:t[1],creative:t[2]};if(t=e.match(new RegExp(`^#/p/(${Ha})/c/(${Qi})$`)),t)return{name:"creative",slug:t[1],creative:t[2]};if(t=e.match(new RegExp(`^#/p/(${Ha})/new$`)),t)return{name:"new-creative",slug:t[1]};if(t=e.match(Lx),t)return{name:"project",slug:t[1],tab:"creatives"};if(t=e.match(new RegExp(`^#/p/(${Ha})(?:/([a-z]+))?$`)),t){const n=t[2]??"creatives";if(n==="creatives"||Jy.includes(n))return{name:"project",slug:t[1],tab:n}}return{name:"projects"}}function sw(e){try{return decodeURIComponent(e)}catch{return e}}const es={welcome:e=>e?`#/welcome/${e}`:"#/welcome",projects:()=>"#/",settings:(e="general")=>`#/settings/${e}`,project:(e,t="creatives")=>t==="creatives"?`#/p/${e}`:`#/p/${e}/${t}`,newCreative:e=>`#/p/${e}/new`,creative:(e,t)=>`#/p/${e}/c/${t}`,format:(e,t,n)=>`#/p/${e}/c/${t}/f/${n}`,subtitles:(e,t,n)=>`#/p/${e}/c/${t}/subtitles${n?`/${n}`:""}`};function tw(e){switch(e.name){case"welcome":return 0;case"projects":return 1;case"settings":case"project":return 2;case"new-creative":case"creative":return 3;case"format":case"subtitles":return 4}}function Zn(e){switch(e.name){case"welcome":case"projects":case"settings":return e.name;case"project":return`project:${e.slug}`;case"new-creative":return`new:${e.slug}`;case"creative":return`creative:${e.slug}/${e.creative}`;case"format":return`format:${e.slug}/${e.creative}/${e.format}`;case"subtitles":return`subtitles:${e.slug}/${e.creative}`}}function zx(e){return e.name==="project"||e.name==="new-creative"||e.name==="creative"||e.name==="format"||e.name==="subtitles"?e.slug:null}function Ox(){return xt()?"noopener":"noopener noreferrer"}function xt(){const e=window.motionStudio;return e?.isDesktop===!0&&typeof e.pickFolder=="function"&&typeof e.revealPath=="function"?e:null}function Du(e,t,n){return n.length===1?e.revealPath(n[0]):typeof e.openFolder=="function"?e.openFolder(t):e.revealPath(n[0]??t)}const Dx="motion-studio.notifyApprovals",Kc="Motion Studio",nw=99,aw=200;function Nh(e,t=aw){if(e.length<=t)return e;let n=e.slice(0,t-1);return/[\uD800-\uDBFF]$/.test(n)&&(n=n.slice(0,-1)),`${n}…`}function Bx(){try{return localStorage.getItem(Dx)!=="false"}catch{return!0}}function rw(e){try{localStorage.setItem(Dx,String(e))}catch{}}const Ux="motion-studio.notifyReady";function _x(){try{return localStorage.getItem(Ux)!=="false"}catch{return!0}}function lw(e){try{localStorage.setItem(Ux,String(e))}catch{}}const qx="motion-studio.notifySound";function Vx(){try{return localStorage.getItem(qx)!=="false"}catch{return!0}}function iw(e){try{localStorage.setItem(qx,String(e))}catch{}}function _d(){try{return document.visibilityState==="hidden"||!document.hasFocus()}catch{return!1}}function uc(e){try{Promise.resolve(e()).catch(()=>{})}catch{}}const ow=5e3;function cw(e){if(!e||typeof e!="object"||!("shown"in e))return{state:"unconfirmed"};if(e.shown===!0)return{state:"sent"};const{detail:t,reason:n}=e,a=n==="timeout"||n==="unsupported"?n:"failed";return typeof t=="string"&&t?{state:"blocked",reason:a,detail:t}:{state:"blocked",reason:a}}function dw(e){return new Promise(t=>{const n=setTimeout(()=>t({state:"blocked"}),ow);e.onshow=()=>{clearTimeout(n),t({state:"sent"})},e.onerror=()=>{clearTimeout(n),t({state:"blocked"})}})}async function Kx(e,t=!1){const n={title:Nh(e.title),body:Nh(e.body),sound:Vx()},a=xt();if(typeof a?.notify=="function")return cw(await a.notify(n));if(typeof Notification>"u")throw new Error("unsupported");if(Notification.permission!=="granted")throw new Error(Notification.permission);const r=document.visibilityState==="hidden"||!document.hasFocus();return t&&!r?{state:"skipped"}:dw(new Notification(n.title,{body:n.body,silent:!n.sound}))}function To(e){uc(()=>Kx(e,!0))}async function uw(){const e=xt();if(e){if(typeof e.notifyStatus!="function")return"ok";try{return(await e.notifyStatus()).supported?"ok":"unsupported"}catch{return"unsupported"}}if(typeof Notification>"u")return"unsupported";const t=Notification.permission;return t==="granted"?"ok":t==="denied"?"denied":"default"}function mw(e){const t=xt();if(typeof t?.onAttentionClick!="function")return()=>{};try{return t.onAttentionClick(e)}catch{return()=>{}}}function Sh(e){const t=xt();typeof t?.setBadge=="function"&&uc(()=>t.setBadge(Math.max(0,Math.min(nw,Math.trunc(e)))))}function Ch(e){const t=xt();typeof t?.setRendersRunning=="function"&&uc(()=>t.setRendersRunning(Math.max(0,Math.min(1e3,Math.trunc(e)))))}function Eh(e){const t=xt();typeof t?.setDraftsUnsaved=="function"&&uc(()=>t.setDraftsUnsaved(Math.max(0,Math.min(1e3,Math.trunc(e)))))}function hw(){return!xt()&&typeof Notification<"u"&&Notification.permission==="default"}const Mn=i.createContext(null);function ol(){const e=i.useContext(Mn);if(!e)throw new Error("useShell outside the shell");return e}function Bs(e){location.hash!==e&&(location.hash=e)}const le=(...e)=>e.filter(Boolean).join(" "),Ya={play:"M5 3.5v9l7.5-4.5L5 3.5Z",back:"M10 3.5 5.5 8l4.5 4.5",chevron:"M4.5 6 8 9.5 11.5 6",plus:"M8 3v10M3 8h10",close:"m4 4 8 8M12 4l-8 8",check:"m3.5 8.5 3 3 6-6.5",search:"M7 12a5 5 0 1 0 0-10 5 5 0 0 0 0 10ZM11 11l3.5 3.5",bell:"M4 11V7a4 4 0 0 1 8 0v4l1 1.5H3L4 11ZM6.5 14h3",gear:"M8 5.8a2.2 2.2 0 1 0 0 4.4 2.2 2.2 0 0 0 0-4.4ZM8 1.8v1.8M8 12.4v1.8M1.8 8h1.8M12.4 8h1.8M3.6 3.6l1.3 1.3M11.1 11.1l1.3 1.3M3.6 12.4l1.3-1.3M11.1 4.9l1.3-1.3",folder:"M2 4.5h4l1.5 1.5H14v6.5H2Z",send:"M14 2 7 9M14 2l-4.5 12-2.5-5.5L1.5 6 14 2Z",upload:"M8 11V3M5 6l3-3 3 3M3 13h10",download:"M8 3v8M5 8l3 3 3-3M3 13h10",link:"M7 9 9 7M6.5 7.5 4.6 9.4a2.1 2.1 0 0 0 3 3L9.5 10.5M9.5 8.5l1.9-1.9a2.1 2.1 0 0 0-3-3L6.5 5.5",globe:"M8 2a6 6 0 1 0 0 12A6 6 0 0 0 8 2ZM2 8h12M8 2c2 2 2 10 0 12M8 2c-2 2-2 10 0 12",video:"M2 4h12v8H2ZM6.8 6.3v3.4L9.6 8Z",image:"M2 3.5h12v9H2ZM3.5 11l3-3 2 2 1.5-1.5L12.5 11",comment:"M3 3h10v7H7l-3 3v-3H3V3Z",hand:"M5 8V4.5a1 1 0 0 1 2 0V8M7 7V3.5a1 1 0 0 1 2 0V7M9 7V4.5a1 1 0 0 1 2 0V10a4 4 0 0 1-4 4H6.5L3.5 10.5l1.2-1A1 1 0 0 1 6 9.6",cursor:"M3 2.5 12.5 7 8 8.5 6.5 13 3 2.5Z",text:"M3 3.5h10M8 3.5v9M6 12.5h4",crop:"M4 1.5v10h10M1.5 4h10v10",drop:"M10 2.5 13.5 6 6 13.5H2.5V10L10 2.5ZM8.5 4l3.5 3.5",eye:"M1.5 8S4 3.5 8 3.5 14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8ZM8 6a2 2 0 1 0 0 4 2 2 0 0 0 0-4Z",lock:"M4.5 7.5h7v6h-7ZM6 7.5V5.5a2 2 0 0 1 4 0v2",refresh:"M13 8a5 5 0 1 1-1.5-3.5M13 2.5v3h-3",trash:"M2.5 4.5h11M6 4.5V3h4v1.5M4 4.5l.7 9h6.6l.7-9",more:"M4 8h.01M8 8h.01M12 8h.01",shield:"M8 1.5 13.5 4v4c0 3.2-2.3 5.6-5.5 6.5C4.8 13.6 2.5 11.2 2.5 8V4L8 1.5ZM5.5 8l1.8 1.8L10.8 6.3",code:"m5.5 4.5-3.5 3.5 3.5 3.5M10.5 4.5 14 8l-3.5 3.5",sparkle:"M8 1.5v3M8 11.5v3M1.5 8h3M11.5 8h3M3.4 3.4l2.1 2.1M10.5 10.5l2.1 2.1M12.6 3.4l-2.1 2.1M5.5 10.5l-2.1 2.1",chart:"M2 13h12M4 10V7M8 10V3M12 10V5",grid:"M2.5 2.5h4.5v4.5H2.5ZM9 2.5h4.5v4.5H9ZM2.5 9h4.5v4.5H2.5ZM9 9h4.5v4.5H9Z",list:"M2.5 4h11M2.5 8h11M2.5 12h11",star:"m8 2 1.8 3.8 4.2.5-3.1 2.9.8 4.1L8 11.3l-3.7 2 .8-4.1L2 6.3l4.2-.5Z",alignL:"M2.5 4h11M2.5 8h7M2.5 12h9",alignC:"M2.5 4h11M4.5 8h7M3.5 12h9",alignR:"M2.5 4h11M6.5 8h7M4.5 12h9",warn:"M8 2 14.5 13.5h-13ZM8 6.5v3M8 11.5v.5",clock:"M8 2a6 6 0 1 0 0 12A6 6 0 0 0 8 2ZM8 4.5V8l2.5 1.5",terminal:"M2.5 3.5h11v9h-11ZM5 6.5l2 1.5-2 1.5M8.5 10h2.5",key:"M10 2.5a3.5 3.5 0 1 1-3.2 4.9L2.5 11.7v1.8h1.8l.7-.7v-1.3h1.3l1-1",forward:"M6 3.5 10.5 8 6 12.5",menu:"M2.5 4.5h11M2.5 8h11M2.5 11.5h11",minus:"M3 8h10",external:"M9 2.5h4.5V7M13.5 2.5 7.5 8.5M11.5 9.5v4h-9v-9h4",copy:"M5.5 5.5h8v8h-8ZM10.5 5.5v-3h-8v8h3",edit:"M10.5 2.5 13.5 5.5 6 13H3v-3l7.5-7.5Z",pin:"M8 14s4.5-4.2 4.5-7.5a4.5 4.5 0 0 0-9 0C3.5 9.8 8 14 8 14ZM8 5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3Z",pause:"M5.5 3.5v9M10.5 3.5v9",user:"M8 8a2.75 2.75 0 1 0 0-5.5A2.75 2.75 0 0 0 8 8ZM2.5 13.5c.7-2.4 2.9-3.8 5.5-3.8s4.8 1.4 5.5 3.8",undo:"M5.5 3.5 2.5 6.5l3 3M2.5 6.5H9a4 4 0 0 1 0 8H6",redo:"m10.5 3.5 3 3-3 3M13.5 6.5H7a4 4 0 0 0 0 8h3",unlock:"M4.5 7.5h7v6h-7ZM6 7.5V5.5a2 2 0 0 1 3.9-.6",eyeOff:"M1.5 8S4 3.5 8 3.5 14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8ZM2.5 2.5l11 11",rotate:"M13 8a5 5 0 1 1-1.5-3.5M13 2.5v3h-3M8 6v2.5l1.5 1",music:"M6 11.5V3.5l7-1.5v8M6 11.5a1.75 1.75 0 1 1-3.5 0 1.75 1.75 0 0 1 3.5 0ZM13 10a1.75 1.75 0 1 1-3.5 0 1.75 1.75 0 0 1 3.5 0Z",scissors:"M4.5 6a1.75 1.75 0 1 0 0-3.5 1.75 1.75 0 0 0 0 3.5ZM4.5 13.5a1.75 1.75 0 1 0 0-3.5 1.75 1.75 0 0 0 0 3.5ZM6 5l7.5 8M6 11l7.5-8",volume:"M3 6.5h2.5L9 3.5v9L5.5 9.5H3ZM11.5 5.5a3.5 3.5 0 0 1 0 5",mute:"M3 6.5h2.5L9 3.5v9L5.5 9.5H3ZM11 6l3 4M14 6l-3 4",magnet:"M3 13.5v-6a5 5 0 0 1 10 0v6M3 11h2.5M10.5 11H13",plug:"M6 1.5v3M10 1.5v3M4 4.5h8V7a4 4 0 0 1-8 0ZM8 11v3.5"};function F({name:e,size:t=15,strokeWidth:n=1.4,fill:a=!1,className:r}){return s.jsx("svg",{className:r,width:t,height:t,viewBox:"0 0 16 16",fill:a?"currentColor":"none",stroke:"currentColor",strokeWidth:n,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:s.jsx("path",{d:Ya[e]})})}function Ts({size:e=14,label:t,decorative:n,className:a}){const r=V(),l=s.jsxs("svg",{className:le("ms-spin",a),width:e,height:e,viewBox:"0 0 16 16",fill:"none",strokeWidth:2,"aria-hidden":"true",focusable:"false",children:[s.jsx("circle",{cx:"8",cy:"8",r:"5.5",className:"ms-spin-track"}),s.jsx("path",{d:"M8 2.5a5.5 5.5 0 0 1 5.5 5.5",className:"ms-spin-arc",strokeLinecap:"round"})]});return n?l:s.jsx("span",{className:"ms-spinner",role:"status","aria-label":t??r.web.ui.loading,children:l})}function $({variant:e="default",size:t="md",icon:n,loading:a,disabled:r,className:l,type:o="button",children:c,...d}){return s.jsxs("button",{...d,type:o,disabled:r||a,"aria-busy":a||void 0,className:le("ms-btn",e!=="default"&&`ms-${e}`,t!=="md"&&`ms-${t}`,n&&"ms-icon",a&&"ms-busy",l),children:[a?s.jsx(Ts,{decorative:!0,size:t==="sm"?12:14}):null,a&&n?null:c]})}const fw=["instagram","tiktok","youtube","facebook","linkedin","x","pinterest","appstore","googleplay","web","identity","custom"];function da(e){const t=e.toLowerCase().replace(/[^a-z]/g,""),n=t==="playstore"?"googleplay":t;return fw.includes(n)?n:"web"}const pw={instagram:"#C13584",tiktok:"#111111",youtube:"#E62117",facebook:"#1877F2",linkedin:"#0A66C2",x:"#111111",pinterest:"#E60023",appstore:"#0D96F6",googleplay:"#01875F",web:"#525252",identity:"#6D28D9",custom:"#0F766E"},xw="#FFFFFF",gw="M5.3 3.4a2.1 2.1 0 1 0 0 4.2 2.1 2.1 0 0 0 0-4.2ZM3.5 9.1h3.6v11.5H3.5ZM9.4 9.1h3.45v1.57h.05c.48-.91 1.65-1.87 3.4-1.87 3.64 0 4.3 2.4 4.3 5.5v6.3h-3.59v-5.58c0-1.33-.02-3.04-1.85-3.04-1.86 0-2.14 1.45-2.14 2.95v5.67H9.4Z",vw={instagram:cj.path,tiktok:oj.path,youtube:ij.path,facebook:lj.path,linkedin:gw,x:rj.path,pinterest:aj.path,appstore:nj.path,googleplay:tj.path};function en({channel:e,size:t=16,className:n}){const a=V(),r={instagram:a.channels.instagram,tiktok:a.channels.tikTok,youtube:a.channels.youTube,facebook:a.channels.facebook,linkedin:a.channels.linkedIn,x:a.channels.x,pinterest:a.channels.pinterest,appstore:a.channels.appStore,googleplay:a.channels.playStore,web:a.channels.web,identity:a.channels.identity,custom:a.channels.custom},l=t===20?12:10;return s.jsx("span",{className:le("ms-ch",t===20&&"ms-lg",n),style:{background:pw[e],color:xw},role:"img","aria-label":r[e],children:e==="web"||e==="identity"||e==="custom"?s.jsx("svg",{width:l,height:l,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:s.jsx("path",{d:e==="identity"?Ya.star:e==="custom"?Ya.crop:Ya.globe})}):s.jsx("svg",{width:l,height:l,viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",focusable:"false",children:s.jsx("path",{d:vw[e]})})})}function bw({prefix:e,children:t,className:n}){return s.jsxs("label",{className:le("ms-field",n),children:[e?s.jsx("small",{children:e}):null,t]})}function ms({className:e,...t}){return s.jsx("input",{...t,className:le("ms-input",e)})}function nn({className:e,rows:t=3,...n}){return s.jsx("textarea",{...n,rows:t,className:le("ms-input","ms-textarea",e)})}function cl({value:e,min:t,max:n,step:a=1,onChange:r,label:l,valueText:o,disabled:c,className:d}){const m=i.useRef(null),u=i.useRef(()=>{}),h=i.useRef(r);h.current=r,i.useEffect(()=>()=>u.current(),[]);const f=n-t,x=f>0?Math.min(100,Math.max(0,(e-t)/f*100)):0,p=y=>Math.min(n,Math.max(t,Math.round((y-t)/a)*a+t)),g=y=>{const w=m.current?.getBoundingClientRect();return!w||!w.width?null:p(t+(y-w.left)/w.width*f)},b=y=>{if(c||y.button!==0)return;const w=g(y.clientX);w!==null&&h.current(w);const j=k=>{const E=g(k.clientX);E!==null&&h.current(E)};u.current=()=>{window.removeEventListener("pointermove",j),window.removeEventListener("pointerup",S),window.removeEventListener("pointercancel",S),u.current=()=>{}};const S=()=>u.current();window.addEventListener("pointermove",j),window.addEventListener("pointerup",S),window.addEventListener("pointercancel",S)},v=y=>{if(c||y.metaKey||y.ctrlKey||y.altKey)return;const w=y.key==="ArrowRight"||y.key==="ArrowUp"?e+a:y.key==="ArrowLeft"||y.key==="ArrowDown"?e-a:y.key==="PageUp"?e+a*10:y.key==="PageDown"?e-a*10:y.key==="Home"?t:y.key==="End"?n:null;w!==null&&(y.preventDefault(),y.stopPropagation(),r(p(w)))};return s.jsxs("div",{ref:m,className:le("ms-slider",c&&"ms-off",d),role:"slider",tabIndex:c?-1:0,"aria-label":l,"aria-valuemin":t,"aria-valuemax":n,"aria-valuenow":e,"aria-valuetext":o,"aria-disabled":c||void 0,onPointerDown:b,onKeyDown:v,children:[s.jsx("i",{className:"ms-slider-fill",style:{width:`${x}%`},"aria-hidden":"true"}),s.jsx("i",{className:"ms-slider-thumb",style:{left:`${x}%`},"aria-hidden":"true"})]})}const Wx=(e,t)=>{const n=10**t;return Math.round(e*n)/n},Th=(e,t)=>e===null||!Number.isFinite(e)?"":String(Wx(e,t));function Tt({value:e,onChange:t,label:n,prefix:a,unit:r,min:l=-1/0,max:o=1/0,step:c=1,decimals:d=3,startAt:m=0,disabled:u,invalid:h,describedBy:f,onEnd:x,className:p}){const g=i.useId(),[b,v]=i.useState(null),y=i.useRef(null),w=C=>Wx(Math.min(o,Math.max(l,C)),d),j=C=>{const R=C.trim().replace(",",".");if(R===""||!/^[-+]?(\d+\.?\d*|\.\d+)$/.test(R))return null;const P=Number(R);return Number.isFinite(P)?P:null},S=C=>{const R=w(C);return R!==e&&t(R),R},k=()=>{if(b===null)return;const C=j(b);v(null),C!==null&&S(C)},E=C=>{if(u||C.metaKey||C.ctrlKey||C.altKey)return;const R=C.shiftKey?10:1,P=C.key==="ArrowUp"?1:C.key==="ArrowDown"?-1:C.key==="PageUp"?10:C.key==="PageDown"?-10:0;if(P!==0){C.preventDefault();const z=(b!==null?j(b):null)??e??m,O=S(z+P*c*(Math.abs(P)===10?1:R));v(String(O));return}if(C.key==="Enter"){C.preventDefault(),k(),x?.(),y.current?.select();return}C.key==="Escape"&&(b!==null&&(C.preventDefault(),C.stopPropagation(),v(null)),x?.())},N=b??Th(e,d);return s.jsxs("label",{className:le("ms-field",u&&"ms-off",h&&"ms-invalid",p),children:[a?s.jsx("small",{"aria-hidden":"true",children:a}):null,s.jsx("input",{ref:y,id:g,type:"text",inputMode:"decimal",role:"spinbutton",autoComplete:"off",spellCheck:!1,"aria-label":n,"aria-valuenow":e??void 0,"aria-valuemin":Number.isFinite(l)?l:void 0,"aria-valuemax":Number.isFinite(o)?o:void 0,"aria-invalid":h||void 0,"aria-describedby":f,disabled:u,value:N,placeholder:"—",onFocus:()=>v(Th(e,d)),onChange:C=>v(C.target.value),onKeyDown:E,onBlur:()=>{k(),v(null),x?.()}}),r?s.jsx("span",{className:"ms-field-unit","aria-hidden":"true",children:r}):null]})}function jw(e){const t=(e??"").trim().replace(/^#/,"");return/^[0-9a-fA-F]{3,4}$/.test(t)?`#${[...t.slice(0,3)].map(n=>n+n).join("")}`.toLowerCase():/^[0-9a-fA-F]{6}(?:[0-9a-fA-F]{2})?$/.test(t)?`#${t.slice(0,6)}`.toLowerCase():"#000000"}function yw(e,t){const n=(t??"").trim().replace(/^#/,"");return/^[0-9a-fA-F]{4}$/.test(n)?`${e}${n[3]}${n[3]}`:/^[0-9a-fA-F]{8}$/.test(n)?`${e}${n.slice(6)}`:e}function Hx({value:e,onPick:t,disabled:n,className:a,size:r=28}){const l=V(),o=i.useRef(null),c=i.useRef(t);c.current=t;const d=jw(e);return i.useEffect(()=>{o.current&&o.current.value!==d&&(o.current.value=d)},[d]),i.useEffect(()=>{const m=o.current;if(!m)return;const u=()=>c.current(m.value);return m.addEventListener("change",u),()=>m.removeEventListener("change",u)},[]),s.jsxs("label",{className:le("ms-color-pick",n&&"ms-off",a),style:{width:r,height:r},children:[s.jsx("span",{className:"ms-color-chip","aria-hidden":"true",style:e?{background:e}:void 0}),s.jsx("input",{ref:o,type:"color",className:"ms-color-native","aria-label":l.web.ui.pickColor,defaultValue:d,disabled:n})]})}const ww=/^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;function Rh(e){const t=e.trim(),n=t.startsWith("#")?t:`#${t}`;return ww.test(n)?n:null}function ni({value:e,onChange:t,label:n,groups:a=[],disabled:r,invalid:l,describedBy:o,onEnd:c,className:d}){const[m,u]=i.useState(null),h=m!==null?Rh(m):void 0,f=l||m!==null&&m.trim()!==""&&h===null,x=()=>{if(m===null)return;const v=Rh(m);u(null),v&&v.toLowerCase()!==e?.toLowerCase()&&t(v)},p=v=>{v.key==="Enter"?(v.preventDefault(),x(),c?.()):v.key==="Escape"&&(m!==null&&(v.preventDefault(),v.stopPropagation(),u(null)),c?.())},g=m??e??"",b=h??e;return s.jsxs("div",{className:le("ms-color",d),children:[s.jsxs("div",{className:"ms-color-top",children:[s.jsx(Hx,{value:b,disabled:r,onPick:v=>{const y=yw(v,e);u(null),y.toLowerCase()!==e?.toLowerCase()&&t(y),c?.()}}),s.jsx("label",{className:le("ms-field",r&&"ms-off",f&&"ms-invalid"),children:s.jsx("input",{type:"text",autoComplete:"off",spellCheck:!1,"aria-label":n,"aria-invalid":f||void 0,"aria-describedby":o,disabled:r,value:g,placeholder:"#rrggbb",maxLength:9,onFocus:()=>u(e??""),onChange:v=>u(v.target.value),onKeyDown:p,onBlur:()=>{x(),u(null),c?.()}})})]}),s.jsx(Gx,{groups:a,value:e,disabled:r,onPick:v=>{e?.toLowerCase()!==v.toLowerCase()&&t(v),c?.()}})]})}function Gx({groups:e,value:t,disabled:n,onPick:a}){return s.jsx(s.Fragment,{children:e.filter(r=>r.colors.length>0).map(r=>s.jsxs("div",{role:"group","aria-label":r.label,className:"ms-color-group",children:[s.jsx("span",{className:"ms-color-cap",children:r.label}),s.jsx("div",{className:"ms-color-swatches",children:r.colors.map(l=>s.jsx("button",{type:"button",className:"ms-color-swatch","aria-label":l,"aria-pressed":t?.toLowerCase()===l.toLowerCase(),disabled:n,style:{background:l},onClick:()=>a(l)},l))})]},r.label))})}function Un({on:e,onChange:t,label:n,size:a="md",disabled:r,className:l,describedBy:o}){return s.jsx("button",{type:"button",role:"switch","aria-checked":e,"aria-label":n,"aria-describedby":o,disabled:r,className:le("ms-toggle",e&&"ms-on",a==="sm"&&"ms-sm",l),onClick:c=>{c.stopPropagation(),t(!e)},children:s.jsx("i",{"aria-hidden":"true"})})}function Rn({on:e,onChange:t,label:n,disabled:a,className:r,mixed:l=!1}){const o=l&&!e;return s.jsx("button",{type:"button",role:"checkbox","aria-checked":o?"mixed":e,"aria-label":n,disabled:a,className:le("ms-check",e&&"ms-on",o&&"ms-mixed",r),onClick:c=>{c.stopPropagation(),t(o||!e)},children:s.jsx("svg",{width:11,height:11,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:2.2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:s.jsx("path",{d:o?Ya.minus:Ya.check})})})}function Ma(e,t,n){if(n<=0)return null;switch(e){case"ArrowRight":case"ArrowDown":return(t+1)%n;case"ArrowLeft":case"ArrowUp":return(t-1+n)%n;case"Home":return 0;case"End":return n-1;default:return null}}function it({options:e,value:t,onChange:n,label:a,className:r,disabled:l,describedBy:o}){const c=i.useRef([]),d=Math.max(0,e.findIndex(h=>h.value===t)),m=e[d]?.disabled?Math.max(0,e.findIndex(h=>!h.disabled)):d,u=(h,f)=>{let x=Ma(h.key,f,e.length);if(x===null)return;h.preventDefault();const p=h.key==="ArrowLeft"||h.key==="ArrowUp"||h.key==="End";for(let b=0;b<e.length&&e[x]?.disabled;b++)x=(x+(p?-1:1)+e.length)%e.length;if(e[x]?.disabled)return;const g=e[x];g&&(c.current[x]?.focus(),g.value!==t&&n(g.value))};return s.jsx("div",{role:"radiogroup","aria-label":a,"aria-disabled":l||void 0,"aria-describedby":o,className:le("ms-seg",r),children:e.map((h,f)=>{const x=h.value===t;return s.jsxs("button",{ref:p=>{c.current[f]=p},type:"button",role:"radio","aria-checked":x,tabIndex:f===m?0:-1,disabled:l||h.disabled,title:h.title,className:le(x&&"ms-on",h.disabled&&"ms-unavail"),onClick:()=>{x||n(h.value)},onKeyDown:p=>u(p,f),children:[h.icon?s.jsx(F,{name:h.icon,size:13}):null,s.jsx("span",{children:h.label}),h.count!==void 0?s.jsx("span",{className:le("ms-n",h.accent&&h.count>0&&"ms-accent"),children:h.count}):null]},h.value)})})}function sn({on:e,onClick:t,icon:n,children:a,className:r,title:l,disabled:o}){const c=le("ms-chip",e&&"ms-on",o&&"ms-disabled",r),d=i.useId(),m=s.jsxs(s.Fragment,{children:[n?s.jsx(F,{name:n,size:11}):null,a]});if(!t)return s.jsx("span",{className:c,title:l,children:m});const u=o&&l;return s.jsxs(s.Fragment,{children:[s.jsx("button",{type:"button",className:c,"aria-pressed":e,"aria-disabled":o||void 0,"aria-describedby":u?d:void 0,onClick:o?void 0:t,title:l,children:m}),u?s.jsx("span",{id:d,hidden:!0,children:l}):null]})}function tn({children:e,mono:t,className:n,title:a}){return s.jsx("span",{className:le("ms-tag",t&&"ms-mono",n),title:a,children:e})}function Qs({tone:e="neutral",dot:t,spinner:n,children:a,className:r}){return s.jsxs("span",{className:le("ms-pill",`ms-${e}`,r),children:[n?s.jsx(Ts,{decorative:!0,size:11}):t?s.jsx("span",{className:"ms-dot","aria-hidden":"true"}):null,a]})}function Bu({label:e}){const t=V();return s.jsxs("span",{className:"ms-typing",role:"status","aria-label":e??t.web.ui.typing,children:[s.jsx("i",{}),s.jsx("i",{}),s.jsx("i",{})]})}function kr({value:e,label:t,className:n}){const a=V(),r=Math.round(Math.min(100,Math.max(0,Number.isFinite(e)?e:0)));return s.jsx("div",{className:le("ms-progress",n),role:"progressbar","aria-label":t??a.web.ui.progress,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":r,children:s.jsx("i",{style:{width:`${r}%`}})})}const qd=9,Mh=2*Math.PI*qd,Wc=(e,t,n)=>Math.max(0,t-(n-e)/1e3);function mc({createdAt:e,ttlSec:t}){const n=V(),[a,r]=i.useState(()=>Date.now()),l=Wc(e,t,a);i.useEffect(()=>{if(Wc(e,t,Date.now())<=0)return;const m=setInterval(()=>{const u=Date.now();r(u),Wc(e,t,u)<=0&&clearInterval(m)},1e3);return()=>clearInterval(m)},[e,t]);const o=t>0?l/t:0,c=Math.ceil(l-1e-6),d=`${Math.floor(c/60)}:${String(c%60).padStart(2,"0")}`;return s.jsxs("span",{className:"ms-ring",role:"timer","aria-label":n.web.ui.timeLeft({time:d}),children:[s.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:[s.jsx("circle",{cx:"12",cy:"12",r:qd,className:"ms-ring-track"}),s.jsx("circle",{cx:"12",cy:"12",r:qd,className:"ms-ring-prog",strokeDasharray:Mh,strokeDashoffset:Mh*(1-o),transform:"rotate(-90 12 12)"})]}),s.jsx("span",{"aria-hidden":"true",children:d})]})}function ai(e){const t=e.trim().split(/\s+/).filter(Boolean);return(t.length>1?[t[0],t[1]].map(a=>[...a][0]??""):[...t[0]??""].slice(0,2)).join("").toUpperCase()}function Rt({icon:e="sparkle",title:t,sub:n,action:a,className:r}){const l=V();return s.jsxs("div",{className:le("ms-empty",r),children:[s.jsx("span",{className:"ms-empty-icon",children:s.jsx(F,{name:e,size:16})}),s.jsx("b",{children:t??l.web.ui.emptyTitle}),n?s.jsx("span",{className:"ms-empty-sub",children:n}):null,a?s.jsx("div",{className:"ms-empty-action",children:a}):null]})}function Dt({hoverable:e,className:t,...n}){return s.jsx("div",{...n,className:le("ms-card",e&&"ms-hov",t)})}function dn({on:e,icon:t,count:n,className:a,children:r,type:l="button",...o}){return s.jsxs("button",{...o,type:l,"aria-current":e?"page":void 0,className:le("ms-navitem",e&&"ms-on",a),children:[t?s.jsx(F,{name:t}):null,s.jsx("span",{className:"ms-navitem-label",children:r}),n!==void 0?s.jsx("span",{className:"ms-n",children:n}):null]})}function hc({tabs:e,value:t,onChange:n,label:a,variant:r="panel",className:l}){const o=i.useRef([]),c=Math.max(0,e.findIndex(m=>m.value===t)),d=(m,u)=>{let h=Ma(m.key,u,e.length);if(h===null)return;m.preventDefault();const f=m.key==="ArrowLeft"||m.key==="ArrowUp"||m.key==="End"?-1:1;for(let p=0;p<e.length&&e[h]?.disabled;p++)h=(h+f+e.length)%e.length;const x=e[h];!x||x.disabled||(o.current[h]?.focus(),x.value!==t&&n(x.value))};return s.jsx("div",{role:"tablist","aria-label":a,className:le("ms-tabs",`ms-${r}`,l),children:e.map((m,u)=>{const h=m.value===t;return s.jsxs("button",{ref:f=>{o.current[u]=f},type:"button",role:"tab","aria-selected":h,disabled:m.disabled,"aria-controls":m.controls,tabIndex:u===c&&!m.disabled?0:-1,className:le("ms-tab",h&&"ms-on"),onClick:()=>{h||n(m.value)},onKeyDown:f=>d(f,u),children:[m.label,m.count!==void 0?s.jsx("span",{className:"ms-tag ms-n",children:m.count}):null]},m.value)})})}const kw=/^https?:\/\/[^\s]+$/i,Nw=new Set([".",",",";",":","!","?","'",'"']);function Sw(e){let t=e.length;for(;t>0&&Nw.has(e[t-1]);)t--;return e.slice(0,t)}function $h(e){if(!kw.test(e))return null;try{const t=new URL(e);return t.protocol==="http:"||t.protocol==="https:"?e:null}catch{return null}}const Fh=({href:e,children:t})=>s.jsx("a",{className:"ms-link",href:e,target:"_blank",rel:Ox(),children:t}),Hc=[{re:/`([^`\n]+)`/g,render:(e,t)=>s.jsx("code",{children:e[1]},t)},{re:new RegExp("\\*\\*(?=\\S)((?:[^*\\n]|\\*(?!\\*))+?)(?<=\\S)\\*\\*","g"),render:(e,t,n)=>s.jsx("strong",{children:mr(e[1],t,n)},t)},{re:new RegExp("\\*(?=[^\\s*])([^*\\n]+?)(?<=\\S)\\*","g"),render:(e,t,n)=>s.jsx("em",{children:mr(e[1],t,n)},t)},{re:new RegExp("(?<![\\p{L}\\p{N}_])_(?=[^\\s_])([^_\\n]+?)(?<=\\S)_(?![\\p{L}\\p{N}_])","gu"),render:(e,t,n)=>s.jsx("em",{children:mr(e[1],t,n)},t)},{re:/\[([^[\]\n]+)\]\(([^()[\]\s]+)\)/g,render:(e,t,n)=>{const a=n?$h(e[2]):null;return a?s.jsx(Fh,{href:a,children:mr(e[1],t,!1)},t):e[0]}},{re:/https?:\/\/[^\s<>()[\]]+/g,trimEnd:!0,render:(e,t,n)=>{const a=n?$h(e[0]):null;return a?s.jsx(Fh,{href:a,children:a},t):e[0]}}];function mr(e,t,n=!0){const a=[],r=Hc.map(()=>{});let l=0,o=0;for(;l<e.length;){let c=-1;Hc.forEach((h,f)=>{let x=r[f];(x===void 0||x!==null&&x.index<l)&&(h.re.lastIndex=l,x=h.re.exec(e),r[f]=x),x&&(c<0||x.index<r[c].index)&&(c=f)});const d=c<0?null:r[c];if(!d){a.push(e.slice(l));break}const m=Hc[c],u=m.trimEnd?Sw(d[0]):d[0];d.index>l&&a.push(e.slice(l,d.index)),a.push(m.render([u,...d.slice(1)],`${t}.${o++}`,n)),l=d.index+u.length}return a}const Cw=/^\s*[-*+]\s+([^]*)$/,Ew=/^(#{1,6})[ \t]+([^]*)$/,Tw=/^( {0,3})(`{3,}|~{3,})([^]*)$/,Rw=/^ {0,3}(`{3,}|~{3,})[ \t]*$/,ki={BULLET:Cw,HEADING:Ew,FENCE_OPEN:Tw,FENCE_CLOSE:Rw},Ph=e=>e.endsWith("\r")?e.slice(0,-1):e;function Mw(e){let t=e.length;for(;t>0&&(e[t-1]==="#"||e[t-1]===" "||e[t-1]===" ");)t--;return e.slice(0,t)}function $w(e,t){const n=[];let a=null,r=null;for(const l of e.split(/\r?\n/)){if(r){const u=ki.FENCE_CLOSE.exec(l);if(u&&u[1][0]===r.ch&&u[1].length>=r.len){r=null,a=null;continue}let h=0;for(;h<r.indent&&l[h]===" ";)h++;r.block.lines.push(l.slice(h));continue}const o=ki.FENCE_OPEN.exec(l);if(o&&!(o[2][0]==="`"&&o[3].includes("`"))){const u={kind:"pre",lang:o[3].trim().split(" ")[0],lines:[]};n.push(u),r={ch:o[2][0],len:o[2].length,indent:o[1].length,block:u},a=null;continue}const c=ki.BULLET.exec(l),d=t?ki.HEADING.exec(l):null;if(!l.trim()){a=null;continue}const m=d?Mw(Ph(d[2])):"";d&&m?(n.push({kind:"h",level:d[1].length,text:m}),a=null):c?(a?.kind!=="ul"&&(a={kind:"ul",items:[]},n.push(a)),a.items.push(Ph(c[1]))):(a?.kind!=="p"&&(a={kind:"p",lines:[]},n.push(a)),a.lines.push(l))}return n}const Fw=["h3","h4","h5"];function Ro({text:e,className:t,headings:n=!1}){return s.jsx("div",{className:le("ms-md",t),children:$w(e,n).map((a,r)=>{if(a.kind==="h"){const l=Fw[Math.min(a.level,3)-1];return s.jsx(l,{className:"ms-md-h",children:mr(a.text,`${r}`)},r)}return a.kind==="pre"?s.jsxs("div",{className:"ms-md-code",children:[a.lang?s.jsx("span",{className:"ms-md-lang",children:a.lang}):null,s.jsx("pre",{className:"ms-md-pre",children:s.jsx("code",{children:a.lines.join(`
|
|
2
|
+
`)})})]},r):a.kind==="ul"?s.jsx("ul",{children:a.items.map((l,o)=>s.jsx("li",{children:mr(l,`${r}.${o}`)},o))},r):s.jsx("p",{children:a.lines.map((l,o)=>s.jsxs(i.Fragment,{children:[o>0?s.jsx("br",{}):null,mr(l,`${r}.${o}`)]},o))},r)})})}let Pw=0;const Xx=()=>++Pw,Mo=i.createContext(null),ba=[];let fc=null;const pc=()=>ba[ba.length-1];function Ah(e){const t=pc();if(t){if(e.key==="Tab"&&t.trap){Qx(e,t.trap());return}e.key!=="Escape"||e.isComposing||(e.preventDefault(),e.stopPropagation(),t.close())}}function Lh(e){const t=pc();fc={target:e.target,top:t?.id??null},!(!t||!t.outside)&&(e.target instanceof Node&&t.contains(e.target)||t.close())}function Ih(e){const n=pc()?.trap?.();!n||!(e.target instanceof Node)||n.contains(e.target)||Uu(n)}function zh(){setTimeout(()=>{fc=null},0)}function Oh(e){e?(document.addEventListener("keydown",Ah,!0),document.addEventListener("pointerdown",Lh,!0),document.addEventListener("click",zh,!0),document.addEventListener("focusin",Ih,!0)):(fc=null,document.removeEventListener("keydown",Ah,!0),document.removeEventListener("pointerdown",Lh,!0),document.removeEventListener("click",zh,!0),document.removeEventListener("focusin",Ih,!0))}function Zx(e){ba.length===0&&Oh(!0);const t=ba.findIndex(n=>n.parent===e.id);return t>=0?ba.splice(t,0,e):ba.push(e),()=>{const n=ba.indexOf(e);n>=0&&ba.splice(n,1),ba.length===0&&Oh(!1)}}const Aw=e=>pc()?.id===e,Jx=()=>ba.length>0;function Lw(e){const t=[];let n=e;for(;n&&!t.includes(n);){t.push(n);const a=n;n=[...ba].reverse().find(l=>l.anchor&&l.contains(a)&&l.anchor()!==a)?.anchor?.()??null}return t}function Iw(e,t){const n=fc;return n?n.target===t&&n.top===e:Aw(e)}const zw='a[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]), [contenteditable="true"]';function Yx(e){return[...e.querySelectorAll(zw)].filter(t=>!t.closest('[hidden], [inert], [aria-hidden="true"]'))}function Qx(e,t){if(e.key!=="Tab"||!t||e.defaultPrevented)return!1;const n=Yx(t);if(n.length===0)return e.preventDefault(),!0;const a=n[0],r=n[n.length-1],l=document.activeElement,o=l instanceof Node&&t.contains(l);return e.shiftKey&&(l===a||!o)?(e.preventDefault(),r.focus(),!0):!e.shiftKey&&(l===r||!o)?(e.preventDefault(),a.focus(),!0):!1}function Uu(e){e&&(document.activeElement instanceof Node&&e.contains(document.activeElement)||(Yx(e)[0]??e).focus({preventScroll:!0}))}function eg(e,t){const[n,a]=i.useState(e);e&&!n&&a(!0);const r=i.useRef(e);r.current=e;const l=i.useRef(t);return l.current=t,i.useLayoutEffect(()=>{if(!n)return;if(e){l.current.enter();return}let o=!0;return l.current.exit().then(c=>{c&&o&&!r.current&&a(!1)}),()=>{o=!1}},[e,n]),n||e}const Ni=6,Si=8,Ow=160;function Dw(e,t,n,a,r,l){let o=t==="bottom-end"?e.right-n:e.left;o=Math.max(Si,Math.min(o,r-n-Si));const c=l-e.bottom-Ni-Si,d=e.top-Ni-Si,m=t!=="top-start",u=Math.max(a,Ow),h=m?c:d,f=m?d:c,x=h<u&&f>h?!m:m,p=t==="bottom-end"?"right":"left";return x?{style:{left:o,top:e.bottom+Ni,maxHeight:Math.max(0,c)},origin:`top ${p}`}:{style:{left:o,bottom:l-e.top+Ni,maxHeight:Math.max(0,d)},origin:`bottom ${p}`}}function ot({open:e,onClose:t,anchor:n,placement:a="bottom-start",width:r,label:l,children:o}){const c=i.useRef(null),[d]=i.useState(Xx),m=i.useContext(Mo),u=i.useRef(t);u.current=t;const[h,f]=i.useState({style:{},origin:a==="top-start"?"bottom left":"top left"}),x=eg(e,{enter:()=>{const v=c.current;Gs(v,{y:-4,scale:.96,ms:qs.s,ease:Vt.spring}),v&&Ud(v.querySelectorAll("[data-row]"),{y:-4,ms:qs.s},20)},exit:()=>gr(c.current,{ms:qs.xs})}),p=i.useRef(!1);if(i.useLayoutEffect(()=>{if(!e){if(!p.current)return;p.current=!1;const y=document.activeElement;(!y||y===document.body||c.current?.contains(y))&&n.current?.focus({preventScroll:!0});return}p.current=!0;const v=Zx({id:d,parent:m,outside:!0,contains:y=>!!(c.current?.contains(y)||n.current?.contains(y)),close:()=>u.current(),anchor:()=>n.current});return Uu(c.current),v},[e,d,m,n]),i.useLayoutEffect(()=>{if(!e)return;const v=()=>{const y=n.current;if(!y)return;const w=c.current;f(Dw(y.getBoundingClientRect(),a,r??w?.offsetWidth??0,w?.scrollHeight??0,window.innerWidth,window.innerHeight))};return v(),window.addEventListener("resize",v),window.addEventListener("scroll",v,!0),()=>{window.removeEventListener("resize",v),window.removeEventListener("scroll",v,!0)}},[e,n,a,r]),!x)return null;const g=v=>{Qx(v,c.current)},b=v=>{v.stopPropagation()};return ma.createPortal(s.jsx(Mo.Provider,{value:d,children:s.jsx("div",{ref:c,className:"ms-pop",tabIndex:-1,...l?{role:"dialog","aria-label":l}:{},style:{...h.style,width:r,transformOrigin:h.origin},onKeyDown:g,onClick:b,inert:!e||void 0,children:o})}),document.body)}const Bw=150,Gc=6,Xc=8;function Uw(e){try{return e.matches(":focus-visible")}catch{return!0}}function Dh(e,t){if(!t)return!0;const n=e.querySelector(t);return!n||getComputedStyle(n).display==="none"}function pn({label:e,whenHidden:t,children:n}){const a=i.useId(),[r,l]=i.useState(null),[o,c]=i.useState({visibility:"hidden"}),d=i.useRef(null),m=n.props;i.useCallback(()=>l(null),[]);const u=i.useRef(null),h=i.useCallback(()=>{u.current&&(clearTimeout(u.current),u.current=null)},[]),f=i.useCallback(()=>{h(),u.current=setTimeout(()=>{u.current=null,l(null)},Bw)},[h]),x=i.useCallback(()=>{h(),l(null)},[h]);i.useEffect(()=>h,[h]);const p=typeof m["aria-label"]=="string"?m["aria-label"]:void 0,g=p!==void 0&&e!==p,b=m["aria-expanded"]===!0||m["aria-expanded"]==="true",v=i.useCallback(z=>{z.getAttribute("aria-expanded")!=="true"&&(g||Dh(z,t))&&(h(),l(z))},[t,h,g]),[y,w]=i.useState(null),j=m.ref,S=i.useCallback(z=>{w(z),typeof j=="function"?j(z):j&&(j.current=z)},[j]),[k,E]=i.useState(!t);i.useLayoutEffect(()=>{if(!y||!t){E(!0);return}const z=()=>{const T=Dh(y,t);E(T),!T&&!g&&x()};if(z(),typeof ResizeObserver>"u")return;const O=new ResizeObserver(z);return O.observe(y),()=>O.disconnect()},[y,t,x,g]),i.useEffect(()=>{b&&x()},[b,x]),i.useEffect(()=>{if(!r)return;const z=O=>{O.key==="Escape"&&x()};return document.addEventListener("keydown",z,!0),window.addEventListener("scroll",x,!0),window.addEventListener("resize",x),()=>{document.removeEventListener("keydown",z,!0),window.removeEventListener("scroll",x,!0),window.removeEventListener("resize",x)}},[r,x]),i.useEffect(()=>{r&&!r.isConnected&&x()}),i.useLayoutEffect(()=>{const z=d.current;if(!r||!z)return;const O=r.getBoundingClientRect(),T=z.offsetWidth,W=z.offsetHeight,Z=Math.max(Xc,Math.min(O.left+O.width/2-T/2,window.innerWidth-T-Xc)),A=O.top-Gc-W>=Xc;c({left:Z,top:A?O.top-Gc-W:O.bottom+Gc}),Gs(z,{y:A?3:-3,ms:qs.xs})},[r,e]);const N=(z,O)=>T=>{typeof z=="function"&&z(T),O(T)},C=k||g,R=C&&e!==p,P=i.cloneElement(n,{ref:S,"aria-describedby":R?[m["aria-describedby"],a].filter(Boolean).join(" "):m["aria-describedby"],title:(m.disabled||m.loading)&&C?e:m.title,onMouseEnter:N(m.onMouseEnter,z=>v(z.currentTarget)),onMouseLeave:N(m.onMouseLeave,f),onFocus:N(m.onFocus,z=>{Uw(z.currentTarget)&&v(z.currentTarget)}),onBlur:N(m.onBlur,x)});return s.jsxs(s.Fragment,{children:[P,R?ma.createPortal(s.jsx("span",{id:a,role:"tooltip",className:"ms-sr",children:e}),document.body):null,r?ma.createPortal(s.jsx("div",{ref:d,className:"ms-tooltip","aria-hidden":"true",style:o,onMouseEnter:h,onMouseLeave:f,children:e}),document.body):null]})}function At({value:e,options:t,onChange:n,label:a,className:r,disabled:l,variant:o="field",icon:c,display:d}){const m=i.useId(),u=i.useRef(null),[h,f]=i.useState(!1),[x,p]=i.useState(0),[g,b]=i.useState(void 0),v=Math.max(0,t.findIndex(N=>N.value===e)),y=t[v],w=N=>`${m}-o${N}`,j=()=>{p(v);const N=u.current?.offsetWidth??0;b(Math.max(180,N)),f(!0)},S=N=>{const C=t[N];C?.disabled||(f(!1),C&&C.value!==e&&n(C.value))},k=N=>{["ArrowDown","ArrowUp","Enter"," "].includes(N.key)&&(N.preventDefault(),h||j())},E=N=>{let C=Ma(N.key,x,t.length);if(C!==null){N.preventDefault();const R=N.key==="ArrowUp"||N.key==="ArrowLeft"||N.key==="End"?-1:1;for(let P=0;P<t.length&&t[C]?.disabled;P++)C=(C+R+t.length)%t.length;if(t[C]?.disabled)return;p(C),document.getElementById(w(C))?.scrollIntoView?.({block:"nearest"});return}if(N.key==="Enter"||N.key===" "){N.preventDefault(),S(x);return}if(N.key.length===1&&!N.metaKey&&!N.ctrlKey&&!N.altKey){const R=N.key.toLowerCase(),P=t.length;for(let z=1;z<=P;z++){const O=(x+z)%P;if(t[O].label.toLowerCase().startsWith(R)){p(O);break}}}};return s.jsxs(s.Fragment,{children:[s.jsxs("button",{ref:u,type:"button",className:le("ms-select",o==="pill"&&"ms-select-pill",h&&"ms-open",r),"aria-haspopup":"listbox","aria-expanded":h,"aria-labelledby":`${m}-l ${m}-v`,disabled:l,onClick:()=>h?f(!1):j(),onKeyDown:k,children:[s.jsx("span",{id:`${m}-l`,className:"ms-sr",children:a}),c?s.jsx(F,{name:c,size:14,className:"ms-select-icon"}):null,s.jsx("span",{id:`${m}-v`,className:"ms-select-value",children:d??y?.label??""}),s.jsx(F,{name:"chevron",size:14,className:"ms-select-chev"})]}),s.jsx(ot,{open:h&&!l,onClose:()=>f(!1),anchor:u,width:g,children:s.jsx("div",{role:"listbox","aria-label":a,tabIndex:0,"aria-activedescendant":t.length?w(x):void 0,className:"ms-listbox",onKeyDown:E,children:t.map((N,C)=>{const R=C===v;return s.jsxs(i.Fragment,{children:[N.group!==void 0&&N.group!==t[C-1]?.group?s.jsx("div",{role:"presentation",className:"ms-option-group",children:N.group}):null,s.jsxs("div",{id:w(C),role:"option","aria-selected":R,"aria-disabled":N.disabled||void 0,"data-row":"",className:le("ms-option",C===x&&"ms-active",R&&"ms-on",N.disabled&&"ms-off"),onMouseDown:P=>P.preventDefault(),onMouseMove:()=>{C!==x&&!N.disabled&&p(C)},onClick:()=>S(C),children:[s.jsxs("span",{className:"ms-option-label",children:[N.label,N.hint?s.jsx("small",{className:"ms-option-hint",children:N.hint}):null]}),R?s.jsx(F,{name:"check",size:14,strokeWidth:2}):null]})]},N.value)})})})]})}function rt({open:e,onClose:t,label:n,width:a=560,dismissible:r=!0,children:l}){const o=i.useRef(null),c=i.useRef(null),[d]=i.useState(Xx),m=i.useContext(Mo),u=i.useRef(t);u.current=t;const h=i.useRef(r);h.current=r;const f=i.useRef([]),x=i.useRef(!1);if(e&&!x.current){const w=typeof document>"u"?null:document.activeElement;f.current=Lw(w instanceof HTMLElement&&w!==document.body?w:null)}x.current=e;const p=()=>{f.current.find(w=>w.isConnected)?.focus({preventScroll:!0})},g=eg(e,{enter:()=>{Gs(o.current,{y:0,ms:qs.s,ease:Vt.std}),Gs(c.current,{y:0,scale:.97,ms:qs.m})},exit:()=>Promise.all([gr(c.current,{ms:qs.xs}),gr(o.current,{ms:qs.xs})]).then(w=>w.every(Boolean))}),b=i.useRef(!1);if(i.useLayoutEffect(()=>{if(!e){if(!b.current)return;b.current=!1,p();return}b.current=!0;const w=Zx({id:d,parent:m,outside:!1,contains:j=>!!c.current?.contains(j),close:()=>{h.current&&u.current()},trap:()=>c.current});return Uu(c.current),w},[e,d,m]),i.useLayoutEffect(()=>()=>{b.current&&p()},[]),!g)return null;const v=w=>{w.target===w.currentTarget&&h.current&&Iw(d,w.currentTarget)&&u.current()},y=w=>{w.stopPropagation()};return ma.createPortal(s.jsx(Mo.Provider,{value:d,children:s.jsxs("div",{className:"ms-modal",inert:!e||void 0,onClick:y,children:[s.jsx("div",{ref:o,className:"ms-scrim",onClick:v}),s.jsx("div",{ref:c,className:"ms-dialog",role:"dialog","aria-modal":"true","aria-label":n,tabIndex:-1,style:{width:a},children:l})]})}),document.body)}const sg=3,tg=3200,_w=sg*2;let qw=0,Qa=[];const Wl=new Map,$o=new Set,Fo=e=>{Qa=e;for(const t of $o)t()};function Vw(e){return $o.add(e),()=>{$o.delete(e)}}const Bh=()=>Qa;function Kw(e){Qa.some(t=>t.id===e)&&Fo(Qa.filter(t=>t.id!==e))}function ng(e){const t=Wl.get(e);t?.timer&&clearTimeout(t.timer),Wl.delete(e)}function ag(e,t){t.since=Date.now(),t.timer=setTimeout(()=>rg(e),t.left)}function Ww(e){const t=Wl.get(e);t&&t.paused++===0&&t.timer&&(clearTimeout(t.timer),t.timer=null,t.left=Math.max(0,t.left-(Date.now()-t.since)))}function Hw(e){const t=Wl.get(e);!t||t.paused===0||--t.paused===0&&ag(e,t)}function rg(e){ng(e),Qa.some(t=>t.id===e&&!t.leaving)&&($o.size===0?Fo(Qa.filter(t=>t.id!==e)):Fo(Qa.map(t=>t.id===e?{...t,leaving:!0}:t)))}function Gw(e,t={}){const n=++qw;let a=[...Qa,{id:n,text:e,tone:t.tone??"neutral",action:t.action,leaving:!1}];const r=a.filter(o=>!o.leaving).length-sg,l=a.filter(o=>!o.leaving).slice(0,Math.max(0,r)).map(o=>o.id);a=a.map(o=>l.includes(o.id)?{...o,leaving:!0}:o);for(const o of l)ng(o);for(;a.length>_w;){const o=a.findIndex(c=>c.leaving);a.splice(o>=0?o:0,1)}if(Fo(a),!t.sticky){const o={timer:null,left:t.ms??tg,since:0,paused:0};Wl.set(n,o),ag(n,o)}return n}const Pe={show:Gw,dismiss:rg};function Xw(){const e=i.useSyncExternalStore(Vw,Bh,Bh);return ma.createPortal(s.jsx("div",{className:"ms-toasts",role:"status","aria-live":"polite",children:e.map(t=>s.jsx(Zw,{t},t.id))}),document.body)}function Zw({t:e}){const t=i.useRef(null),n=i.useRef({pointer:!1,focus:!1});i.useLayoutEffect(()=>{Gs(t.current,{y:-16,ms:qs.m})},[]),i.useLayoutEffect(()=>{e.leaving&&gr(t.current,{y:-8,ms:qs.s}).then(o=>{o&&Kw(e.id)})},[e.leaving,e.id]);const a=(o,c)=>{n.current[o]!==c&&(n.current[o]=c,c?Ww(e.id):Hw(e.id))},r=o=>{o.relatedTarget instanceof Node&&o.currentTarget.contains(o.relatedTarget)||a("focus",!1)},l=()=>{try{e.action.run()}catch(o){console.error(o)}finally{Pe.dismiss(e.id)}};return s.jsxs("div",{ref:t,className:"ms-toast","aria-hidden":e.leaving||void 0,onPointerEnter:()=>a("pointer",!0),onPointerLeave:()=>a("pointer",!1),onFocus:()=>a("focus",!0),onBlur:r,children:[e.tone==="ok"?s.jsx("span",{className:"ms-toast-ok",children:s.jsx(F,{name:"check",size:14,strokeWidth:2})}):s.jsx("span",{className:"ms-dot ms-toast-dot"}),s.jsx("span",{className:"ms-toast-text",children:e.text}),e.action?s.jsx("button",{type:"button",className:"ms-toast-action",disabled:e.leaving,onClick:l,children:e.action.label}):s.jsx("span",{className:"ms-toast-end"})]})}function la(e){const t=Math.max(0,Math.floor(e+1e-6)),n=Math.floor(t/3600),a=Math.floor(t%3600/60),r=t%60;return n>0?`${n}:${String(a).padStart(2,"0")}:${String(r).padStart(2,"0")}`:`${a}:${String(r).padStart(2,"0")}`}const Uh=e=>Math.round(e*1e3)/1e3,Ci=5;function lg({player:e,peaks:t,className:n}){const r=V().web.player,l=i.useRef(null),o=i.useRef(!1),{playing:c,time:d,duration:m,failed:u}=e,h=u||m<=0,f=m?Math.min(100,Math.max(0,d/m*100)):0,x=j=>{const S=l.current?.getBoundingClientRect();return!S||!S.width||!m?null:Math.min(m,Math.max(0,(j-S.left)/S.width*m))},p=j=>{if(h||j.button!==0)return;j.currentTarget.setPointerCapture?.(j.pointerId),o.current=!0;const S=x(j.clientX);S!==null&&e.seek(S)},g=j=>{if(!o.current)return;const S=x(j.clientX);S!==null&&e.seek(S)},b=()=>{o.current=!1},v=j=>{if(h||j.metaKey||j.ctrlKey||j.altKey)return;const S=j.key==="ArrowRight"||j.key==="ArrowUp"?d+Ci:j.key==="ArrowLeft"||j.key==="ArrowDown"?d-Ci:j.key==="PageUp"?d+Ci*2:j.key==="PageDown"?d-Ci*2:j.key==="Home"?0:j.key==="End"?m:null;if(j.key===" "){j.preventDefault(),e.toggle();return}S!==null&&(j.preventDefault(),j.stopPropagation(),e.seek(S))},y=t&&t.length>0?t:null,w=j=>s.jsx("svg",{className:j,viewBox:`0 0 ${y.length} 1`,preserveAspectRatio:"none","aria-hidden":"true",focusable:"false",children:y.map((S,k)=>{const E=Math.max(.04,S);return s.jsx("rect",{x:k+.15,y:(1-E)/2,width:.7,height:E},k)})});return s.jsxs("div",{className:le("ms-player-controls",n),children:[s.jsx("button",{type:"button",className:"ms-player-play","aria-label":c?r.pause:r.play,"aria-keyshortcuts":"Space",disabled:u,onClick:e.toggle,children:s.jsx(F,{name:c?"pause":"play",size:13,fill:!c,strokeWidth:c?2:1.4})}),s.jsxs("span",{className:"ms-player-tc",children:[la(d),s.jsxs("span",{className:"ms-player-total",children:[" / ",la(m)]})]}),s.jsxs("div",{ref:l,className:le("ms-player-scrub",y&&"ms-wave",h&&"ms-off"),role:"slider",tabIndex:h?-1:0,"aria-label":r.position,"aria-disabled":h||void 0,"aria-valuemin":0,"aria-valuemax":Uh(m),"aria-valuenow":Uh(d),"aria-valuetext":r.positionText({time:la(d),total:la(m)}),onPointerDown:p,onPointerMove:g,onPointerUp:b,onPointerCancel:b,onKeyDown:v,children:[y?s.jsxs(s.Fragment,{children:[w("ms-player-wave"),s.jsx("span",{className:"ms-player-played",style:{clipPath:`inset(0 ${100-f}% 0 0)`},children:w("ms-player-wave")})]}):null,y?null:s.jsx("div",{className:"ms-player-bar","aria-hidden":"true",children:s.jsx("i",{style:{width:`${f}%`}})}),s.jsx("span",{className:"ms-player-head",style:{left:`${f}%`},"aria-hidden":"true"})]}),u?s.jsx("span",{className:"ms-player-err",role:"status",children:r.unplayable}):null]})}const Ei=e=>Number.isFinite(e)&&e>0?e:0;function ig(e){const t=i.useRef(null),[n,a]=i.useState({playing:!1,time:0,duration:Ei(e??0),failed:!1}),r=i.useCallback(()=>{const c=t.current;c&&a(d=>{const m=Ei(c.duration)||d.duration,u={...d,time:Ei(c.currentTime),duration:m,playing:!c.paused&&!c.ended};return u.time===d.time&&u.duration===d.duration&&u.playing===d.playing?d:u})},[]);i.useEffect(()=>{const c=t.current;if(!c)return;const d=["loadedmetadata","durationchange","timeupdate","seeked","play","playing","pause","ended"];for(const u of d)c.addEventListener(u,r);const m=()=>a(u=>({...u,failed:!0,playing:!1}));return c.addEventListener("error",m),r(),()=>{for(const u of d)c.removeEventListener(u,r);c.removeEventListener("error",m)}},[r]),i.useEffect(()=>{if(!n.playing)return;let c=requestAnimationFrame(function d(){r(),c=requestAnimationFrame(d)});return()=>cancelAnimationFrame(c)},[n.playing,r]);const l=i.useCallback(()=>{const c=t.current;c&&(c.paused||c.ended?Promise.resolve(c.play()).catch(()=>a(d=>({...d,failed:!0,playing:!1}))):c.pause())},[]),o=i.useCallback(c=>{const d=t.current;if(!d)return;const m=Ei(d.duration)||n.duration,u=Math.min(m||c,Math.max(0,c));d.currentTime=u,a(h=>({...h,time:u}))},[n.duration]);return{ref:t,...n,toggle:l,seek:o}}function Jw({src:e,name:t,peaks:n,durationSec:a,className:r}){const l=V().web.player,o=ig(a);return s.jsxs("section",{className:le("ms-player ms-player-audio",r),"aria-label":l.audio({name:t}),children:[s.jsx("audio",{ref:o.ref,src:e,preload:"metadata"}),s.jsx(lg,{player:o,peaks:n})]})}function Yw({src:e,name:t,poster:n,durationSec:a,className:r,handle:l}){const o=V().web.player,c=ig(a);return i.useImperativeHandle(l,()=>({seek:c.seek}),[c.seek]),s.jsxs("section",{className:le("ms-player ms-player-video",r),"aria-label":o.video({name:t}),children:[s.jsx("video",{ref:c.ref,className:"ms-player-picture",src:e,poster:n,preload:"metadata",playsInline:!0,onClick:c.toggle}),s.jsx(lg,{player:c})]})}function ia(e,t){return t<1e3?Vs(e,t,{maximumFractionDigits:0}):`${Vs(e,t/1e3,{minimumFractionDigits:1,maximumFractionDigits:1})}k`}function Ur(e,t){if(t>0&&t<.001)return`< ${Ur(e,.001)}`;const n=t>0&&t<.1?3:2;return Vs(e,t,{style:"currency",currency:"USD",currencyDisplay:"narrowSymbol",minimumFractionDigits:n,maximumFractionDigits:n})}function dl(e,t,n,a=!1){if(n===null)return null;const r=Ur(t,n);return a?e.web.usage.atLeast({cost:r}):r}function og(e,t,n,a,r=!1){if(a===null)return null;const l=e.web.usage;if(n==="api")return dl(e,t,a,r);const o=Ur(t,a);return n==="subscription"?r?l.billingSubscriptionAtLeast({cost:o}):l.billingSubscription({cost:o}):r?l.billingUnknownAtLeast({cost:o}):l.billingUnknown({cost:o})}function Qw({tokens:e}){const t=V(),n=rs(),a=e===null?t.web.usage.unknown:ia(n,e);return s.jsx($,{variant:"ghost",className:"ms-tokens ms-mono","aria-label":t.web.usage.todayButton({count:a}),onClick:()=>Bs(es.settings("usage")),children:t.web.usage.tokens({count:a})})}function ar({tokens:e,className:t,live:n,partial:a}){const r=V(),l=rs();if(e===null)return null;const o=ia(l,e);return s.jsxs("span",{className:le("ms-tokcount",t),children:[a?r.web.usage.tokensAtLeast({count:o}):r.web.usage.tokens({count:o}),n?s.jsx("span",{className:"ms-sr",children:` ${r.web.usage.soFar}`}):null]})}function _h({usage:e,billing:t}){const n=V(),a=n.web.usage,r=rs(),l=i.useRef(null),[o,c]=i.useState(!1);if(!e)return null;const d=e.estimated===!0,m=dl(n,r,e.costUsd,d),u=[a.tokens({count:ia(r,_n(e.tokens))}),m].filter(Boolean).join(" · "),h=og(n,r,t??"unknown",e.costUsd,d),f=p=>Vs(r,p),x=[[a.input,e.tokens.input],[a.output,e.tokens.output],[a.cacheWrite,e.tokens.cacheWrite],[a.cacheRead,e.tokens.cacheRead]];return s.jsxs(s.Fragment,{children:[s.jsx($,{ref:l,size:"sm",variant:"ghost",className:"ms-usage-badge ms-mono","aria-haspopup":"dialog","aria-expanded":o,onClick:()=>c(p=>!p),children:u}),s.jsx(ot,{open:o,onClose:()=>c(!1),anchor:l,placement:"bottom-end",width:280,label:a.details,children:s.jsxs("div",{className:"ms-usage-pop",children:[s.jsx("b",{children:a.details}),s.jsx("dl",{className:"ms-usage-rows",children:x.map(([p,g])=>s.jsxs("div",{children:[s.jsx("dt",{children:p}),s.jsx("dd",{children:f(g)})]},p))}),s.jsx("p",{className:"ms-usage-note",children:h??a.noCost}),d&&e.costUsd!==null?s.jsx("p",{className:"ms-usage-note",children:a.costUnknown}):null]})})]})}const pe=e=>e instanceof Error?e.message:String(e),cg=5e3;function oa({children:e,action:t}){return s.jsxs("div",{className:"ms-alert",role:"alert",children:[s.jsx(F,{name:"warn",size:14}),s.jsx("span",{children:e}),t]})}function Xn({title:e,sub:t,children:n}){return s.jsxs("div",{className:"ms-set-row",children:[s.jsxs("div",{className:"ms-set-row-text",children:[s.jsx("b",{children:e}),t?s.jsx("span",{children:t}):null]}),n!==void 0?s.jsx("div",{className:"ms-set-row-ctl",children:n}):null]})}function ua({title:e,sub:t,children:n}){return s.jsxs("div",{className:"ms-set-head","data-enter":!0,children:[s.jsxs("div",{className:"ms-set-head-text",children:[s.jsx("h1",{children:e}),t?s.jsx("span",{children:t}):null]}),n]})}function dg({section:e,children:t}){const n=Ra([e]);return s.jsx("main",{ref:n,className:"ms-set-main",children:t})}const ek="/assets/logo-dark-Yi8yb5WJ.svg",sk="/assets/logo-Dd9VMLzB.svg",tk="/assets/logo-horizontal-dark-B16it8f0.svg",nk="/assets/logo-horizontal-Blb7HKgj.svg",ak="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='-11%20-11%20362%20322'%3e%3crect%20x='0'%20y='0'%20width='200'%20height='200'%20rx='44'%20fill='none'%20stroke='%239C9C9C'%20stroke-width='12'%20stroke-dasharray='26%2022'/%3e%3crect%20x='70'%20y='50'%20width='200'%20height='200'%20rx='44'%20fill='none'%20stroke='%23F5F5F5'%20stroke-width='14'/%3e%3crect%20x='140'%20y='100'%20width='200'%20height='200'%20rx='44'%20fill='%23FF5A1F'/%3e%3cpath%20d='M207.62%20164Q207.62%20154%20216.31%20158.94L279.88%20195.06Q288.58%20200%20279.88%20204.94L216.31%20241.06Q207.62%20246%20207.62%20236Z'%20fill='%23FFFFFF'/%3e%3c/svg%3e",rk="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='-11%20-11%20362%20322'%3e%3crect%20x='0'%20y='0'%20width='200'%20height='200'%20rx='44'%20fill='none'%20stroke='%236B6B6B'%20stroke-width='12'%20stroke-dasharray='26%2022'/%3e%3crect%20x='70'%20y='50'%20width='200'%20height='200'%20rx='44'%20fill='none'%20stroke='%23171717'%20stroke-width='14'/%3e%3crect%20x='140'%20y='100'%20width='200'%20height='200'%20rx='44'%20fill='%23FF5A1F'/%3e%3cpath%20d='M207.62%20164Q207.62%20154%20216.31%20158.94L279.88%20195.06Q288.58%20200%20279.88%20204.94L216.31%20241.06Q207.62%20246%20207.62%20236Z'%20fill='%23FFFFFF'/%3e%3c/svg%3e";function qh(){const e=document.documentElement.getAttribute("data-theme");return e==="light"||e==="dark"?e:typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function lk(){const[e,t]=i.useState(qh);return i.useEffect(()=>{const n=()=>t(qh()),a=new MutationObserver(n);a.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const r=typeof window.matchMedia=="function"?window.matchMedia("(prefers-color-scheme: dark)"):null;return r?.addEventListener?.("change",n),n(),()=>{a.disconnect(),r?.removeEventListener?.("change",n)}},[]),e}const ik={stacked:{light:sk,dark:ek,w:883.73,h:360},horizontal:{light:nk,dark:tk,w:1720,h:322},mark:{light:rk,dark:ak,w:362,h:322}};function Hr({height:e=24,className:t,variant:n="stacked",decorative:a=!1}){const r=lk(),l=ik[n];return s.jsx("img",{className:t,src:l[r],"data-variant":r,alt:a?"":"Motion Studio",height:e,width:Math.round(e*l.w/l.h),draggable:!1})}function ok(e,t){return e===null?"":t?"ms-titlebar":e==="darwin"?"ms-titlebar ms-tb-mac":"ms-titlebar ms-tb-overlay"}function ck(){try{return xt()?.isFullscreen?.()===!0}catch{return!1}}function _u(){const e=xt(),[t,n]=i.useState(ck);return i.useEffect(()=>{const a=e?.onFullscreenChange?.(r=>{n(r===!0)});return typeof a=="function"?a:void 0},[e]),ok(e?.platform??null,t)}function dk(e){const t=document.documentElement.getAttribute("data-theme");return t==="light"||t==="dark"?t:e?.matches?"dark":"light"}function uk(){const e=xt();if(typeof e?.setTitleBarTheme!="function")return()=>{};const t=typeof window.matchMedia=="function"?window.matchMedia("(prefers-color-scheme: dark)"):null;let n=null;const a=()=>{const l=dk(t);if(l!==n){n=l;try{Promise.resolve(e.setTitleBarTheme(l)).catch(()=>{})}catch{}}};a(),t?.addEventListener("change",a);const r=new MutationObserver(a);return r.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>{t?.removeEventListener("change",a),r.disconnect()}}const mk="https://code.claude.com/docs/en/troubleshoot-install",hk=1e3,fk=2e3,pk={"install-claude":"claudeInstall","sign-in":"claudeLogin","install-ffmpeg":"ffmpegInstall"},xk={"install-claude":"claude-install","sign-in":"claude-login","install-ffmpeg":"ffmpeg-install"},Vd=e=>`${Math.max(1,Math.round(e/1e6))} MB`;function gk(e,t){const[n,a]=i.useState(null),[r,l]=i.useState(null),o=i.useRef(t);o.current=t;const c=i.useRef(null),d=u=>{const h=c.current;c.current=u,a(u),h&&Object.keys(u.tasks).some(f=>h.tasks[f].state==="running"&&u.tasks[f].state!=="running")&&o.current()},m=n?Object.values(n.tasks).some(u=>u.state==="running"):!1;return i.useEffect(()=>{if(!e)return;let u=!0;const h=()=>q.getSetup().then(x=>{u&&(d(x),l(null))},x=>{u&&l(pe(x))});if(c.current||h(),!m)return()=>{u=!1};const f=setInterval(()=>{h()},hk);return()=>{u=!1,clearInterval(f)}},[e,m]),{status:n,error:r,set:d}}function vk({command:e}){const t=V().web.welcome,n=i.useRef(null),[a,r]=i.useState("idle"),l=i.useRef(null);i.useEffect(()=>()=>{l.current&&clearTimeout(l.current)},[]);const o=async()=>{l.current&&clearTimeout(l.current);try{if(!navigator.clipboard?.writeText)throw new Error("clipboard unavailable");await navigator.clipboard.writeText(e),r("copied"),l.current=setTimeout(()=>r("idle"),fk)}catch{const c=window.getSelection();if(c&&n.current){const d=document.createRange();d.selectNodeContents(n.current),c.removeAllRanges(),c.addRange(d)}r("manual")}};return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ms-setup-cmd",children:[s.jsx("code",{ref:n,children:e}),s.jsxs($,{size:"sm",variant:"ghost",onClick:()=>{o()},children:[s.jsx(F,{name:a==="copied"?"check":"copy",size:13,strokeWidth:a==="copied"?2:1.4}),a==="copied"?t.copied:t.copy]})]}),a==="manual"?s.jsx("p",{className:"ms-setup-hint",role:"status",children:t.copyManual}):null]})}function bk({check:e,status:t}){const n=V().web.welcome;if(e.action==="install-claude"){const a=t?.claudeManual??e.fix;return a?s.jsxs("details",{className:"ms-setup-manual",children:[s.jsx("summary",{children:n.manualTitle}),s.jsxs("ol",{children:[s.jsx("li",{children:t?.platform==="windows"?n.manualOpenWindows:n.manualOpenOther}),s.jsxs("li",{children:[n.manualPaste,s.jsx(vk,{command:a})]}),s.jsx("li",{children:n.manualDone})]})]}):null}return e.fix?s.jsxs("details",{className:"ms-setup-manual",children:[s.jsx("summary",{children:n.manualTitle}),s.jsx("p",{children:e.fix})]}):null}function jk(e,t,n){return t.state==="running"?e==="install-claude"?n.installingClaude:e==="sign-in"?n.signingIn:n.installingFfmpeg({done:Vd(t.bytes??0),total:Vd(t.total??0)}):t.state==="cancelled"?n.taskCancelled:t.state!=="failed"?null:e==="install-ffmpeg"?n.ffmpegFailed:e==="sign-in"?t.error==="timeout"?n.signInTimeout:n.signInFailed:t.error==="timeout"?n.installTimeout:n.installFailed}function yk({check:e,setup:t,onRecheck:n}){const a=V(),r=a.web.welcome,l=e.action,{status:o}=t,c=o?.tasks[pk[l]]??{state:"idle"},[d,m]=i.useState(!1),[u,h]=i.useState(!1),[f,x]=i.useState(null),p=c.state==="running",g=l==="install-claude"?r.installClaude:l==="sign-in"?r.signIn:r.installFfmpeg,b=o?.ffmpeg??null,v=o!==null&&(!o.allowed||l==="install-ffmpeg"&&!b),y=async()=>{h(!0),x(null);try{const E=l==="install-claude"?await q.setupInstallClaude():l==="sign-in"?await q.setupSignIn():await q.setupInstallFfmpeg();t.set(E),m(!1)}catch(E){x(pe(E))}finally{h(!1)}},w=async()=>{try{t.set(await q.setupCancel(xk[l]))}catch(E){x(pe(E))}},j=l==="install-claude"?r.confirmClaude:l==="sign-in"?r.confirmSignIn:b?r.confirmFfmpeg({version:b.version,source:b.source,size:Vd(b.sizeBytes),license:b.license}):"",S=jk(l,c,r),k=l!=="install-ffmpeg";return s.jsxs("div",{className:`ms-remedy ms-setup ${k?"ms-setup-primary":""}`,children:[p?s.jsxs("div",{className:"ms-setup-row",children:[s.jsxs("div",{className:"ms-setup-status",role:"status",children:[s.jsx(Ts,{decorative:!0,size:13}),s.jsx("span",{children:S})]}),s.jsx("div",{className:"ms-grow"}),s.jsx($,{size:"sm",variant:"ghost",onClick:()=>{w()},children:a.common.cancel})]}):s.jsxs("div",{className:"ms-setup-row",children:[o&&!v&&!d?s.jsx($,{size:"sm",variant:k?"ink":"outline",onClick:()=>{m(!0),x(null)},children:g}):null,s.jsx("div",{className:"ms-grow"}),s.jsxs($,{size:"sm",variant:"outline",onClick:n,children:[s.jsx(F,{name:"refresh",size:12}),r.checkAgain]})]}),d?s.jsxs("div",{className:"ms-setup-confirm",role:"group","aria-label":g,children:[s.jsx("p",{children:j}),s.jsxs("div",{className:"ms-setup-row",children:[s.jsx($,{size:"sm",variant:"ink",loading:u,onClick:()=>{y()},children:l==="sign-in"?r.confirmContinue:r.confirmInstall}),s.jsx($,{size:"sm",variant:"ghost",disabled:u,onClick:()=>m(!1),children:a.common.cancel})]})]}):null,S&&!p?s.jsxs("div",{className:`ms-setup-status ${c.state==="failed"?"ms-warn":""}`,role:c.state==="failed"?"alert":"status",children:[c.state==="failed"?s.jsx(F,{name:"warn",size:12}):null,s.jsx("span",{children:S})]}):null,p&&l==="install-ffmpeg"&&c.total?s.jsx(kr,{value:(c.bytes??0)/c.total*100}):null,p&&l==="sign-in"&&c.loginUrl?s.jsx("a",{className:"ms-setup-link",href:c.loginUrl,target:"_blank",rel:"noreferrer noopener",children:r.openSignIn}):null,c.state==="failed"&&l==="install-claude"?s.jsx("a",{className:"ms-setup-link",href:mk,target:"_blank",rel:"noreferrer noopener",children:r.troubleshoot}):null,f?s.jsxs("p",{className:"ms-setup-status ms-warn",role:"alert",children:[s.jsx(F,{name:"warn",size:12}),s.jsx("span",{children:f})]}):null,o&&!o.allowed?s.jsx("p",{className:"ms-setup-hint",children:a.errors.setupNotLoopback}):null,s.jsx(bk,{check:e,status:o})]})}const Vh="brand, assets, references, creatives",wk=280,Kh=3;function kk(e,t,n){switch(e.code){case"not-found":return n.workspaceNotFound({path:t});case"invalid":return n.workspaceInvalid({path:t,detail:e.message});case"not-writable":return e.message}}function Nk(e){const t=e.trim();if(!t||/\s/.test(t))return null;const n=/^[a-z][a-z0-9+.-]*:\/\//i.test(t)?t:`https://${t}`;try{const a=new URL(n);return a.protocol!=="http:"&&a.protocol!=="https:"||!a.hostname.includes(".")||a.username||a.password?null:n}catch{return null}}function Sk(e){const{checks:t,loadError:n,workspace:a,canLeave:r,onFinish:l}=e,o=V(),c=o.web.welcome,d=_u(),m=!t||!!n||t.some(W=>W.required&&!W.ok),[u,h]=i.useState(null),f=!!a?.settings||u!==null,x=m?1:f?3:2,[p,g]=i.useState(()=>Math.min(e.step??1,x)),b=p,v=i.useRef(null),y=i.useRef(null),w=i.useRef(!1),j=i.useRef(0),[S,k]=i.useState(0),E=i.useRef(!0);i.useEffect(()=>(E.current=!0,()=>{E.current=!1}),[]);const N=async W=>{if(w.current||W===p||W<1)return;w.current=!0;const Z=W>p?1:-1;await gr(y.current,{x:-Z*16}),E.current&&(j.current=Z,g(W),k(A=>A+1),w.current=!1)};i.useLayoutEffect(()=>{j.current&&(Gs(y.current,{x:j.current*16,y:0}),j.current=0)},[S]),i.useEffect(()=>{p>x&&N(x)});const C=Ra([]),R=i.useRef(null);i.useEffect(()=>{const W=Z=>{Z.key!=="Enter"||Z.defaultPrevented||Z.isComposing||Z.metaKey||Z.ctrlKey||Z.altKey||Z.shiftKey||(Z.target instanceof Element?Z.target:null)?.closest('button, a, textarea, select, [role="listbox"], [role="dialog"], .ms-pop')||(Z.preventDefault(),R.current?.())};return document.addEventListener("keydown",W),()=>document.removeEventListener("keydown",W)},[]);const P=t?.filter(W=>!W.info)??[],z=P.filter(W=>W.ok).length,O=[[c.checkTitle,n?c.serverUnreachableShort:t?c.checksPassed({ok:z,total:P.length}):c.checking],[c.workspaceTitle,c.workspaceSub],[c.projectTitle,c.projectSub]];let T;return b===1?T=s.jsx(Ek,{...e,blocking:m,onNext:()=>{N(2)},primary:R,onBack:()=>{},revealedRun:v}):b===2?T=s.jsx(Tk,{...e,onRecheck:()=>{N(1).then(e.onRecheck)},onBack:()=>{N(1)},onSaved:W=>{h(W.path),e.onWorkspace(W),N(3)},primary:R}):T=s.jsx(Mk,{onBack:()=>{N(2)},onFinish:l,primary:R}),s.jsxs("div",{className:"ms-welcome",ref:C,children:[s.jsxs("header",{className:le("ms-welcome-top",d),children:[r?s.jsx("a",{className:"ms-logo",href:es.projects(),"aria-label":o.web.shell.home,onClick:W=>{W.preventDefault(),l(es.projects())},children:s.jsx(Wh,{})}):s.jsx("span",{className:"ms-logo","aria-hidden":"true",children:s.jsx(Wh,{})}),s.jsx(Hr,{className:"ms-welcome-brand",height:22}),s.jsx("span",{className:"ms-welcome-version",children:"0.1.1"}),s.jsx("div",{className:"ms-grow"}),e.onLanguage?s.jsx(Ck,{value:e.language??"system",systemLocale:e.systemLocale??"en",onChange:e.onLanguage}):null]}),s.jsx("main",{className:"ms-welcome-stage",children:s.jsxs("div",{className:"ms-welcome-grid",children:[s.jsxs("div",{className:"ms-welcome-side","data-enter":!0,children:[s.jsxs("div",{className:"ms-welcome-hero",children:[s.jsx("span",{className:"ms-welcome-cap",children:c.setupStep({n:b,total:3})}),s.jsx("h1",{children:c.title}),s.jsx("p",{children:c.intro})]}),s.jsx("ol",{className:"ms-steps","aria-label":c.steps,children:O.map(([W,Z],A)=>{const L=A+1,_=L<b?"done":L===b?"now":"next";return s.jsxs("li",{className:le("ms-step",`ms-${_}`),"aria-current":_==="now"?"step":void 0,children:[s.jsx("span",{className:"ms-step-mark","aria-hidden":"true",children:_==="done"?s.jsx(F,{name:"check",size:11,strokeWidth:2.2}):L}),s.jsxs("span",{className:"ms-step-text",children:[s.jsx("b",{children:W}),s.jsx("span",{children:Z}),_==="done"?s.jsx("span",{className:"ms-sr",children:c.stepDone}):null]})]},L)})})]}),s.jsx("section",{className:"ms-welcome-panel",ref:y,"data-enter":!0,"data-delay":"60","aria-labelledby":"ms-welcome-h2",children:T})]})})]})}function Wh(){return s.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",children:s.jsx("path",{d:"M3 2.5v7l6-3.5-6-3.5Z"})})}function Ck({value:e,systemLocale:t,onChange:n}){const r=V().web.settings,l=[{value:"system",label:r.languageSystem({detected:r.languageNames[t]})},...nc.map(d=>({value:d,label:r.languageNames[d]}))],o=async d=>{try{const m=await q.setLanguage(d);n({locale:m.locale,setting:m.languageSetting,systemLocale:m.systemLocale})}catch(m){Pe.show(r.languageFailed({detail:pe(m)}))}},c=r.languageNames[e==="system"?t:e];return s.jsx(At,{className:"ms-welcome-lang",variant:"pill",icon:"globe",display:c,value:e,options:l,onChange:d=>{o(d)},label:r.language})}function qu({title:e,intro:t,children:n,footer:a}){return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ms-panel-head",children:[s.jsx("h2",{id:"ms-welcome-h2",children:e}),s.jsx("p",{children:t})]}),s.jsx("div",{className:"ms-panel-body",children:n}),s.jsx("div",{className:"ms-panel-foot",children:a})]})}function Vu({onBack:e,back:t=!0,hint:n=!0,children:a}){const l=V().web.welcome;return s.jsxs(s.Fragment,{children:[s.jsx($,{variant:"ghost",disabled:!t,onClick:e,children:l.back}),s.jsx("div",{className:"ms-grow"}),n?s.jsx("span",{className:"ms-welcome-hint","aria-hidden":"true",children:l.enterHint}):null,a]})}function Ek({checks:e,checking:t,checksRun:n,loadError:a,onRecheck:r,blocking:l,onNext:o,primary:c,onBack:d,revealedRun:m}){const h=V().web.welcome;return i.useEffect(()=>{c.current=l||t?null:o}),s.jsx(qu,{title:h.checkTitle,intro:h.checkIntro,footer:s.jsxs(Vu,{onBack:d,back:!1,hint:!l,children:[l&&e&&!a?s.jsx("span",{className:"ms-welcome-blocked",children:h.blocked}):null,s.jsx($,{variant:"ink",size:"lg",disabled:l||t,onClick:o,children:h.continue})]}),children:s.jsx(ug,{checks:e,checking:!!t,run:n??0,revealedRun:m,loadError:a??null,onRecheck:r,split:!0})})}const Hh=["claude","claude-auth","git","ffmpeg"],Gh=e=>{const t=Hh.indexOf(e.id);return t===-1?Hh.length:t},Xh=e=>!!e.technical&&!(e.required&&!e.ok);function ug({checks:e,checking:t,run:n,revealedRun:a,loadError:r,onRecheck:l,split:o=!1}){const d=V().web.welcome,m=e&&o?e.filter(j=>!Xh(j)).sort((j,S)=>Gh(j)-Gh(S)):e,u=e&&o?e.filter(Xh):[],h=gk(!!e?.some(j=>j.action),l),[f,x]=i.useState(()=>a.current===n?1/0:0),p=m?.length??0,g=m!==null&&!t;i.useEffect(()=>{if(!g)return;if(a.current===n||wr()){a.current=n,x(1/0);return}x(0);let j=0;const S=setInterval(()=>{j+=1,x(j),j>=p&&(clearInterval(S),a.current=n,x(1/0))},wk);return()=>clearInterval(S)},[n,g]);const b=t?0:f;if(r&&!t)return s.jsxs("div",{className:"ms-syscheck-error",children:[s.jsx("p",{role:"alert",children:d.serverUnreachable({detail:r})}),s.jsxs($,{variant:"outline",onClick:l,children:[s.jsx(F,{name:"refresh",size:14}),d.checkAgain]})]});if(!m)return s.jsx("ul",{className:"ms-syschecks","aria-label":d.checksList,"aria-busy":"true",children:s.jsxs("li",{className:"ms-syscheck",children:[s.jsx(Ts,{decorative:!0,size:16}),s.jsx("span",{className:"ms-syscheck-label ms-muted",children:d.checking})]})});const v=b>=m.length,y=m.some(j=>(j.id==="claude"||j.id==="claude-auth")&&!j.ok),w=Math.max(m.findIndex(j=>j.id==="claude"),m.findIndex(j=>j.id==="claude-auth"));return s.jsxs(s.Fragment,{children:[s.jsx("ul",{className:"ms-syschecks","aria-label":d.checksList,"aria-busy":!v||void 0,children:m.map((j,S)=>S<b?s.jsx(Zh,{check:j,onRecheck:l,setup:h,after:y&&S===w?s.jsxs("li",{className:"ms-setup-plan",children:[s.jsx(F,{name:"user",size:13}),s.jsx("span",{children:d.planNote})]}):null},j.id):s.jsxs("li",{className:"ms-syscheck",children:[s.jsx(Ts,{decorative:!0,size:16}),s.jsx("span",{className:"ms-syscheck-label ms-muted",children:j.label}),s.jsx("span",{className:"ms-syscheck-value",children:d.checkingRow})]},j.id))}),v&&u.length>0?s.jsxs("details",{className:"ms-tech",children:[s.jsxs("summary",{children:[d.technicalDetails,s.jsxs("span",{className:"ms-faint",children:[" · ",u.length]})]}),s.jsx("ul",{className:"ms-syschecks","aria-label":d.technicalDetails,children:u.map(j=>s.jsx(Zh,{check:j,onRecheck:l,setup:h},j.id))})]}):null]})}function Zh({check:e,onRecheck:t,setup:n,after:a}){const l=V().web.welcome,o=i.useRef(null);if(i.useLayoutEffect(()=>{ti(o.current)},[]),e.ok)return s.jsxs(s.Fragment,{children:[s.jsxs("li",{className:"ms-syscheck",children:[s.jsx("span",{ref:o,className:le("ms-syscheck-mark",e.info?"ms-note":"ms-ok"),"aria-hidden":"true",children:s.jsx(F,{name:e.info?"minus":"check",size:10,strokeWidth:2.4})}),s.jsx("span",{className:"ms-syscheck-label",children:e.label}),s.jsx("span",{className:"ms-syscheck-value",children:e.version??e.message})]}),a]});const c=e.action,d=!e.required&&!c&&!!e.technical;return s.jsxs(s.Fragment,{children:[s.jsxs("li",{className:le("ms-syscheck","ms-fail",e.required&&"ms-required"),children:[s.jsxs("div",{className:"ms-syscheck-line",children:[s.jsx("span",{ref:o,className:le("ms-syscheck-mark",e.required?"ms-warn":"ms-note"),"aria-hidden":"true",children:s.jsx(F,{name:e.required?"close":"minus",size:10,strokeWidth:2.4})}),s.jsx("span",{className:"ms-syscheck-label",children:e.label}),s.jsx(Qs,{tone:e.required?"warn":"neutral",children:e.required?l.missing:d?l.note:l.recommended})]}),s.jsx("p",{className:"ms-syscheck-message",children:e.message}),c?s.jsx(yk,{check:{...e,action:c},setup:n,onRecheck:t}):e.waitsFor?null:d?e.fix?s.jsx("p",{className:"ms-syscheck-message ms-syscheck-advice",children:e.fix}):null:e.fix||e.required?s.jsxs("div",{className:"ms-remedy",children:[e.fix?s.jsxs("div",{className:"ms-remedy-text",children:[s.jsx("span",{className:"ms-welcome-cap ms-plain",children:l.remedy}),s.jsx("span",{className:"ms-remedy-plain",children:e.fix})]}):s.jsx("div",{className:"ms-grow"}),s.jsxs($,{size:"sm",variant:"outline",onClick:t,children:[s.jsx(F,{name:"refresh",size:12}),l.checkAgain]})]}):null]}),a]})}function Tk({workspace:e,checks:t,onRecheck:n,onBack:a,onSaved:r,primary:l}){const o=V(),c=o.web.welcome,d=e?.path??null,[m,u]=i.useState(d??""),[h,f]=i.useState(!1),[x,p]=i.useState(null);i.useEffect(()=>{d&&u(R=>R||d)},[d]);const g=m.trim(),b=!!d&&g===d,[v,y]=i.useState(null),w=b&&!!e?.settings&&!e?.error;i.useEffect(()=>{if(!w){y(null);return}let R=!1;return q.listProjects().then(P=>{R||y(P.map(z=>z.slug))}).catch(()=>{R||y(null)}),()=>{R=!0}},[w]);const j=xt(),S=async()=>{try{const R=await j?.pickFolder(c.pickFolderTitle,g||void 0);R&&(u(R),p(null))}catch(R){p(pe(R))}},k=i.useRef(!1),E=async()=>{if(!(!g||k.current)){k.current=!0,f(!0),p(null);try{const R=await q.setWorkspace(g);r(R)}catch(R){p(c.saveFailed({detail:pe(R)})),f(!1),k.current=!1}}};i.useEffect(()=>{l.current=g&&!h?()=>{E()}:null});let N;x?N=s.jsxs("p",{role:"alert",className:"ms-ws-status ms-warn",children:[s.jsx(F,{name:"warn",size:12}),x]}):b&&e?.error?N=s.jsxs("p",{role:"alert",className:"ms-ws-status ms-warn",children:[s.jsx(F,{name:"warn",size:12}),kk(e.error,d,c)]}):w?N=s.jsxs("p",{className:"ms-ws-status ms-ok",children:[s.jsx(F,{name:"check",size:12,strokeWidth:2}),v?c.statusCurrent({count:v.length}):c.statusChecking]}):N=s.jsx("p",{className:"ms-ws-status",children:c.statusNew});const C=(v??[]).slice(0,Kh);return s.jsxs(qu,{title:c.workspaceTitle,intro:c.workspaceIntro,footer:s.jsx(Vu,{onBack:a,children:s.jsx($,{variant:"ink",size:"lg",loading:h,disabled:!g,onClick:()=>{E()},children:c.continue})}),children:[s.jsxs("div",{className:"ms-ws-field",children:[s.jsx("label",{className:"ms-welcome-label",htmlFor:"ms-ws-path",children:c.folder}),s.jsxs("div",{className:"ms-ws-row",children:[s.jsxs("div",{className:"ms-ws-input",children:[s.jsx(F,{name:"folder",size:15}),s.jsx(ms,{id:"ms-ws-path",className:"ms-mono",value:m,spellCheck:!1,autoComplete:"off",placeholder:c.pathPlaceholder,"aria-invalid":x?!0:void 0,onChange:R=>{u(R.target.value),p(null)}})]}),j?s.jsx($,{variant:"outline",size:"lg",disabled:h,onClick:()=>{S()},children:o.web.common.chooseFolder}):null]}),N]}),g?s.jsxs("div",{className:"ms-ws-preview","aria-label":c.preview,role:"group",children:[s.jsxs("div",{className:"ms-ws-root",children:[g.replace(/\/+$/,""),"/"]}),C.map(R=>s.jsxs("div",{children:["├─ ",s.jsxs("span",{className:"ms-ws-name",children:[R,"/"]})," ",s.jsxs("span",{className:"ms-faint",children:["· ",Vh]})]},R)),v&&v.length>Kh?s.jsx("div",{children:"├─ …"}):null,s.jsxs("div",{children:["└─ ",s.jsxs("span",{className:"ms-faint",children:[c.previewProject," · ",Vh]})]})]}):null,t?s.jsx(Rk,{checks:t,onRecheck:n}):null]})}function Rk({checks:e,onRecheck:t}){const a=V().web.welcome,[r,l]=i.useState(!1),o=e.filter(m=>!m.info),c=o.filter(m=>m.ok).length,d=c<o.length;return s.jsxs("div",{className:"ms-ws-checks",children:[s.jsxs("div",{className:"ms-ws-checks-head",children:[s.jsxs("button",{type:"button",className:"ms-ws-checks-toggle","aria-expanded":r,"aria-controls":"ms-ws-checks-list",onClick:()=>l(m=>!m),children:[s.jsx("span",{className:le("ms-syscheck-mark",d?"ms-note":"ms-ok"),"aria-hidden":"true",children:s.jsx(F,{name:d?"minus":"check",size:10,strokeWidth:2.4})}),s.jsx("b",{children:d?a.systemNotes:a.systemReady}),s.jsxs("span",{className:"ms-muted",children:["· ",a.checksPassed({ok:c,total:o.length})]}),s.jsx(F,{name:"chevron",size:12,className:le("ms-ws-chev",r&&"ms-open")})]}),s.jsx($,{size:"sm",variant:"ghost",onClick:t,children:a.recheck})]}),r?s.jsx("ul",{id:"ms-ws-checks-list",className:"ms-ws-checks-list",children:e.map(m=>s.jsxs("li",{children:[s.jsx("span",{className:le("ms-ws-dot",m.ok&&!m.info?"ms-ok":"ms-note"),"aria-hidden":"true"}),s.jsx("span",{className:"ms-syscheck-label",children:m.label}),s.jsx("span",{className:"ms-syscheck-value",children:m.ok?m.version??m.message:a.recommended})]},m.id))}):null]})}function Mk({onBack:e,onFinish:t,primary:n}){const r=V().web.welcome,[l,o]=i.useState(""),[c,d]=i.useState(""),[m,u]=i.useState(!1),[h,f]=i.useState(null),[x,p]=i.useState(!1),g=i.useRef(null);i.useEffect(()=>{g.current?.focus({preventScroll:!0})},[]);const b=i.useRef(!1),v=async()=>{const y=l.trim();if(!y||b.current)return;const w=c.trim()?Nk(c):null;if(c.trim()&&!w){p(!0);return}b.current=!0,u(!0),f(null),p(!1);let j;try{j=(await q.createProject(y)).slug}catch(S){f(r.createFailed({detail:pe(S)})),u(!1),b.current=!1;return}if(w){let S="source";try{const k=await q.addBrandSource(j,{kind:"website",url:w});S="analysis",await q.analyzeBrand(j,[k.id]),Pe.show(r.createdLearning({name:y,site:new URL(w).host}),{tone:"ok"})}catch(k){const E=pe(k);Pe.show(S==="source"?r.sourceFailed({detail:E}):r.analysisFailed({detail:E}),{sticky:!0})}}else Pe.show(r.created({name:y}),{tone:"ok"});t(es.project(j,"brand"))};return i.useEffect(()=>{n.current=l.trim()&&!m?()=>{v()}:null}),s.jsxs(qu,{title:r.projectTitle,intro:r.projectIntro,footer:s.jsxs(Vu,{onBack:e,children:[s.jsx($,{variant:"ghost",disabled:m,onClick:()=>t(es.projects()),children:r.skip}),s.jsx($,{variant:"ink",size:"lg",loading:m,disabled:!l.trim(),onClick:()=>{v()},children:r.create})]}),children:[s.jsxs("div",{className:"ms-ws-field",children:[s.jsx("label",{className:"ms-welcome-label",htmlFor:"ms-project-name",children:r.projectName}),s.jsx(ms,{id:"ms-project-name",ref:g,value:l,placeholder:r.projectNamePlaceholder,autoComplete:"off",onChange:y=>{o(y.target.value),f(null)}})]}),s.jsxs("div",{className:"ms-ws-field",children:[s.jsxs("label",{className:"ms-welcome-label",htmlFor:"ms-project-site",children:[r.website," ",s.jsxs("span",{className:"ms-faint",children:["· ",r.optional]})]}),s.jsx(ms,{id:"ms-project-site",value:c,placeholder:r.websitePlaceholder,inputMode:"url",autoComplete:"url",spellCheck:!1,"aria-invalid":x||void 0,"aria-describedby":x?"ms-project-site-error":void 0,onChange:y=>{d(y.target.value),p(!1)}}),x?s.jsxs("p",{id:"ms-project-site-error",role:"alert",className:"ms-ws-status ms-warn",children:[s.jsx(F,{name:"warn",size:12}),r.websiteInvalid]}):null]}),h?s.jsxs("p",{role:"alert",className:"ms-ws-status ms-warn",children:[s.jsx(F,{name:"warn",size:12}),h]}):null]})}const mg=["image","svg","video","font","audio","other"],hg=30,fg=40,On=e=>e.split("/").pop()??e;function pg(e,t){const n=[...e];for(const a of t){const r=a.trim().slice(0,fg);if(!(!r||n.some(l=>l.toLowerCase()===r.toLowerCase()))){if(n.length>=hg)break;n.push(r)}}return n}const Po=e=>e.split(",").map(t=>t.trim()).filter(Boolean),$k=e=>/\b(white|light|inverse|negative|reversed|bianco|chiaro)\b/i.test(`${e.file} ${e.tags.join(" ")}`),Fk=e=>e.kind==="svg"||/\.(png|webp|gif|avif)$/i.test(e.file),Pk=["date","name","kind","duration"];function Ak(e,t){const n=(o,c)=>On(o.file).localeCompare(On(c.file),void 0,{numeric:!0,sensitivity:"base"})||o.file.localeCompare(c.file),a=e.map((o,c)=>({a:o,i:c})),r=o=>mg.indexOf(o.kind),l=(o,c)=>{if(t==="name")return n(o.a,c.a);if(t==="kind")return r(o.a)-r(c.a)||n(o.a,c.a);if(t==="duration"){const d=o.a.durationSec??null,m=c.a.durationSec??null;return d===null||m===null?d===m?n(o.a,c.a):d===null?1:-1:m-d||n(o.a,c.a)}return c.a.addedAt.localeCompare(o.a.addedAt)||o.i-c.i};return a.sort(l).map(o=>o.a)}function Ku(e,t){if(e<1e3)return`${t(e)} B`;const n=["KB","MB","GB"];let a=e/1e3,r=0;for(;a>=1e3&&r<n.length-1;)a/=1e3,r++;return`${t(Math.round(a*(a<10?10:1))/(a<10?10:1))} ${n[r]}`}const Lk=["ask","whisper","openai","elevenlabs","never"],Ik=["small","large-v3-turbo"],zk=["whisper.cpp","openai-whisper","faster-whisper"],Ok=1e3,xg=e=>e.slice(Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"))+1);function Dk(){const e=V(),t=e.transcription,n=rs(),[a,r]=i.useState(null),[l,o]=i.useState(null),[c,d]=i.useState(null),[m,u]=i.useState(null),[h,f]=i.useState(""),[x,p]=i.useState("whisper.cpp"),[g,b]=i.useState(""),v=()=>Promise.resolve().then(()=>q.getTranscription());i.useEffect(()=>{let T=!0;return v().then(W=>{T&&(r(W),W.settings.custom&&(f(W.settings.custom.program),p(W.settings.custom.engine),b(W.settings.custom.modelFile??"")))},W=>{T&&o(t.loadFailed({detail:pe(W)}))}),()=>{T=!1}},[t]);const y=a?.download.state==="running"||a?.detection.state==="running";i.useEffect(()=>{if(!y)return;let T=!0;const W=window.setInterval(()=>{v().then(Z=>{T&&r(Z)},()=>{})},Ok);return()=>{T=!1,window.clearInterval(W)}},[y]);const w=async(T,W,Z=t.saveFailed)=>{d(T);try{const A=await W();return r(A??await v()),!0}catch(A){return Pe.show(Z({detail:pe(A)})),!1}finally{d(null)}},j=T=>Ku(T,W=>Vs(n,W));if(!a)return s.jsxs("div",{className:"ms-set-narrow",children:[s.jsx(ua,{title:t.title,sub:t.sub}),l?s.jsx(oa,{children:l}):s.jsx(Dt,{className:"ms-set-card ms-tset-loading","data-enter":!0,children:s.jsx(Ts,{decorative:!0,size:16})})]});const S=a.settings,k=a.download,E=Lk.map(T=>{const W=T==="openai"&&!a.providers.openai||T==="elevenlabs"&&!a.providers.elevenlabs;return{value:T,label:t.methods[T],disabled:W&&S.method!==T,...W?{title:t.noKey}:{}}}),N=T=>t.perMinute({cost:dl(e,n,T)??""}),C=S.method==="openai"?`${t.paidNote} ${N(a.prices.openai)}`:S.method==="elevenlabs"?`${t.paidNote} ${N(a.prices.elevenlabs)}`:t.methodSub,R=async()=>{u(null),d("program");try{const T={program:h.trim(),engine:x,...x==="whisper.cpp"&&g.trim()?{modelFile:g.trim()}:{}};r(await q.saveTranscription({custom:T})),Pe.show(t.saved,{tone:"ok"})}catch(T){u(pe(T))}finally{d(null)}},P=async T=>{const W=xt();if(W?.pickFile)try{const Z=await W.pickFile(T==="program"?t.program:t.modelFile);if(!Z)return;if(T==="program"){f(Z);const A=xg(Z).toLowerCase();p(A.startsWith("faster-whisper")||A.startsWith("whisper-ctranslate2")?"faster-whisper":A==="whisper"?"openai-whisper":"whisper.cpp")}else b(Z);u(null)}catch(Z){u(t.pickFailed({detail:pe(Z)}))}},z=!!xt()?.pickFile,O=T=>{f(T.program),p(T.engine),b(""),w(`use:${T.program}`,()=>q.saveTranscription({custom:{program:T.program,engine:T.engine}}))};return s.jsxs("div",{className:"ms-set-narrow",children:[s.jsx(ua,{title:t.title,sub:t.sub}),s.jsxs(Dt,{className:"ms-set-card","data-enter":!0,children:[s.jsxs("div",{className:"ms-tset-block",children:[s.jsxs("div",{className:"ms-set-row-text",children:[s.jsx("b",{children:t.method}),s.jsx("span",{children:C})]}),s.jsx(it,{className:"ms-tset-methods",label:t.method,value:S.method,options:E,onChange:T=>{w("method",()=>q.saveTranscription({method:T}))}})]}),s.jsxs("div",{className:"ms-tset-block",children:[s.jsxs("div",{className:"ms-set-row-text",children:[s.jsx("b",{children:t.model}),s.jsx("span",{children:t.modelSub})]}),s.jsx(it,{className:"ms-tset-seg",label:t.model,value:S.model,options:Ik.map(T=>({value:T,label:t.models[T]})),onChange:T=>{w("model",()=>q.saveTranscription({model:T}))}}),s.jsx("ul",{className:"ms-tset-models",children:a.models.map(T=>{const W=k.state==="running"&&k.model===T.id;return s.jsxs("li",{className:"ms-tset-model",children:[s.jsxs("span",{className:"ms-tset-model-text",children:[s.jsx("b",{children:t.models[T.id]}),s.jsx("span",{children:T.installed?t.installedSize({size:j(T.bytesOnDisk||T.sizeBytes)}):t.notInstalled})]}),T.installed?s.jsxs($,{size:"sm",variant:"ghost",disabled:c!==null||W,loading:c===`rm:${T.id}`,onClick:()=>{w(`rm:${T.id}`,async()=>{await q.removeWhisperModel(T.id)},t.removeFailed)},children:[s.jsx(F,{name:"trash",size:12}),t.remove]}):W?null:s.jsxs($,{size:"sm",variant:"outline",disabled:c!==null||k.state==="running",loading:c===`dl:${T.id}`,onClick:()=>{w(`dl:${T.id}`,async()=>{await q.downloadWhisperModel(T.id,T.sizeBytes)},t.installFailed)},children:[s.jsx(F,{name:"download",size:12}),t.install({size:j(T.sizeBytes)})]}),W?s.jsxs("span",{className:"ms-tset-progress",children:[s.jsx(kr,{value:k.total?k.bytes/k.total*100:0,label:t.downloading({percent:k.total?Math.round(k.bytes/k.total*100):0})}),s.jsx("span",{children:t.downloading({percent:k.total?Math.round(k.bytes/k.total*100):0})})]}):null,k.state==="failed"&&k.model===T.id?s.jsx("span",{className:"ms-tset-error",role:"alert",children:t.installFailed({detail:k.error??""})}):null]},T.id)})})]}),s.jsx(Xn,{title:t.whyTitle,sub:t.why})]}),s.jsxs(Dt,{className:"ms-set-card","data-enter":!0,children:[s.jsxs("div",{className:"ms-tset-block",children:[s.jsxs("div",{className:"ms-tset-headrow",children:[s.jsxs("div",{className:"ms-set-row-text",children:[s.jsx("b",{children:t.useInstalled}),s.jsx("span",{children:a.whisper?t.inUse({engine:a.whisper.engine,source:t.sources[a.whisper.source]}):t.noneInUse})]}),s.jsxs($,{size:"sm",variant:"ghost",disabled:a.detection.state==="running",loading:c==="detect",onClick:()=>{w("detect",()=>q.detectWhisper())},children:[s.jsx(F,{name:"refresh",size:12}),t.searchAgain]})]}),a.whisper?s.jsxs("p",{className:"ms-tset-found",role:"status",children:[s.jsx(F,{name:"check",size:12}),Bk(e,a.whisper)]}):null,s.jsx("span",{className:"ms-lib-label ms-tset-cap",children:t.detected}),a.detection.state==="running"?s.jsxs("p",{className:"ms-tset-note",children:[s.jsx(Ts,{decorative:!0,size:12}),t.searching]}):a.detected.length===0?s.jsx("p",{className:"ms-tset-note",children:t.noneDetected}):s.jsx("ul",{className:"ms-tset-found-list",children:a.detected.map(T=>s.jsxs("li",{className:le("ms-tset-detected",T.problem&&"ms-tset-bad"),children:[s.jsxs("span",{className:"ms-tset-model-text",children:[s.jsxs("b",{children:[T.engine,T.version?` · ${T.version}`:""]}),s.jsx("span",{className:"ms-tset-mono",children:T.program}),T.problem?s.jsx("span",{className:"ms-tset-error",children:t.problem({detail:T.problem})}):T.needsModel?s.jsx("span",{children:t.needsModel}):T.downloadsOwnModel?s.jsx("span",{children:t.downloadsOwn}):null]}),!T.problem&&S.custom?.program!==T.program?s.jsx($,{size:"sm",variant:"outline",disabled:c!==null,loading:c===`use:${T.program}`,onClick:()=>O(T),children:t.useThis}):null]},T.program))})]}),s.jsxs("div",{className:"ms-tset-block",children:[s.jsx("span",{className:"ms-lib-label ms-tset-cap",children:t.custom}),s.jsxs("div",{className:"ms-tset-field",children:[s.jsx("label",{htmlFor:"ms-tset-program",children:t.program}),s.jsxs("div",{className:"ms-tset-pick",children:[s.jsx(ms,{id:"ms-tset-program",className:"ms-tset-mono",value:h,placeholder:t.programPlaceholder,spellCheck:!1,onChange:T=>{f(T.target.value),u(null)}}),z?s.jsx($,{size:"sm",variant:"outline",onClick:()=>{P("program")},children:t.choose}):null]})]}),s.jsxs("div",{className:"ms-tset-field",children:[s.jsx("span",{className:"ms-tset-lbl","aria-hidden":"true",children:t.engine}),s.jsx(At,{label:t.engine,value:x,options:zk.map(T=>({value:T,label:T})),onChange:T=>{p(T),u(null)}})]}),x==="whisper.cpp"?s.jsxs("div",{className:"ms-tset-field",children:[s.jsx("label",{htmlFor:"ms-tset-modelfile",children:t.modelFile}),s.jsxs("div",{className:"ms-tset-pick",children:[s.jsx(ms,{id:"ms-tset-modelfile",className:"ms-tset-mono",value:g,placeholder:t.modelFilePlaceholder,spellCheck:!1,onChange:T=>{b(T.target.value),u(null)}}),z?s.jsx($,{size:"sm",variant:"outline",onClick:()=>{P("model")},children:t.choose}):null]})]}):s.jsx("p",{className:"ms-tset-note",children:t.pythonCache}),m?s.jsx("p",{className:"ms-tset-error",role:"alert",children:m}):null,s.jsxs("div",{className:"ms-tset-actions",children:[S.custom?s.jsx($,{size:"sm",variant:"ghost",disabled:c!==null,loading:c==="stop",onClick:()=>{w("stop",()=>q.saveTranscription({custom:null}))},children:t.stopUsing}):null,s.jsx($,{size:"sm",variant:"ink",disabled:!h.trim()||c!==null,loading:c==="program",onClick:()=>{R()},children:c==="program"?t.testing:t.testAndSave})]})]})]})]})}function Bk(e,t){const n=e.transcription;return n.found({engine:t.engine,version:t.version??n.versionUnknown,model:xg(t.model),gpu:t.gpu===null?n.gpu.unknown:t.gpu?n.gpu.yes:n.gpu.no})}const Uk=["general","system","paid","transcription","usage","notifications","updates"],gg=[["openai","OpenAI","OPENAI_API_KEY","AI"],["elevenlabs","ElevenLabs","ELEVENLABS_API_KEY","11"],["pexels","Pexels","PEXELS_API_KEY","Px"],["unsplash","Unsplash","UNSPLASH_ACCESS_KEY","Un"]],Ti=["system","light","dark"];function _k(e){const{section:t,checks:n,checking:a}=e,l=V().web.appSettings,[o,c]=i.useState(null),[d,m]=i.useState(null);i.useEffect(()=>{let p=!0;return q.getSecrets().then(g=>{p&&c(g)}).catch(g=>{p&&m(l.paid.loadFailed({detail:pe(g)}))}),()=>{p=!1}},[l]);const u=o?.filter(p=>p.configured).length,h=n?.filter(p=>!p.ok&&p.required).length??0,f=a||!n?"ms-busy":h?"ms-warn":"",x={system:s.jsx("span",{className:le("ms-set-dot",f),"aria-hidden":"true"}),paid:u!==void 0?s.jsx("span",{className:"ms-n",children:l.configured({n:u,total:gg.length})}):null,updates:s.jsx("span",{className:"ms-n ms-set-mono",children:"0.1.1"})};return s.jsxs("div",{className:"ms-settings",children:[s.jsxs("nav",{className:"ms-set-nav","aria-label":l.sections,children:[s.jsx("span",{className:"ms-set-cap",children:l.appName}),Uk.map(p=>s.jsxs("button",{type:"button",className:le("ms-navitem",t===p&&"ms-on"),"aria-current":t===p?"page":void 0,onClick:()=>Bs(es.settings(p)),children:[s.jsx("span",{className:"ms-navitem-label",children:l.nav[p]}),x[p]??null]},p))]}),s.jsx(dg,{section:t,children:t==="general"?s.jsx(qk,{...e}):t==="system"?s.jsx(Wk,{...e}):t==="paid"?s.jsx(Zk,{secrets:o,error:d,onChange:p=>c(g=>(g??[]).map(b=>b.provider===p.provider?p:b)),reload:c}):t==="transcription"?s.jsx(Dk,{}):t==="usage"?s.jsx(tN,{}):t==="notifications"?s.jsx(eN,{}):s.jsx(sN,{})})]})}function qk({settings:e,checks:t,checking:n,loadError:a,onRecheck:r,language:l,systemLocale:o,onLanguage:c,onSettings:d}){const m=V(),u=m.web.appSettings,[h,f]=i.useState(null),x=async b=>{f(null);try{const v=await q.setLanguage(b);c({locale:v.locale,setting:v.languageSetting,systemLocale:v.systemLocale})}catch(v){f(m.web.settings.languageFailed({detail:pe(v)}))}},p=async b=>{f(null);try{d(await q.updateSettings({theme:b}))}catch(v){f(m.web.app.settingsSaveFailed({detail:pe(v)}))}},g=[{value:"system",label:m.web.settings.languageSystem({detected:m.web.settings.languageNames[o]})},...nc.map(b=>({value:b,label:m.web.settings.languageNames[b]}))];return s.jsxs(s.Fragment,{children:[h?s.jsx(oa,{children:h}):null,s.jsxs("div",{className:"ms-set-cols ms-wide-side",children:[s.jsxs("div",{className:"ms-set-col",children:[s.jsx(ua,{title:u.general.title,sub:u.appliesAll}),s.jsxs(Dt,{className:"ms-set-card","data-enter":!0,children:[s.jsx(Xn,{title:u.general.language,sub:u.general.languageSub,children:s.jsx(At,{label:u.general.language,value:l,options:g,onChange:b=>{x(b)}})}),s.jsx(Xn,{title:u.general.theme,sub:u.general.themeSub,children:s.jsx(Vk,{value:e.theme,onChange:b=>{p(b)}})})]}),s.jsxs("p",{className:"ms-set-faint ms-set-small ms-set-pointer","data-enter":!0,children:[s.jsx(F,{name:"gear",size:12}),u.general.agentPointer]})]}),s.jsx("div",{className:"ms-set-col ms-set-side-top",children:s.jsx(Kk,{checks:t,checking:n,loadError:a,onRecheck:r})})]})]})}function Vk({value:e,onChange:t}){const n=V(),a=i.useRef([]),r=Math.max(0,Ti.indexOf(e)),l=o=>{const c=Ma(o.key,r,Ti.length);c!==null&&(o.preventDefault(),a.current[c]?.focus(),t(Ti[c]))};return s.jsx("div",{role:"radiogroup","aria-label":n.web.theme.aria,className:"ms-theme-group",onKeyDown:l,children:Ti.map((o,c)=>s.jsxs("button",{ref:d=>{a.current[c]=d},type:"button",role:"radio","aria-checked":e===o,tabIndex:e===o?0:-1,className:"ms-theme-opt",onClick:()=>{e!==o&&t(o)},children:[s.jsx("span",{className:"ms-theme-preview","aria-hidden":"true",children:o==="system"?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-theme-light"}),s.jsx("span",{className:"ms-theme-dark"})]}):s.jsx("span",{className:o==="light"?"ms-theme-light":"ms-theme-dark"})}),n.web.theme[o]]},o))})}function Kk({checks:e,checking:t,loadError:n,onRecheck:a}){const r=V(),l=r.web.appSettings.status,o=e?.filter(h=>!h.ok&&h.required)??[],c=e?.filter(h=>!h.ok&&!h.required)??[],d=t||!e&&!n,m=d?l.checking:n?r.web.welcome.serverUnreachable({detail:n}):o.length?l.problems({count:o.length}):c.length?l.notes({count:c.length}):l.ok,u=(e??[]).map(h=>h.ok&&h.id!=="updates"?`${h.label}${h.version?` ${h.version}`:""}`:null).filter(Boolean).join(" · ");return s.jsxs(Dt,{className:"ms-status","data-enter":!0,children:[s.jsxs("div",{className:"ms-status-head",children:[s.jsx("span",{className:le("ms-status-mark",d?"ms-busy":(o.length>0||!!n)&&"ms-warn"),"aria-hidden":"true",children:d?s.jsx(Ts,{decorative:!0,size:12}):s.jsx(F,{name:o.length>0||n?"warn":"check",size:10,strokeWidth:2.4})}),s.jsx("b",{children:m}),s.jsx($,{size:"sm",variant:"ghost",disabled:t,onClick:a,children:l.checkAgain})]}),o[0]?s.jsxs("span",{className:"ms-status-line",children:[o[0].label,": ",o[0].message]}):null,u?s.jsx("span",{className:"ms-status-line",children:u}):null,s.jsx("button",{type:"button",className:"ms-blink",onClick:()=>Bs(es.settings("system")),children:l.details})]})}function Wk({checks:e,checking:t,checksRun:n,loadError:a,onRecheck:r}){const o=V().web.appSettings,c=i.useRef(n);return s.jsxs("div",{className:"ms-set-narrow",children:[s.jsx(ua,{title:o.system.title,sub:o.system.sub,children:s.jsxs($,{variant:"outline",disabled:t,onClick:r,children:[t?s.jsx(Ts,{decorative:!0,size:14}):s.jsx(F,{name:"refresh",size:14}),o.status.checkAgain]})}),s.jsx(Dt,{className:"ms-syscard","data-enter":!0,children:s.jsx(ug,{checks:e,checking:t,run:n,revealedRun:c,loadError:a,onRecheck:r})}),s.jsx(Dt,{className:"ms-syscard","data-enter":!0,children:s.jsx(Xk,{run:n})})]})}const Hk=(e,t,n)=>n({n:Vs(e,t/1e6,{maximumFractionDigits:1,minimumFractionDigits:1})}),Gk=1e3;function Xk({run:e}){const t=V(),n=t.web.render,a=rs(),[r,l]=i.useState(null),[o,c]=i.useState(null),[d,m]=i.useState(null),[u,h]=i.useState(!1),f=()=>Promise.resolve().then(()=>q.getRenderEngine());i.useEffect(()=>{let w=!0;return f().then(j=>{w&&(l(j),c(null))},j=>{w&&c(pe(j))}),()=>{w=!1}},[e]);const x=r?.download.state==="running";i.useEffect(()=>{if(!x)return;let w=!0;const j=window.setInterval(()=>{f().then(S=>{w&&l(S)},()=>{})},Gk);return()=>{w=!1,window.clearInterval(j)}},[x]);const p=()=>{m({kind:"checking"}),Promise.resolve().then(()=>q.getChromeDownloadInfo()).then(w=>m({kind:"offer",offer:w}),w=>m({kind:"failed",detail:pe(w)}))},g=w=>{h(!0),Promise.resolve().then(()=>q.downloadChrome(w.sizeBytes)).then(j=>{l(j),m(null)},j=>m({kind:"failed",detail:pe(j)})).finally(()=>h(!1))},b=w=>Hk(a,w,n.sizeMb),v=r?r.kind==="electron"?n.engineElectron:r.kind==="system"?r.version?n.engineSystem({version:r.version}):n.engineSystemPlain:r.kind==="cft"?n.engineCft({version:r.version??""}):r.kind==="injected"?n.engineInjected:n.engineNone:null,y=r?.download;return s.jsxs("div",{className:"ms-engine",children:[s.jsxs("div",{className:"ms-syscheck",children:[r===null&&!o?s.jsx(Ts,{decorative:!0,size:16}):r?.kind?s.jsx("span",{className:"ms-syscheck-mark ms-ok","aria-hidden":"true",children:s.jsx(F,{name:"check",size:10,strokeWidth:2.4})}):s.jsx("span",{className:"ms-syscheck-mark ms-note","aria-hidden":"true",children:s.jsx(F,{name:"minus",size:10,strokeWidth:2.4})}),s.jsx("span",{className:"ms-syscheck-label",children:n.engineLabel}),s.jsx("span",{className:"ms-syscheck-value",children:v??""})]}),o?s.jsx("p",{className:"ms-syscheck-message",role:"alert",children:n.engineLoadFailed({detail:o})}):null,r&&!r.kind?s.jsx("p",{className:"ms-syscheck-message",children:n.engineNoneHint}):null,y?.state==="running"&&y.total?s.jsxs("div",{className:"ms-engine-progress",children:[s.jsx(kr,{value:y.bytes/y.total*100,label:n.downloading({done:b(y.bytes),total:b(y.total)})}),s.jsx("span",{className:"ms-syscheck-message",children:n.downloading({done:b(y.bytes),total:b(y.total)})})]}):null,y?.state==="done"&&r?.kind?s.jsx("p",{className:"ms-syscheck-message",role:"status",children:n.downloaded}):null,y?.state==="failed"?s.jsx("p",{className:"ms-syscheck-message",role:"alert",children:n.downloadFailed({detail:y.error??""})}):null,r?.downloadable&&y?.state!=="running"&&d===null?s.jsxs("div",{className:"ms-remedy",children:[s.jsx("div",{className:"ms-grow"}),s.jsxs($,{size:"sm",variant:"outline",onClick:p,children:[s.jsx(F,{name:"download",size:12}),n.downloadOffer]})]}):null,d?.kind==="checking"?s.jsx("p",{className:"ms-syscheck-message",role:"status",children:n.consentChecking}):null,d?.kind==="failed"?s.jsxs("div",{className:"ms-remedy",children:[s.jsx("p",{className:"ms-syscheck-message",role:"alert",children:n.consentFailed({detail:d.detail})}),s.jsxs($,{size:"sm",variant:"outline",onClick:p,children:[s.jsx(F,{name:"refresh",size:12}),n.retry]})]}):null,d?.kind==="offer"?s.jsxs("div",{className:"ms-engine-consent",role:"group","aria-label":n.consentTitle,children:[s.jsx("b",{children:n.consentTitle}),s.jsx("p",{children:n.consentBody({version:d.offer.version,size:b(d.offer.sizeBytes)})}),s.jsxs("div",{className:"ms-engine-actions",children:[s.jsx($,{size:"sm",variant:"ghost",disabled:u,onClick:()=>m(null),children:t.common.cancel}),s.jsx($,{size:"sm",variant:"ink",loading:u,onClick:()=>g(d.offer),children:n.consentAgree({size:b(d.offer.sizeBytes)})})]})]}):null]})}function Zk({secrets:e,error:t,onChange:n,reload:a}){const l=V().web.appSettings.paid,[o,c]=i.useState({});i.useEffect(()=>{let m=!0;return Promise.resolve().then(()=>q.getKeyChecks()).then(u=>{m&&c(h=>({...u,...h}))}).catch(()=>{}),()=>{m=!1}},[]);const d=(m,u)=>c(h=>({...h,[m]:u}));return s.jsxs("div",{className:"ms-set-narrow",children:[s.jsx(ua,{title:l.title,sub:l.sub}),t?s.jsx(oa,{children:t}):null,s.jsxs(Dt,{className:"ms-set-card","data-enter":!0,children:[!e&&!t?s.jsx("div",{className:"ms-set-pad",children:s.jsx(Ts,{size:16})}):null,e?gg.map(([m,u,h,f])=>s.jsx(Qk,{id:m,name:u,env:h,mark:f,status:e.find(x=>x.provider===m),onChange:n,reload:a,check:o[m]??null,onCheck:x=>d(m,x)},m)):null]})]})}const Jk={ok:"ok",missing:"warn",unverified:"neutral",error:"warn"};function Yk({id:e,name:t,check:n}){const r=V().web.appSettings.paid;if(n.capabilities.find(u=>u.capability==="key")?.status==="missing")return s.jsx("p",{className:"ms-set-error ms-key-note",role:"status",children:r.keyRefused});const o=n.capabilities.some(u=>u.status==="missing"),c=n.capabilities.some(u=>u.status==="unverified"),d=n.capabilities.find(u=>u.status==="error"&&u.detail),m=e==="elevenlabs"?hj.elevenlabs.filter(u=>uh.elevenlabs[u]).map(u=>({capability:u,permission:uh.elevenlabs[u],status:n.capabilities.find(h=>h.capability===u)?.status})):n.capabilities.filter(u=>u.status==="missing"&&u.permission).map(u=>({capability:u.capability,permission:u.permission,status:u.status}));return s.jsxs("div",{className:"ms-key-checks",children:[s.jsx("ul",{className:"ms-key-caps","aria-label":r.checksLabel({name:t}),children:n.capabilities.map(u=>s.jsx("li",{children:s.jsx(Qs,{tone:Jk[u.status],dot:!0,children:`${r.caps[u.capability]} · ${r.capStatus[u.status]}`})},u.capability))}),d?s.jsx("p",{className:"ms-key-note",children:r.someErrors({detail:d.detail})}):null,c?s.jsx("p",{className:"ms-key-note",children:r.unverifiedNote}):null,o?s.jsxs("section",{className:"ms-key-help","aria-label":r.permissionsTitle,children:[s.jsx("b",{children:r.permissionsTitle}),s.jsx("p",{children:r.permissionsHelp[e]}),m.length?s.jsx("ul",{children:m.map(u=>s.jsxs("li",{className:le(u.status==="missing"&&"ms-warn"),children:[s.jsx("code",{children:u.permission})," ",s.jsxs("span",{children:[r.caps[u.capability],u.status?` · ${r.capStatus[u.status]}`:""]})]},u.capability))}):null]}):null]})}function Qk({id:e,name:t,env:n,mark:a,status:r,onChange:l,reload:o,check:c,onCheck:d}){const u=V().web.appSettings.paid,[h,f]=i.useState(!1),[x,p]=i.useState(""),[g,b]=i.useState(!1),[v,y]=i.useState(null),w=i.useRef(null);i.useEffect(()=>{h&&Gs(w.current,{y:-6})},[h]);const[j,S]=i.useState(!1),k=i.useRef(null);i.useEffect(()=>{j&&k.current?.focus()},[j]);const E=r?.source==="env",N=r?.source==="keychain",[C,R]=i.useState(null),P=async T=>{R(T),y(null);try{d(await q.checkSecret(e))}catch(W){y(u.checkFailed({detail:pe(W)}))}finally{R(null)}},z=async T=>{if(T.preventDefault(),!(!x.trim()||g)){b(!0),y(null);try{l(await q.setSecret(e,x.trim()));const W=await q.getSecrets();if(o(W),!W.find(Z=>Z.provider===e)?.configured){y(u.notStored);return}p(""),f(!1),Pe.show(u.saved({name:t}),{tone:"ok"})}catch(W){y(u.failed({detail:pe(W)}));return}finally{b(!1)}d(null),await P("saved")}},O=async()=>{S(!1),y(null);try{l(await q.deleteSecret(e)),d(null),Pe.show(u.removed({name:t}))}catch(T){y(u.removeFailed({detail:pe(T)}))}};return s.jsxs("div",{className:"ms-key",children:[s.jsxs("div",{className:"ms-key-row",children:[s.jsx("span",{className:le("ms-key-mark",!r?.configured&&"ms-off"),"aria-hidden":"true",children:a}),s.jsxs("div",{className:"ms-key-text",children:[s.jsxs("b",{children:[s.jsx("span",{children:t})," ",s.jsxs("span",{className:"ms-set-faint",children:["· ",u.uses[e]]})]}),E?s.jsx("span",{children:u.fromEnv({env:n})}):N?s.jsx("span",{className:"ms-ok",children:u.inKeychain}):s.jsx("span",{children:u.notConnected})]}),r?.configured&&!j?s.jsx($,{size:"sm",variant:"ghost","aria-label":u.testLabel({name:t}),loading:C==="test",disabled:C!==null,onClick:()=>{P("test")},children:C==="test"?u.testing:u.test}):null,E?null:s.jsx("div",{className:"ms-key-actions",children:N&&j?s.jsxs("span",{className:"ms-key-confirm",role:"group","aria-label":u.removeConfirm({name:t}),children:[s.jsx("span",{children:u.removeConfirm({name:t})}),s.jsx($,{size:"sm",variant:"danger",onClick:()=>{O()},children:u.remove}),s.jsx($,{ref:k,size:"sm",variant:"ghost",onClick:()=>S(!1),children:u.cancel})]}):N?s.jsxs(s.Fragment,{children:[s.jsx($,{size:"sm","aria-label":u.replaceLabel({name:t}),onClick:()=>{f(!0),p("")},children:u.replace}),s.jsx($,{size:"sm",variant:"ghost","aria-label":u.removeLabel({name:t}),onClick:()=>{f(!1),S(!0)},children:u.remove})]}):h?null:s.jsx($,{size:"sm",variant:"ink",onClick:()=>{f(!0),p("")},children:u.addKey})})]}),h&&!E?s.jsxs("form",{ref:w,className:"ms-key-form",onSubmit:T=>{z(T)},children:[s.jsx(ms,{type:"password",autoFocus:!0,autoComplete:"off",spellCheck:!1,value:x,onChange:T=>p(T.target.value),placeholder:u.keyPlaceholder,"aria-label":u.keyLabel({name:t})}),s.jsx($,{size:"sm",variant:"ghost",onClick:()=>{f(!1),p(""),y(null)},children:u.cancel}),s.jsx($,{type:"submit",size:"sm",variant:"ink",loading:g,disabled:!x.trim()||g,children:g?u.saving:u.save})]}):null,C==="saved"?s.jsxs("p",{className:"ms-key-note",role:"status",children:[s.jsx(Ts,{decorative:!0,size:11})," ",u.savedChecking]}):null,c&&C!=="saved"&&r?.configured?s.jsx(Yk,{id:e,name:t,check:c}):null,v?s.jsx("p",{className:"ms-set-error",role:"alert",children:v}):null]})}function eN(){const e=V(),t=e.web.appSettings,n=t.notifications,[a,r]=i.useState(Bx),[l,o]=i.useState(_x),[c,d]=i.useState(Vx),[m,u]=i.useState(null),[h,f]=i.useState(!1),[x,p]=i.useState(null),g=()=>{uw().then(u)};i.useEffect(()=>{g()},[]);const b=()=>{const w=()=>g();Promise.resolve(Notification.requestPermission(w)).then(w,()=>{})},v=async()=>{f(!0),p(null);try{p(await Kx({title:e.web.app.approvalNotificationTitle,body:n.testButton}))}catch(w){const j=w instanceof Error?w.message:"";p({state:"error",detail:j==="denied"?n.webDenied:j==="default"?n.webDefault:j==="unsupported"?n.webUnsupported:j||n.unsupported})}finally{f(!1),g()}},y=m==="unsupported"?xt()?n.unsupported:n.webUnsupported:m==="denied"?n.webDenied:m==="default"?n.webDefault:null;return s.jsxs("div",{className:"ms-set-narrow",children:[s.jsx(ua,{title:n.title,sub:t.appliesAll}),s.jsxs(Dt,{className:"ms-set-card","data-enter":!0,children:[s.jsx(Xn,{title:n.approvals,sub:n.approvalsSub,children:s.jsx(Un,{on:a,label:n.approvalsLabel,onChange:w=>{rw(w),r(w)}})}),s.jsx(Xn,{title:n.ready,sub:n.readySub,children:s.jsx(Un,{on:l,label:n.readyLabel,onChange:w=>{lw(w),o(w)}})}),s.jsx(Xn,{title:n.sound,sub:n.soundSub,children:s.jsx(Un,{on:c,label:n.soundLabel,onChange:w=>{iw(w),d(w)}})}),s.jsx(Xn,{title:n.test,sub:n.testSub,children:s.jsx($,{variant:"outline",disabled:h,onClick:()=>{v()},children:n.testButton})})]}),y?s.jsx(oa,{action:m==="default"&&!xt()?s.jsx($,{size:"sm",variant:"outline",onClick:b,children:n.webAllow}):void 0,children:y}):null,x?.state==="error"?s.jsx("p",{className:"ms-set-error",role:"alert",children:n.testFailed({detail:x.detail})}):null,x?.state==="blocked"?s.jsxs("div",{className:"ms-set-error",role:"alert",children:[s.jsx("p",{children:xt()?x.reason==="timeout"?n.testTimeout:x.reason==="unsupported"?n.unsupported:n.testBlocked:n.testBlockedWeb}),x.detail?s.jsx("p",{className:"ms-set-small",children:n.testReason({detail:x.detail})}):null]}):null,x?.state==="sent"?s.jsx("p",{className:"ms-set-sub ms-set-small",role:"status",children:n.testSent}):null,x?.state==="unconfirmed"?s.jsx("p",{className:"ms-set-sub ms-set-small",role:"status",children:n.testUnconfirmed}):null,xt()&&x?.state!=="sent"&&!(x?.state==="blocked"&&x.reason==="failed")?s.jsx("p",{className:"ms-set-faint",children:n.howTo}):null]})}function sN(){const t=V().web.appSettings.updates,[n,a]=i.useState("unknown");return i.useEffect(()=>{if(!xt())return;let r=!0,l;const o=c=>{Promise.resolve().then(()=>q.getUpdatesState()).then(d=>{r&&(a(d.state),d.state==="unknown"&&c&&(l=setTimeout(()=>o(!1),1e3)))}).catch(()=>{r&&c&&(l=setTimeout(()=>o(!1),1e3))})};return o(!0),()=>{r=!1,l&&clearTimeout(l)}},[]),s.jsxs("div",{className:"ms-set-narrow",children:[s.jsx(ua,{title:t.title}),s.jsx(Dt,{className:"ms-set-card","data-enter":!0,children:s.jsx(Xn,{title:t.version({version:"0.1.1"}),sub:xt()?n==="off"?t.off:n==="active"?t.automatic:void 0:void 0})})]})}const Ao=e=>`${e}T12:00:00.000Z`;function tN(){const t=V().web.appSettings.usage,[n,a]=i.useState({report:null,error:null}),[r,l]=i.useState(0);i.useEffect(()=>{let d=!0;return q.getUsage().then(m=>{d&&a({report:m,error:null})}).catch(m=>{d&&a({report:null,error:pe(m)})}),()=>{d=!1}},[r]);const{report:o,error:c}=n;return s.jsxs("div",{className:"ms-set-narrow ms-usage",children:[s.jsx(ua,{title:t.title,sub:t.sub}),c?s.jsx(oa,{action:s.jsx($,{size:"sm",variant:"outline",onClick:()=>{a({report:null,error:null}),l(d=>d+1)},children:t.tryAgain}),children:t.loadFailed({detail:c})}):o?o.trackedSince===null?s.jsxs(s.Fragment,{children:[s.jsx(Dt,{className:"ms-set-card","data-enter":!0,children:s.jsx(Rt,{icon:"sparkle",title:t.empty,sub:t.emptySub})}),o.paid.calls>0?s.jsx(Jh,{paid:o.paid,utcOffsetMinutes:o.utcOffsetMinutes}):null]}):s.jsxs(s.Fragment,{children:[s.jsx(nN,{report:o}),s.jsx(Jh,{paid:o.paid,utcOffsetMinutes:o.utcOffsetMinutes})]}):s.jsx(Dt,{className:"ms-set-card","data-enter":!0,children:s.jsxs("div",{className:"ms-set-pad ms-set-inline",role:"status",children:[s.jsx(Ts,{decorative:!0,size:14}),t.loading]})})]})}function nN({report:e}){const t=V(),n=t.web.appSettings.usage,a=t.web.usage,r=rs(),l=v=>a.tokens({count:ia(r,v)}),o=new Date(Date.now()+e.utcOffsetMinutes*6e4).toISOString().slice(0,10),c=Math.max(0,...e.byDay.map(v=>v.tokens)),d=v=>v===o?n.today:ca(r,Ao(v),{weekday:"short",timeZone:"UTC"}),m=v=>v===o?n.today:ca(r,Ao(v),{weekday:"short",month:"short",day:"numeric",timeZone:"UTC"}),u=i.useRef(null);i.useEffect(()=>{u.current?.querySelectorAll(".ms-usage-bar").forEach((v,y)=>{qn(v,[{transform:"scaleY(0)"},{transform:"scaleY(1)"}],qs.l,Vt.out,y*40)})},[]);const h=e.total,f=h.estimated===!0,x=og(t,r,e.billing,h.costUsd,f),p=e.byProject.filter(v=>v.tokens>0),g=e.byKind.filter(v=>v.tokens>0),b=(v,y,w,j,S)=>{const k=dl(t,r,j,S===!0);return s.jsxs("li",{className:"ms-usage-row",children:[s.jsx("span",{className:"ms-usage-name",children:y}),s.jsx("span",{className:"ms-usage-num",children:l(w)}),k?s.jsx("span",{className:"ms-usage-cost",children:k}):null]},v)};return s.jsxs(Dt,{className:"ms-usage-card","data-enter":!0,role:"region","aria-labelledby":"ms-usage-title",children:[s.jsxs("div",{className:"ms-usage-head",children:[s.jsx("b",{id:"ms-usage-title",children:n.week}),s.jsx("span",{className:"ms-usage-total",children:l(_n(h.tokens))})]}),s.jsx("div",{ref:u,className:"ms-usage-bars","aria-hidden":"true",children:e.byDay.map(v=>s.jsxs("div",{className:"ms-usage-col",title:n.barTitle({day:m(v.day),count:ia(r,v.tokens)}),children:[v.day===o&&v.tokens>0?s.jsx("span",{className:"ms-usage-val",children:ia(r,v.tokens)}):null,s.jsx("span",{"data-day":v.day,className:le("ms-usage-bar",v.tokens===0&&"ms-zero",v.day===o&&"ms-today"),style:v.tokens>0&&c>0?{height:`${v.tokens/c*100}%`}:void 0})]},v.day))}),s.jsx("div",{className:"ms-usage-days","aria-hidden":"true",children:e.byDay.map(v=>s.jsx("span",{className:le(v.day===o&&"ms-today"),children:d(v.day)},v.day))}),s.jsxs("table",{className:"ms-sr","aria-label":n.chart,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{scope:"col",children:n.day}),s.jsx("th",{scope:"col",children:n.tokens})]})}),s.jsx("tbody",{children:e.byDay.map(v=>s.jsxs("tr",{children:[s.jsx("th",{scope:"row",children:m(v.day)}),s.jsx("td",{children:ia(r,v.tokens)})]},v.day))})]}),p.length||g.length?s.jsxs("div",{className:"ms-usage-groups",children:[p.length?s.jsxs("div",{className:"ms-usage-group",children:[s.jsx("span",{className:"ms-usage-cap",id:"ms-usage-projects",children:n.byProject}),s.jsx("ul",{"aria-labelledby":"ms-usage-projects",children:p.map(v=>b(v.slug,v.name,v.tokens,v.costUsd,v.estimated))})]}):null,g.length?s.jsxs("div",{className:"ms-usage-group",children:[s.jsx("span",{className:"ms-usage-cap",id:"ms-usage-kinds",children:n.byKind}),s.jsx("ul",{"aria-labelledby":"ms-usage-kinds",children:g.map(v=>b(v.kind,n.kinds[v.kind],v.tokens,v.costUsd,v.estimated))})]}):null]}):s.jsx("p",{className:"ms-usage-note",children:n.none}),x?s.jsx("p",{className:"ms-usage-billing",children:x}):null,f&&h.costUsd!==null?s.jsx("p",{className:"ms-usage-note",children:a.costUnknown}):null,s.jsx("p",{className:"ms-usage-note",children:n.trackedSince({date:ca(r,e.trackedSince,{dateStyle:"medium"})})})]})}function Jh({paid:e,utcOffsetMinutes:t}){const a=V().web.appSettings.usage,r=a.paid,l=rs(),o=new Date(Date.now()+t*6e4).toISOString().slice(0,10),c=v=>v>0&&v<.001?Ur(l,v):r.estimate({cost:Ur(l,v)}),d=v=>v.map(y=>{const w=r.units[y.unit]({n:y.amount,count:y.unit==="tokens"?ia(l,y.amount):Vs(l,y.amount,{maximumFractionDigits:1})});return y.estimated?r.approx({text:w}):w}).join(" · "),m=Math.max(0,...e.byDay.map(v=>v.costUsd)),u=v=>v===o?a.today:ca(l,Ao(v),{weekday:"short",timeZone:"UTC"}),h=v=>v===o?a.today:ca(l,Ao(v),{weekday:"short",month:"short",day:"numeric",timeZone:"UTC"}),f=i.useRef(null);i.useEffect(()=>{f.current?.querySelectorAll(".ms-usage-bar").forEach((v,y)=>{qn(v,[{transform:"scaleY(0)"},{transform:"scaleY(1)"}],qs.l,Vt.out,y*40)})},[]);const x=(v,y,w,j,S=!1)=>s.jsxs("li",{className:le("ms-usage-row",S&&"ms-usage-wrap"),children:[s.jsx("span",{className:"ms-usage-name",children:y}),w?s.jsx("span",{className:S?"ms-usage-units":"ms-usage-num",children:w}):null,s.jsx("span",{className:"ms-usage-cost",children:c(j)})]},v),p=e.byService.filter(v=>v.calls>0),g=e.byKind.filter(v=>v.calls>0),b=e.byProject.filter(v=>v.calls>0);return s.jsxs(Dt,{className:"ms-usage-card","data-enter":!0,role:"region","aria-labelledby":"ms-paid-title",children:[s.jsxs("div",{className:"ms-usage-head",children:[s.jsx("b",{id:"ms-paid-title",children:r.title}),e.calls>0?s.jsx("span",{className:"ms-usage-total",children:c(e.costUsd)}):null]}),e.calls===0?s.jsx("p",{className:"ms-usage-note",children:r.none}):s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:f,className:"ms-usage-bars","aria-hidden":"true",children:e.byDay.map(v=>s.jsxs("div",{className:"ms-usage-col",title:r.barTitle({day:h(v.day),cost:Ur(l,v.costUsd)}),children:[v.day===o&&v.calls>0?s.jsx("span",{className:"ms-usage-val",children:c(v.costUsd)}):null,s.jsx("span",{"data-day":v.day,className:le("ms-usage-bar",v.costUsd<=0&&"ms-zero",v.day===o&&"ms-today"),style:v.costUsd>0&&m>0?{height:`${v.costUsd/m*100}%`}:void 0})]},v.day))}),s.jsx("div",{className:"ms-usage-days","aria-hidden":"true",children:e.byDay.map(v=>s.jsx("span",{className:le(v.day===o&&"ms-today"),children:u(v.day)},v.day))}),s.jsxs("table",{className:"ms-sr","aria-label":r.chart,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{scope:"col",children:a.day}),s.jsx("th",{scope:"col",children:r.cost})]})}),s.jsx("tbody",{children:e.byDay.map(v=>s.jsxs("tr",{children:[s.jsx("th",{scope:"row",children:h(v.day)}),s.jsx("td",{children:c(v.costUsd)})]},v.day))})]}),s.jsxs("div",{className:"ms-usage-groups",children:[s.jsxs("div",{className:"ms-usage-group",children:[s.jsx("span",{className:"ms-usage-cap",id:"ms-paid-services",children:r.byService}),s.jsx("ul",{"aria-labelledby":"ms-paid-services",children:p.map(v=>x(v.provider,r.services[v.provider],d(v.units),v.costUsd,!0))})]}),s.jsxs("div",{className:"ms-usage-group",children:[s.jsx("span",{className:"ms-usage-cap",id:"ms-paid-kinds",children:r.byKind}),s.jsx("ul",{"aria-labelledby":"ms-paid-kinds",children:g.map(v=>x(v.service,r.kinds[v.service],d(v.units),v.costUsd))})]}),b.length?s.jsxs("div",{className:"ms-usage-group",children:[s.jsx("span",{className:"ms-usage-cap",id:"ms-paid-projects",children:r.byProject}),s.jsx("ul",{"aria-labelledby":"ms-paid-projects",children:b.map(v=>x(v.slug,v.name,null,v.costUsd))})]}):null]}),s.jsx("p",{className:"ms-usage-billing",children:r.note})]})]})}const aN=new Set(["succeeded","failed","cancelled"]);function ul(e,t){const[n,a]=i.useState(null),[r,l]=i.useState(0),o=i.useMemo(()=>Object.values(t.jobs).filter(m=>aN.has(m.state)).length,[t.jobs]),c=t.projectTicks[e]??0;return i.useEffect(()=>{let m=!0;return Promise.resolve().then(()=>q.getIntegrity(e)).then(u=>{m&&a(u)},()=>{}),()=>{m=!1}},[e,o,c,r]),{state:n!==null&&(n.quarantined||n.gitProblem!==null)?n:null,reload:()=>l(m=>m+1)}}function vr({slug:e,state:t,reload:n}){const r=V().web.integrity,[l,o]=i.useState(!1),[c,d]=i.useState(!1),[m,u]=i.useState(null),h=async()=>{d(!0),u(null);try{await q.acceptIntegrity(e,t.token),o(!1),Pe.show(r.accepted,{tone:"ok"})}catch(f){u(f instanceof lt&&f.code==="integrity-changed"?r.changedSince:r.acceptFailed({detail:pe(f)}))}finally{d(!1),n()}};return s.jsxs("section",{className:"ms-integrity","aria-label":t.quarantined?r.title:r.gitTitle,children:[t.quarantined?s.jsxs("div",{className:"ms-integrity-box",role:"alert",children:[s.jsxs("div",{className:"ms-integrity-head",children:[s.jsx(F,{name:"warn",size:16}),s.jsx("h2",{children:r.title})]}),s.jsx("p",{children:r.body}),t.files.length>0?s.jsxs(s.Fragment,{children:[s.jsx("h3",{className:"ms-integrity-label",children:r.filesLabel}),s.jsx("ul",{className:"ms-integrity-files",children:t.files.map(f=>s.jsxs("li",{children:[s.jsx("code",{children:f.path}),s.jsx("span",{className:"ms-integrity-change",children:r.change[f.change]})]},f.path))})]}):null,s.jsx("p",{className:"ms-integrity-hint",children:r.restoreHint}),t.gitProblem===null?s.jsx("div",{className:"ms-integrity-actions",children:s.jsx($,{variant:"outline",onClick:()=>{u(null),o(!0)},children:r.accept})}):null,m&&!l?s.jsx("p",{className:"ms-integrity-error",role:"alert",children:m}):null]}):null,t.gitProblem!==null?s.jsxs("div",{className:"ms-integrity-box ms-integrity-git",role:"alert",children:[s.jsxs("div",{className:"ms-integrity-head",children:[s.jsx(F,{name:"warn",size:16}),s.jsx("h2",{children:r.gitTitle})]}),s.jsx("p",{children:r.gitBody}),s.jsx("p",{className:"ms-integrity-remedy",children:t.gitProblem})]}):null,s.jsx(rt,{open:l,onClose:()=>o(!1),label:r.confirmTitle,width:520,dismissible:!c,children:s.jsxs("div",{className:"ms-integrity-dialog",children:[s.jsx("h2",{children:r.confirmTitle}),s.jsx("p",{className:"ms-integrity-confirm",children:r.confirmText}),s.jsx("p",{children:r.confirmDetail}),s.jsx("ul",{className:"ms-integrity-files",children:t.files.map(f=>s.jsxs("li",{children:[s.jsx("code",{children:f.path}),s.jsx("span",{className:"ms-integrity-change",children:r.change[f.change]})]},f.path))}),m?s.jsx("p",{className:"ms-integrity-error",role:"alert",children:m}):null,s.jsxs("div",{className:"ms-integrity-foot",children:[s.jsx($,{variant:"ghost",disabled:c,onClick:()=>o(!1),children:r.cancel}),s.jsx($,{variant:"danger",loading:c,onClick:()=>{h()},children:r.confirm})]})]})})]})}const eo=e=>e.kind==="asset-description",rN=(e,t)=>eo(e)?t.web.labels.describeFailed({error:e.error??null}):t.web.labels.analysisFailed({error:e.error??null}),_r=e=>!!(e&&(e.state==="queued"||e.state==="running"));let Kd=!1;const Wd=new Set;function lN(){Kd=!0;for(const e of Wd)e()}function iN(e){const t=i.useRef(e);t.current=e,i.useEffect(()=>{const n=()=>{Kd&&(Kd=!1,t.current())};return n(),Wd.add(n),()=>{Wd.delete(n)}},[])}const Lo=new Map,Hd=new Set;function oN(e,t){const n=Lo.get(e)??[];Lo.set(e,[...n,...t.filter(a=>!n.includes(a))]);for(const a of Hd)a()}function cN(e,t){const n=i.useRef(t);n.current=t,i.useEffect(()=>{const a=()=>{const r=Lo.get(e);r&&(Lo.delete(e),r.length>0&&n.current(r))};return a(),Hd.add(a),()=>{Hd.delete(a)}},[e])}const Io=new Map;function Hl(e,t){Io.set(e,t)}function dN(e){return Io.get(e)??null}function zo(e){const t=Io.get(e)??null;return Io.delete(e),t}const Wu=new Map;function uN(e,t){Wu.set(e,t)}function mN(e){return Wu.get(e)??null}function vg(e){Wu.delete(e)}const Oo=new Map;function Hu(e,t){Object.keys(t).length===0?Oo.delete(e):Oo.set(e,{...t})}function Gu(e){const t=Oo.get(e)??{};return Oo.delete(e),t}const Gd=new Map,Xd=new Set;function hN(e,t){Gd.set(e,t);for(const n of Xd)n()}function fN(e,t){const n=i.useRef(t);n.current=t,i.useEffect(()=>{const a=()=>{const r=Gd.get(e);r&&(Gd.delete(e),n.current(r))};return a(),Xd.add(a),()=>{Xd.delete(a)}},[e])}function Xu(e,t){const[n,a]=i.useState(null),[r,l]=i.useState(!1),[o,c]=i.useState(0),d=t.projectTicks[e]??0;i.useEffect(()=>{let u=!0;const h=t.analysisSeq??0;return Promise.resolve().then(()=>q.listVideoAnalyses(e)).then(f=>{u&&(a({views:f,seq:h}),l(!1))}).catch(()=>{u&&l(!0)}),()=>{u=!1}},[e,d,t.snapshots,o]);const m=t.analyses?.[e];return i.useMemo(()=>{const u={};for(const h of n?.views??[])u[h.file]=h;for(const[h,f]of Object.entries(m??{}))(!n||f.seq>n.seq)&&(u[h]=f.view);return{byFile:u,pending:Object.values(u).filter(h=>h.pending!==null),reload:()=>c(h=>h+1),loaded:n!==null||r}},[n,m,r])}function pN(e,t,n,a=!0){const[r,l]=i.useState(null);i.useEffect(()=>{if(!a)return;let c=!0;const d=n.analysisSeq??0;return Promise.resolve().then(()=>q.analysisWait(e,t)).then(m=>{c&&l({files:m.files,seq:d})}).catch(()=>{}),()=>{c=!1}},[e,t,n.snapshots,a]);const o=n.analysisWaits?.[`${e}/${t}`];return a?o&&o.seq>(r?.seq??0)?o.files:r?.files??o?.files??[]:[]}const Zu={keepalive:!0};function Oa(e,t,n){return`${e}\0${t}\0${n}`}const so=new Set,qr=new Map,Zd=new Set;let Yh=!1;function Qh(){xc()}function xN(e){for(const t of e)qr.set(t,(qr.get(t)??0)+1)}function Zc(e,t){for(const n of e){const a=(qr.get(n)??1)-1;a>0?qr.set(n,a):qr.delete(n)}if(e.length)for(const n of[...Zd])n({type:t,keys:e})}function Ju(e){return qr.has(e)}function gN(e){return Zd.add(e),()=>{Zd.delete(e)}}function Yu(e){const[t,n]=i.useReducer(r=>r+1,0),a=i.useRef(e);return a.current=e,i.useEffect(()=>gN(r=>{r.type==="committed"&&a.current?.(r.keys),n()}),[]),t}async function xc(){await Promise.all([...so].map(e=>e()))}function Qu(e){let t=!1,n=0;const a=e.keys??[],r=async()=>{if(!t){t=!0,clearTimeout(o),so.delete(r),Pe.dismiss(n);try{await e.commit(),Zc(a,"committed")}catch(c){Zc(a,"restored"),e.restore(),e.onError?.(c)}}},l=e.ms??tg,o=setTimeout(()=>{r()},l+400);return so.add(r),xN(a),!Yh&&typeof window<"u"&&(Yh=!0,window.addEventListener("pagehide",Qh),window.addEventListener("beforeunload",Qh)),n=Pe.show(e.text,{ms:l,action:{label:e.undoLabel,run:()=>{t||(t=!0,clearTimeout(o),so.delete(r),Pe.dismiss(n),Zc(a,"restored"),e.restore())}}}),r}const Jd=e=>e.slice(e.lastIndexOf("/")+1);function bg({slug:e,view:t,question:n,onDone:a,headingId:r}){const o=V().videoAnalysis,c=rs(),[d,m]=i.useState(null),[u,h]=i.useState(null),f=g=>Vs(c,g),x=Vs(c,Math.round((t.header?.durationSec??0)/60)||Math.round(n.frames*10/60)),p=async g=>{m(g),h(null);try{await q.confirmLongVideo(e,t.file,g),a?.()}catch(b){h(o.actionFailed({detail:pe(b)}))}finally{m(null)}};return s.jsxs("div",{className:"ms-tchoices",children:[s.jsx("h2",{id:r,className:"ms-tchoices-title",children:o.longTitle({file:Jd(t.file)})}),s.jsx("p",{className:"ms-tchoices-why",children:o.longText({minutes:x})}),u?s.jsx("p",{className:"ms-tchoices-error",role:"alert",children:u}):null,s.jsxs("div",{className:"ms-tchoices-list",role:"group","aria-label":o.longTitle({file:Jd(t.file)}),children:[s.jsxs("button",{type:"button",className:"ms-tchoice",disabled:d!==null,"aria-busy":d==="full"||void 0,onClick:()=>{p("full")},children:[s.jsx("span",{className:"ms-tchoice-icon","aria-hidden":"true",children:s.jsx(F,{name:"video",size:14})}),s.jsxs("span",{className:"ms-tchoice-text",children:[s.jsx("b",{children:o.longFull}),s.jsx("span",{children:o.longEstimate({frames:f(n.frames),tokens:f(n.tokens)})})]})]}),s.jsxs("button",{type:"button",className:"ms-tchoice",disabled:d!==null,"aria-busy":d==="reduced"||void 0,onClick:()=>{p("reduced")},children:[s.jsx("span",{className:"ms-tchoice-icon","aria-hidden":"true",children:s.jsx(F,{name:"grid",size:14})}),s.jsxs("span",{className:"ms-tchoice-text",children:[s.jsx("b",{children:o.longReduced}),s.jsxs("span",{children:[o.longEstimate({frames:f(n.reducedFrames),tokens:f(n.reducedTokens)})," · ",o.longReducedNote]})]})]})]})]})}function vN({slug:e,view:t,question:n,open:a,onClose:r}){const l=V(),o=i.useId();return s.jsx(rt,{open:a,onClose:r,label:l.videoAnalysis.longTitle({file:Jd(t.file)}),width:480,children:s.jsxs("div",{className:"ms-tdialog",children:[s.jsx(bg,{slug:e,view:t,question:n,onDone:r,headingId:o}),s.jsx("div",{className:"ms-tdialog-foot",children:s.jsx($,{size:"sm",variant:"ghost",onClick:r,children:l.common.close})})]})})}const bN=1e3,jN=e=>e.slice(e.lastIndexOf("/")+1),em=(e,t)=>e.transcription.dialogTitle({file:jN(t)}),ef={brew:"brew install whisper-cpp",pip:"pip install openai-whisper"},yN=1600;function wN(e){const t=window.getSelection();if(!e||!t)return;const n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}function sf({command:e,onCopied:t}){const n=V().transcription,a=i.useRef(null),[r,l]=i.useState(!1),o=i.useRef(null);i.useEffect(()=>()=>{o.current&&clearTimeout(o.current)},[]);const c=async()=>{o.current&&clearTimeout(o.current);try{if(!navigator.clipboard?.writeText)throw new Error("clipboard unavailable");await navigator.clipboard.writeText(e),l(!0),t("copied"),o.current=setTimeout(()=>{l(!1),t("idle")},yN)}catch{wN(a.current),t("manual")}};return s.jsxs("div",{className:"ms-tcmd",children:[s.jsx("code",{ref:a,children:e}),s.jsxs($,{size:"sm",variant:"ghost","aria-label":n.copyCommand({command:e}),onClick:()=>{c()},children:[s.jsx(F,{name:r?"check":"copy",size:13,strokeWidth:r?2:1.4}),r?n.copied:n.copy]})]})}function jg({slug:e,view:t,question:n,onDone:a,headingId:r,footer:l,onSettings:o,submit:c,recheck:d,title:m,why:u}){const h=V(),f=h.transcription,x=rs(),[p,g]=i.useState(!1),[b,v]=i.useState(null),[y,w]=i.useState(!1),[j,S]=i.useState(null),[k,E]=i.useState(null),[N,C]=i.useState(null),[R,P]=i.useState(!1),[z,O]=i.useState(null),[T,W]=i.useState("idle"),Z=N&&N.for===n?N.offer:n;i.useEffect(()=>{if(!y)return;let oe=!0;const Ne=()=>{Promise.resolve().then(()=>q.getTranscription()).then(Re=>{oe&&S(Re.download)},()=>{})};Ne();const Q=window.setInterval(Ne,bN);return()=>{oe=!1,window.clearInterval(Q)}},[y]);const A=t.pending?.kind==="transcription"?t.pending.error:void 0;i.useEffect(()=>{y&&A&&w(!1)},[y,A]);const L=Ku(Z.whisper.sizeBytes,oe=>Vs(x,oe)),_=oe=>dl(h,x,oe)??"",X=async oe=>{v(oe),E(null);const Ne=oe==="whisper"&&!Z.whisper.installed&&!Z.whisper.downloadsOwnModel;try{const Q={choice:oe,remember:p,...Ne?{sizeBytes:Z.whisper.sizeBytes}:{}},Re=c?await c(Q):await q.transcriptionChoice(e,{file:t.file,...Q});Ne&&Re.pending?.kind==="transcription"&&!Re.pending.error?w(!0):a?.()}catch(Q){E(f.choiceFailed({detail:pe(Q)}))}finally{v(null)}},ae=async()=>{P(!0),O(null);try{const oe=d?await d():await q.recheckTranscription(e,t.file).then(Q=>Q.pending?.kind==="transcription"?Q.pending:null);if(!oe){a?.();return}C({for:n,offer:oe});const Ne=oe.whisper;Ne.installed||Ne.downloadsOwnModel||Ne.canInstall||O(f.stillNone)}catch(oe){O(f.recheckFailed({detail:pe(oe)}))}finally{P(!1)}};i.useEffect(()=>{y&&t.pending?.kind!=="transcription"&&a?.()},[y,t.pending,a]);const K=Z.whisper.installed||Z.whisper.downloadsOwnModel,I=K||Z.whisper.canInstall,H=f.models[Z.whisper.model],de=[f.freeLocal,Z.whisper.downloadsOwnModel?f.ownModel:Z.whisper.installed?f.modelReady({model:H}):f.modelOnce({model:H,size:L})].join(" · "),J=A??Z.error,se=k??(J?f.installFailed({detail:J}):null),U=j&&j.total>0?Math.round(j.bytes/j.total*100):0,te=b!==null||y,G=s.jsxs("span",{className:"ms-tchoice-text",children:[s.jsxs("span",{className:"ms-tchoice-head",children:[s.jsx("b",{children:f.whisperTitle}),s.jsx(Qs,{tone:"accent",children:f.recommended})]}),s.jsx("span",{children:I?de:f.freeLocal})]}),re=(oe,Ne)=>s.jsxs("button",{type:"button",className:"ms-tchoice ms-tchoice-paid",disabled:te,"aria-busy":b===oe||void 0,onClick:()=>{X(oe)},children:[s.jsx("span",{className:"ms-tchoice-icon","aria-hidden":"true",children:s.jsx(F,{name:"globe",size:14})}),s.jsxs("span",{className:"ms-tchoice-text",children:[s.jsx("b",{children:Ne}),s.jsx("span",{children:f.leavesMac})]})]});return s.jsxs("div",{className:"ms-tchoices",children:[s.jsx("h2",{id:r,className:"ms-tchoices-title",children:m??em(h,t.file)}),s.jsx("p",{className:"ms-tchoices-why",children:u??f.why}),se?s.jsx("p",{className:"ms-tchoices-error",role:"alert",children:se}):null,y?s.jsxs("div",{className:"ms-tchoices-progress",role:"status",children:[s.jsx(kr,{value:U,label:f.downloading({percent:U})}),s.jsx("span",{children:f.downloading({percent:U})})]}):s.jsxs("div",{className:"ms-tchoices-list",role:"group","aria-label":f.choicesLabel,children:[I?s.jsxs("button",{type:"button",className:"ms-tchoice ms-tchoice-primary",disabled:te,"aria-busy":b==="whisper"||void 0,onClick:()=>{X("whisper")},children:[s.jsx("span",{className:"ms-tchoice-icon","aria-hidden":"true",children:s.jsx(F,{name:K?"check":"download",size:14})}),G]}):s.jsxs("div",{className:"ms-tchoice ms-tchoice-primary ms-tchoice-steps",children:[s.jsx("span",{className:"ms-tchoice-icon","aria-hidden":"true",children:s.jsx(F,{name:"download",size:14})}),s.jsxs("div",{className:"ms-tchoice-body",children:[G,s.jsx("p",{className:"ms-tsteps-intro",children:f.getWhisper}),s.jsxs("ol",{className:"ms-tsteps",children:[s.jsxs("li",{children:[s.jsx("span",{children:f.stepBrew}),s.jsx(sf,{command:ef.brew,onCopied:W})]}),s.jsxs("li",{children:[s.jsx("span",{children:f.stepPip}),s.jsx(sf,{command:ef.pip,onCopied:W})]})]}),s.jsx("p",{className:T==="manual"?"ms-tsteps-note":"ms-tsteps-note ms-sr",role:"status",children:T==="manual"?f.copyFallback({keys:Pt()?"⌘C":"Ctrl+C"}):T==="copied"?f.copiedStatus:""}),s.jsxs("div",{className:"ms-tsteps-actions",children:[s.jsxs($,{size:"sm",variant:"outline",disabled:R,"aria-busy":R||void 0,onClick:()=>{ae()},children:[s.jsx(F,{name:"refresh",size:13}),R?f.rechecking:f.recheck]}),s.jsx("a",{className:"ms-tsteps-link",href:es.settings("transcription"),onClick:()=>o?.(),children:f.pickInstalled})]}),z?s.jsx("p",{className:"ms-tsteps-note",role:"status",children:z}):null]})]}),Z.openai||Z.elevenlabs?s.jsx("h3",{className:"ms-tchoices-paidhead",children:f.paidHeading}):null,Z.openai?re("openai",f.withOpenai({cost:_(Z.openai.costUsd)})):null,Z.elevenlabs?re("elevenlabs",f.withElevenlabs({cost:_(Z.elevenlabs.costUsd)})):null]}),s.jsxs("div",{className:"ms-tchoices-foot",children:[y?null:s.jsxs("label",{className:"ms-tchoices-remember",children:[s.jsx(Rn,{on:p,onChange:g,label:f.remember}),s.jsx("span",{"aria-hidden":"true",children:f.remember})]}),s.jsxs("span",{className:"ms-tchoices-foot-actions",children:[y?null:s.jsx("button",{type:"button",className:"ms-tchoices-skip",disabled:te,"aria-busy":b==="none"||void 0,onClick:()=>{X("none")},children:f.continueWithout}),l]})]})]})}function yg({slug:e,view:t,question:n,open:a,onClose:r,onSettings:l,...o}){const c=V(),d=i.useId();return s.jsx(rt,{open:a,onClose:r,label:o.title??em(c,t.file),width:480,children:s.jsx("div",{className:"ms-tdialog",children:s.jsx(jg,{slug:e,view:t,question:n,onDone:r,headingId:d,onSettings:l??r,...o,footer:s.jsx($,{size:"sm",variant:"ghost",onClick:r,children:c.common.close})})})})}function wg({slug:e,view:t,open:n,onClose:a,onSettings:r}){const[l,o]=i.useState(null);if(i.useEffect(()=>{t&&o(d=>t.pending?{view:t,question:t.pending}:d&&d.view.file===t.file?{...d,view:t}:d)},[t]),!l)return null;const c=`${l.question.kind}:${l.view.file}`;return l.question.kind==="long"?s.jsx(vN,{slug:e,view:l.view,question:l.question,open:n,onClose:a},c):s.jsx(yg,{slug:e,view:l.view,question:l.question,open:n,onClose:a,...r?{onSettings:r}:{}},c)}function kN({question:e,open:t,onClose:n,onSettings:a}){const r=V(),{slug:l,creative:o}=e,c={file:`creatives/${o}`,state:"waiting",jobId:e.jobId,error:null,pending:e.pending,header:null,body:null},d=()=>q.subtitlesRecheck(l,o).then(m=>m.pending,m=>{if(m instanceof lt&&m.code==="transcription-not-asked")return null;throw m});return s.jsx(yg,{slug:l,view:c,question:e.pending,open:t,onClose:n,...a?{onSettings:a}:{},title:r.transcription.subtitlesTitle({title:e.title}),why:r.transcription.subtitlesWhy,submit:m=>q.subtitlesChoice(l,o,m),recheck:d})}function kg(e,t){const n=e.web.conversation.groupTurn,a=r=>`${r.variant.toUpperCase()} (${r.status==="complete"?`v${r.version}`:r.status==="incomplete"?n.incomplete({n:r.version??0}):r.status==="unchanged"?r.version!==null?n.unchangedAt({n:r.version}):n.unchanged:r.status==="stopped"?n.stopped:n.failed})`;return n.workedOn({list:t.map(a).join(", ")})}const pt=(e,t)=>Zi(e,t)??null,sm=(e,t)=>Su({id:kt(e.id),name:e.name},t);function xn(e,t,n,a){return e?nx(t,sm(e,n),a):t}function NN(e,t,n,a){const r={};for(const l of e){const o=t?.[l]??"",c=o===(n?.[l]??"")?a?.[l]??o:o;c.trim()!==""&&(r[l]=c)}return Object.keys(r).length>0?r:void 0}function Ht(e){const t=e.locales;return t?{primary:t.primary,extra:t.extra,all:[t.primary,...t.extra]}:null}function Js(e,t){try{const n=new Intl.DisplayNames([t],{type:"language"}).of(e);if(n&&n!==e)return n.charAt(0).toLocaleUpperCase(t)+n.slice(1)}catch{}return ei.find(n=>n.tag===e)?.name??e}const tf=pj;function SN(e){if(!e)return{kind:"none"};const t=e.stale.length,n=e.problems?.length??0;return t&&n?{kind:"both",stale:t,problems:n}:t?{kind:"stale",count:t}:n?{kind:"problems",count:n}:{kind:"ok"}}function CN(e,t){const n=t.web.languages;switch(e.kind){case"none":return n.statusNone;case"ok":return n.statusOk;case"stale":return n.statusStale({count:e.count});case"problems":return n.statusProblems({count:e.count});case"both":return`${n.statusStale({count:e.stale})} · ${n.statusProblems({count:e.problems})}`}}const EN={auto:["openai","elevenlabs"],openai:["openai"],elevenlabs:["elevenlabs"]};function TN(e,t,n){const a=ac(e).voice;if(a==="none")return"off";const r=EN[a],l=t?r.filter(o=>t.has(o)):r;return l.length===0?"noKey":n&&l.every(o=>Cu(n[o],"tts")!==null)?"missingPermission":null}function RN(e){return e.find(t=>t.voiceFallback!==void 0)?.voiceFallback??null}function to(e,t){return t.web.languages.voiceReason[e]}const tm=new Set(["textOverflow","textOverflowMeasured","sourceTextOverflow"]),MN=new Set(["voiceTooLong","voiceFailed","voiceDurationUnknown","voiceFileInvalid"]);function nm(e,t){const n=new Set;for(const a of["en","it"]){const r=al(a).variants;for(let l=70;l<=100;l++)n.add(r.textOverflow({clip:t,fit:l})),n.add(r.textOverflowMeasured({clip:t,fit:l}))}return e.filter(a=>n.has(a))}function $N(e,t){return e.issues?e.issues.filter(n=>n.clipId===t.clipId&&n.code!=="stale"):nm(e.problems??[],Gr(t)).map(n=>({code:"textOverflow",clipId:t.clipId,message:n}))}const FN=(e,t)=>$N(e,t).filter(n=>tm.has(n.code)).map(n=>n.message);function PN(e,t){const n=new Set(t.flatMap(a=>nm(e.problems??[],Gr(a))));if(e.issues){const a=new Set(t.map(c=>c.clipId)),r=new Set(e.issues.map(c=>c.message)),l=e.issues.filter(c=>c.code!=="stale"&&!(c.clipId!==void 0&&a.has(c.clipId)&&(tm.has(c.code)||c.code==="notTranslated"))).map(c=>c.message),o=(e.problems??[]).filter(c=>!r.has(c)&&!n.has(c));return[...new Set([...l,...o])]}return(e.problems??[]).filter(a=>!n.has(a))}const Gr=e=>(e.name??e.clipId).slice(0,100),nf=["stale","overflow","notTranslated","voice","asset"],AN=e=>e==="stale"?"stale":tm.has(e)?"overflow":e==="notTranslated"?"notTranslated":MN.has(e)?"voice":e==="assetChanged"?"asset":null;function LN(e){const t=[];for(const n of e.clips){const a=new Map,r=(o,c)=>a.set(o,[...a.get(o)??[],c]);(e.stale.includes(n.clipId)||e.stale.some(o=>o.startsWith(`${n.clipId}.`)))&&r("stale","");for(const o of e.issues??[]){const c=o.clipId===n.clipId?AN(o.code):null;c&&c!=="stale"&&r(c,o.message)}if(!e.issues)for(const o of nm(e.problems,Gr(n)))r("overflow",o);const l=nf.find(o=>a.has(o));l&&t.push({clipId:n.clipId,label:Gr(n),kind:l,messages:[...new Set(nf.flatMap(o=>a.get(o)??[]).filter(Boolean))]})}return t}function IN(e,t,n){const a=new Set((t.compositions??[]).map(d=>d.format)),r=e.filter(d=>fj(d)&&(a.size===0||a.has(d))),l=t.localizations??[],o=[],c=[];for(const d of n){const m=r.map(u=>l.find(h=>h.locale===d&&h.instanceId===u));r.length===0||m.some(u=>!u)?o.push(d):m.some(u=>u.stale.length>0||(u.problems?.length??0)>0)&&c.push(d)}return{untranslated:o,review:c}}const af={high:0,medium:1,low:2},zN={high:"warn",medium:"eye",low:"shield"},ON={high:"ms-danger",medium:"ms-warn",low:void 0},rf=new Set(["low","medium","high"]),xl=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function DN(e){return xl(e)&&rf.has(e.risk)&&Array.isArray(e.summary)&&Array.isArray(e.indicators)&&e.summary.every(t=>xl(t)&&typeof t.key=="string"&&(t.params===void 0||xl(t.params)))&&e.indicators.every(t=>xl(t)&&typeof t.id=="string"&&rf.has(t.risk)&&(t.params===void 0||xl(t.params)))}function am(e,t){if(!DN(e))return null;const n=xj({...e,summary:e.summary.map(o=>({...o,params:o.params??{}}))},t),a=t.web.approvalUi,r=n.summary.map((o,c)=>o===e.summary[c].key||o.startsWith("explain.")?a.runsCommand:o),l=n.indicators.map((o,c)=>({...o,label:o.label.startsWith("explain.")?a.otherRisk:o.label,i:c})).sort((o,c)=>af[o.risk]-af[c.risk]||o.i-c.i);return{...n,summary:r,title:r.join(" · "),indicators:l}}function Ng({explanation:e}){const t=V(),n=am(e,t)?.indicators??[];return s.jsx(s.Fragment,{children:n.map(a=>{const r=t.explain.risk[a.risk];return s.jsxs(sn,{icon:zN[a.risk],className:le("ms-risk",ON[a.risk]),title:r,children:[s.jsxs("span",{className:"ms-sr",children:[t.web.approvalUi.riskPrefix({risk:r})," "]}),s.jsx("span",{className:"ms-risk-label",children:a.label})]},`${a.id}:${a.i}`)})})}const BN=e=>e.replace(/\\([\\[\]*?{}()!+@])/g,"$1");function Sg(e,t){const n=t.approvals;let a=/^Bash\((.+):\*\)$/.exec(e);if(a)return n.commandsLabel({command:a[1]});if(a=/^WebFetch\(domain:(.+)\)$/.exec(e),a)return n.pagesOf({host:a[1]});if(a=/^(Edit|Read)\(\/(.+)\/\*\*\)$/.exec(e),a){const r=BN(a[2]);return a[1]==="Edit"?n.editsIn({dir:r}):n.readsIn({dir:r})}return e.startsWith("provider:")?n.providerNoConfirm({provider:e.slice(9)}):n.toolLabel({tool:e})}const Ri={openai:"OpenAI",elevenlabs:"ElevenLabs",pexels:"Pexels",unsplash:"Unsplash"},lf=e=>new Date(e).getTime();function UN({approval:e,context:t,leaving:n=!1,onGone:a}){const r=V(),l=r.web.approvalUi,o=r.web.paidBatch,c=rs(),d=i.useRef(null),[m,u]=i.useState(!1),[h,f]=i.useState(!1),[x,p]=i.useState(null),g=i.useRef(n);g.current=n;const b=i.useRef(a);b.current=a;const v=e.paidBatch;i.useLayoutEffect(()=>{const O=d.current;Gs(O,{y:10}).then(async()=>{for(let T=0;T<2&&!g.current&&O?.isConnected;T++)await cc(O)})},[]);const y=i.useRef(!1);i.useLayoutEffect(()=>{const O=d.current;if(!n){y.current&&(f(!1),Gs(O,{y:0,ms:200})),y.current=!1;return}y.current=!0;let T=!0;return il(O).then(W=>{W&&T&&g.current&&b.current?.(e.id)}),()=>{T=!1}},[n,e.id]);const w=e.alwaysRule?Sg(e.alwaysRule,r):null,j=async O=>{u(!0),p(null);try{await q.decideApproval(e.id,O),O==="always"&&w&&Pe.show(l.alwaysSaved({label:w}),{tone:"ok"}),f(!0)}catch(T){p(T instanceof lt&&T.status===404?l.alreadyHandled:pe(T))}finally{u(!1)}};if(!v)return null;const S=lf(e.createdAt),k=(lf(e.expiresAt)-S)/1e3,E=m||h||n,N=v.calls.reduce((O,T)=>O+T.chars,0),C=Ri[v.provider],R=v.items,P=v.total?.providers??[],z=P.length>1?o.introMixed({count:v.total?.calls??v.calls.length,list:P.map(O=>`${Ri[O.provider]} ${O.calls}`).join(", ")}):o.intro({provider:P.length===1?Ri[P[0].provider]:C,count:v.total?.calls??v.calls.length});return s.jsxs("div",{ref:d,role:"group","aria-label":e.title,className:"ms-approval ms-batch","data-approval":e.id,children:[s.jsxs("div",{className:"ms-approval-head",children:[s.jsx("span",{className:"ms-approval-dot","aria-hidden":"true"}),s.jsx("b",{className:"ms-approval-title",children:e.title}),Number.isFinite(S)&&Number.isFinite(k)&&k>0&&s.jsx(mc,{createdAt:S,ttlSec:k})]}),t&&s.jsx("span",{className:"ms-approval-context",children:t}),s.jsx("span",{className:"ms-approval-text",children:R?z:o.intro({provider:C,count:v.calls.length})}),s.jsxs("div",{className:"ms-approval-chips",children:[s.jsx(tn,{children:o.provider({provider:R&&P.length>0?P.map(O=>Ri[O.provider]).join(", "):C})}),!R||N>0?s.jsx(tn,{children:o.total({chars:Vs(c,N)})}):null,s.jsx(tn,{children:R?o.estimatedCalls:v.estimate?o.estimate({estimate:v.estimate}):o.noEstimate})]}),R?s.jsx("ul",{className:"ms-batch-calls ms-batch-variants","aria-label":o.variantItems,children:R.map((O,T)=>s.jsxs("li",{children:[s.jsx("span",{className:"ms-batch-label",children:v.calls[T]?.label??`${O.variant.toUpperCase()} · ${O.capability}`}),s.jsx("span",{className:"ms-batch-chars",children:O.chars?o.chars({chars:Vs(c,O.chars)}):O.seconds?o.itemSeconds({seconds:Vs(c,O.seconds)}):""})]},`${T}-${O.variant}-${O.capability}`))}):s.jsx("ul",{className:"ms-batch-calls","aria-label":o.calls,children:v.calls.map((O,T)=>s.jsxs("li",{children:[s.jsx("span",{className:"ms-batch-label",children:O.label}),s.jsx("span",{className:"ms-batch-chars",children:o.chars({chars:Vs(c,O.chars)})})]},`${T}-${O.label}`))}),s.jsxs("div",{className:"ms-approval-actions",children:[s.jsx($,{size:"sm",variant:"ink",className:"ms-grow",disabled:E,onClick:()=>{j("once")},children:o.approve}),e.alwaysRule&&s.jsx($,{size:"sm",variant:"outline",disabled:E,title:e.alwaysRule,onClick:()=>{j("always")},children:l.alwaysHere}),s.jsx($,{size:"sm",variant:"ghost",disabled:E,onClick:()=>{j("deny")},children:o.decline})]}),w?s.jsx("span",{className:"ms-approval-scope",children:l.alwaysScope({label:w})}):null,x&&s.jsx("p",{role:"alert",className:"ms-approval-error",children:x})]})}const of=e=>new Date(e).getTime();function _N(e,t){const n=Array.from(e);return n.length<=t?{shown:e}:{shown:`${n.slice(0,t-1).join("").trimEnd()}…`,full:e}}function Lr({text:e,max:t,className:n}){const a=_N(e,t);return s.jsx("span",{className:n,title:a.full,children:a.shown})}function qN({approval:e,context:t,leaving:n=!1,onGone:a}){const r=V(),l=r.web.questionUi,o=r.web.approvalUi,c=i.useRef(null),d=e.questions??[],[m,u]=i.useState(()=>d.map(()=>({selected:[],other:null}))),[h,f]=i.useState(!1),[x,p]=i.useState(!1),[g,b]=i.useState(null),v=i.useRef(n);v.current=n;const y=i.useRef(a);y.current=a,i.useLayoutEffect(()=>{const z=c.current;Gs(z,{y:10}).then(async()=>{for(let O=0;O<2&&!v.current&&z?.isConnected;O++)await cc(z)})},[]);const w=i.useRef(!1);i.useLayoutEffect(()=>{const z=c.current;if(!n){w.current&&(p(!1),Gs(z,{y:0,ms:200})),w.current=!1;return}w.current=!0;let O=!0;return il(z).then(T=>{T&&O&&v.current&&y.current?.(e.id)}),()=>{O=!1}},[n,e.id]);const j=(z,O)=>u(T=>T.map((W,Z)=>Z===z?O(W):W)),S=z=>z.selected.length>0||z.other!==null&&z.other.trim()!=="",k=d.length>0&&m.every(S),E=h||x||n,N=async z=>{f(!0),b(null);try{await z(),p(!0)}catch(O){b(O instanceof lt&&O.status===404?o.alreadyHandled:pe(O))}finally{f(!1)}},C=()=>{const z=m.map(O=>{const T=O.other?.trim()??"";return{selected:[...O.selected].sort((W,Z)=>W-Z),...T?{other:T}:{}}});N(()=>q.answerQuestion(e.id,z))},R=of(e.createdAt),P=(of(e.expiresAt)-R)/1e3;return s.jsxs("div",{ref:c,role:"group","aria-label":e.title,className:"ms-approval ms-question","data-approval":e.id,children:[s.jsxs("div",{className:"ms-approval-head",children:[s.jsx("span",{className:"ms-approval-dot","aria-hidden":"true"}),s.jsx("b",{className:"ms-approval-title",children:l.title}),Number.isFinite(R)&&Number.isFinite(P)&&P>0&&s.jsx(mc,{createdAt:R,ttlSec:P})]}),t&&s.jsx("span",{className:"ms-approval-context",children:t}),d.map((z,O)=>s.jsx(VN,{question:z,choice:m[O],disabled:E,onPick:T=>j(O,W=>z.multiSelect?{...W,selected:W.selected.includes(T)?W.selected.filter(Z=>Z!==T):[...W.selected,T]}:{selected:[T],other:null}),onOther:T=>j(O,W=>z.multiSelect?{...W,other:T?W.other??"":null}:{selected:[],other:T?W.other??"":null}),onOtherText:T=>j(O,W=>({...W,other:T}))},O)),s.jsxs("div",{className:"ms-approval-actions",children:[s.jsx($,{size:"sm",variant:"ink",className:"ms-grow",disabled:E||!k,title:k?void 0:l.chooseFirst,onClick:C,children:l.send}),s.jsx($,{size:"sm",variant:"ghost",disabled:E,onClick:()=>{N(()=>q.decideApproval(e.id,"deny"))},children:l.skip})]}),g&&s.jsx("p",{role:"alert",className:"ms-approval-error",children:g})]})}function VN({question:e,choice:t,disabled:n,onPick:a,onOther:r,onOtherText:l}){const c=V().web.questionUi,d=i.useId(),m=e.multiSelect,u=m?"checkbox":"radio",h=t.other!==null;return s.jsxs("fieldset",{className:"ms-question-block",role:"group","aria-label":e.question,children:[e.header&&s.jsx(Lr,{className:"ms-question-header",text:e.header,max:Pr.header}),s.jsx(Lr,{className:"ms-question-text",text:e.question,max:Pr.question}),m&&s.jsx("span",{className:"ms-approval-note",children:c.multiHint}),s.jsxs("div",{className:"ms-question-options",children:[e.options.map((f,x)=>s.jsxs("label",{className:"ms-question-option",children:[s.jsx("input",{type:u,name:d,checked:t.selected.includes(x),disabled:n,onChange:()=>a(x)}),s.jsxs("span",{className:"ms-question-option-text",children:[s.jsx(Lr,{className:"ms-question-label",text:f.label,max:Pr.label}),f.description&&s.jsx(Lr,{className:"ms-question-desc",text:f.description,max:Pr.description})]})]},x)),s.jsxs("label",{className:"ms-question-option",children:[s.jsx("input",{type:u,name:d,checked:h,disabled:n,onChange:()=>r(m?!h:!0)}),s.jsx("span",{className:"ms-question-option-text",children:s.jsx("span",{className:"ms-question-label",children:c.other})})]}),h&&s.jsx(ms,{autoFocus:!0,value:t.other??"",maxLength:gj.other,disabled:n,placeholder:c.otherPlaceholder,"aria-label":c.otherPlaceholder,onChange:f=>l(f.target.value)})]})]})}const cf={tool:500,any:2e3},KN=10;function WN(e){return e.kind==="provider"?"provider":e.toolName==="Bash"?"command":["Write","Edit","MultiEdit","NotebookEdit"].includes(e.toolName)?"edit":e.toolName==="Read"?"read":e.toolName==="WebFetch"?"web":"tool"}const HN=e=>e.replace(/\n$/,"").split(`
|
|
3
|
+
`).length,df=e=>new Date(e).getTime();function ri(e){return e.approval.kind==="paid-batch"&&e.approval.paidBatch?s.jsx(UN,{...e}):e.approval.kind==="question"?s.jsx(qN,{...e}):s.jsx(GN,{...e})}function GN({approval:e,context:t,leaving:n=!1,onGone:a}){const r=V(),l=r.web.approvalUi,o=rs(),c=i.useRef(null),d=i.useRef(null),m=i.useId(),[u,h]=i.useState(!1),[f,x]=i.useState(!1),[p,g]=i.useState(!1),[b,v]=i.useState(null),[y,w]=i.useState(!1),j=i.useRef(n);j.current=n;const S=i.useRef(a);S.current=a,i.useLayoutEffect(()=>{const _=c.current;Gs(_,{y:10}).then(async()=>{for(let X=0;X<2&&!j.current&&_?.isConnected;X++)await cc(_)})},[]);const k=i.useRef(!1);i.useLayoutEffect(()=>{const _=c.current;if(!n){k.current&&(g(!1),Gs(_,{y:0,ms:200})),k.current=!1;return}k.current=!0;let X=!0;return il(_).then(ae=>{ae&&X&&j.current&&S.current?.(e.id)}),()=>{X=!1}},[n,e.id]),i.useEffect(()=>{const _=d.current;w(!!(_&&_.scrollHeight>_.clientHeight+1))},[u,e.detail]);const E=e.alwaysRule?Sg(e.alwaysRule,r):null,N=i.useId(),C=async _=>{x(!0),v(null);try{await q.decideApproval(e.id,_),_==="always"&&E&&Pe.show(l.alwaysSaved({label:E}),{tone:"ok"}),g(!0)}catch(X){v(X instanceof lt&&X.status===404?l.alreadyHandled:pe(X))}finally{x(!1)}},R=WN(e),P=R==="provider",z=HN(e.detail),O=df(e.createdAt),T=(df(e.expiresAt)-O)/1e3,W=R==="tool"?cf.tool:cf.any,Z=f||p||n,A=am(e.explanation,r),L=A?.title||e.title;return s.jsxs("div",{ref:c,role:"group","aria-label":L,className:"ms-approval","data-approval":e.id,children:[s.jsxs("div",{className:"ms-approval-head",children:[s.jsx("span",{className:"ms-approval-dot","aria-hidden":"true"}),s.jsx("b",{className:"ms-approval-title",children:L}),Number.isFinite(O)&&Number.isFinite(T)&&T>0&&s.jsx(mc,{createdAt:O,ttlSec:T})]}),t&&s.jsx("span",{className:"ms-approval-context",children:t}),P?s.jsx("span",{className:"ms-approval-text",children:e.detail}):s.jsx("span",{className:"ms-approval-text",children:l.describe[R]}),s.jsxs("div",{className:"ms-approval-chips",children:[A&&e.explanation?s.jsx(Ng,{explanation:e.explanation}):s.jsx(tn,{children:l.kinds[R]}),!P&&e.detail&&s.jsxs("button",{type:"button",className:"ms-chip ms-approval-toggle","aria-expanded":u,"aria-controls":m,onClick:()=>h(_=>!_),children:[s.jsx(F,{name:"code",size:11}),R==="command"?u?l.hideCommand:l.showCommand:u?l.hideDetails:l.showDetails,s.jsx("span",{className:"ms-approval-lines",children:l.lines({count:z})})]})]}),A&&e.agentReason?s.jsx("span",{className:"ms-approval-reason",children:l.agentSays({reason:e.agentReason})}):null,!P&&u&&s.jsxs("div",{id:m,className:"ms-approval-cmd",children:[s.jsx("pre",{ref:d,className:"ms-approval-pre",tabIndex:0,"aria-label":R==="command"?l.fullCommand:l.fullDetails,children:e.detail}),(y||z>KN)&&s.jsx("span",{className:"ms-approval-note",children:l.scrollMore}),e.detail.length>=W&&s.jsx("span",{className:"ms-approval-note ms-warn",children:l.shortened({count:Vs(o,W)})}),e.alwaysRule&&s.jsx("span",{className:"ms-approval-note",children:l.alwaysRule({rule:e.alwaysRule})})]}),s.jsxs("div",{className:"ms-approval-actions",children:[s.jsx($,{size:"sm",variant:"ink",className:"ms-grow",disabled:Z,onClick:()=>{C("once")},children:P?l.generate:l.allow}),e.alwaysRule&&s.jsx($,{size:"sm",variant:"outline",disabled:Z,title:e.alwaysRule,"aria-describedby":N,onClick:()=>{C("always")},children:l.alwaysHere}),s.jsx($,{size:"sm",variant:"ghost",disabled:Z,onClick:()=>{C("deny")},children:l.deny})]}),E?s.jsx("span",{id:N,className:"ms-approval-scope",children:l.alwaysScope({label:E})}):null,b&&s.jsx("p",{role:"alert",className:"ms-approval-error",children:b})]})}const XN=e=>{const t=e?.code;return typeof t=="string"?t:void 0};function Gl(e,t){switch(XN(e)){case"not-queued":return t.live.notQueued;case"queue-changed":return t.live.queueChanged;case"queue-empty":return t.live.queueEmpty;case"redirect-unsupported":return t.live.redirectUnsupported;case"live-off":return t.live.consoleLiveOff;default:return pe(e)}}function Xl(){const e=globalThis.crypto;if(typeof e?.randomUUID=="function")return e.randomUUID();const t=new Uint8Array(16);if(typeof e?.getRandomValues=="function")e.getRandomValues(t);else for(let a=0;a<16;a++)t[a]=Math.floor(Math.random()*256);t[6]=t[6]&15|64,t[8]=t[8]&63|128;const n=[...t].map(a=>a.toString(16).padStart(2,"0")).join("");return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`}function Cg({primary:e,items:t,menuLabel:n,groupLabel:a,variant:r="outline",size:l="sm",disabled:o,className:c,groupRef:d}){const[m,u]=i.useState(!1),h=i.useRef(null),f=d??h,x=i.useRef(null),p=i.useRef(null),g=b=>{const v=[...p.current?.querySelectorAll('[role="menuitem"]')??[]],y=v.indexOf(document.activeElement),w=b.key==="ArrowLeft"||b.key==="ArrowRight"?null:Ma(b.key,y<0?0:y,v.length);w!==null&&(b.preventDefault(),v[w]?.focus())};return s.jsxs("span",{ref:f,className:le("ms-split",c),role:"group","aria-label":a,children:[e,s.jsx($,{ref:x,variant:r,size:l,icon:!0,className:"ms-split-more","aria-label":n,"aria-haspopup":"menu","aria-expanded":m,disabled:o,onClick:()=>u(b=>!b),children:s.jsx(F,{name:"chevron",size:12})}),s.jsx(ot,{open:m,onClose:()=>u(!1),anchor:x,placement:"bottom-end",width:220,children:s.jsx("div",{ref:p,role:"menu","aria-label":n,onKeyDown:g,children:t.map(b=>s.jsx(dn,{"data-row":"",role:"menuitem",icon:b.icon,onClick:()=>{u(!1),b.onSelect()},children:b.label},b.key))})})]})}const ZN=e=>e.kind==="creative"||e.kind==="console";function rm({job:e,onRedirect:t,onError:n,className:a}){const l=V().web.liveUi,[o,c]=i.useState(!1),[d,m]=i.useState(!1),u=i.useRef(null);i.useEffect(()=>{c(!1)},[e.id,e.state]);const h=p=>{n?n(p):Pe.show(p)},f=async()=>{if(!o){c(!0);try{await q.stopJob(e.id)}catch{c(!1),h(l.stopFailed)}}},x=s.jsx($,{variant:"outline",size:"sm",className:"ms-stop",loading:o,disabled:o,onClick:()=>{f()},children:l.stop});return ZN(e)?s.jsxs(s.Fragment,{children:[s.jsx(Cg,{className:a,groupRef:u,primary:x,menuLabel:l.stopMenu,groupLabel:l.stop,disabled:o,items:[{key:"stop",label:l.stop,onSelect:()=>{f()}},{key:"redirect",label:l.stopAndRedirect,onSelect:()=>t?t():m(!0)}]}),d&&s.jsx(JN,{job:e,anchor:u,onClose:()=>m(!1)})]}):s.jsx("span",{className:le("ms-split",a),children:x})}function JN({job:e,anchor:t,onClose:n}){const a=V(),r=a.web.liveUi,l=i.useId(),[o,c]=i.useState(""),[d,m]=i.useState(null),[u,h]=i.useState(!1),f=i.useRef(!1),x=i.useRef(null),p=i.useRef(null);i.useEffect(()=>{p.current?.focus()},[]);const g=async()=>{const b=o.trim();if(!(!b||f.current)){f.current=!0,h(!0),m(null),x.current??=Xl();try{await q.redirectJob(e.id,{clientId:x.current,text:b}),n()}catch(v){m(r.redirectFailed({detail:Gl(v,a)}))}finally{f.current=!1,h(!1)}}};return s.jsx(ot,{open:!0,onClose:n,anchor:t,placement:"bottom-end",width:300,label:r.redirectTitleFor({label:e.label}),children:s.jsxs("form",{className:"ms-redirect-form",onSubmit:b=>{b.preventDefault(),g()},children:[s.jsx("label",{htmlFor:l,className:"ms-redirect-label",children:r.redirectFieldLabel}),s.jsx(nn,{id:l,ref:p,rows:3,maxLength:4e3,value:o,placeholder:r.redirectPlaceholder,onChange:b=>{c(b.target.value),x.current=null}}),s.jsx("p",{className:"ms-redirect-note",children:r.redirectNote}),d&&s.jsx("p",{role:"alert",className:"ms-composer-error",children:d}),s.jsxs("div",{className:"ms-redirect-actions",children:[s.jsx($,{size:"sm",variant:"ghost",onClick:n,children:r.redirectCancel}),s.jsxs($,{type:"submit",size:"sm",variant:"accent","aria-label":r.redirectSend,disabled:!o.trim()||u,children:[s.jsx(F,{name:"forward",size:13}),r.redirectSend]})]})]})})}function YN({jobId:e,liveInput:t,job:n,events:a}){const r=V(),l=r.web.liveUi,o=i.useId(),[c,d]=i.useState(""),[m,u]=i.useState(!1),[h,f]=i.useState(null),[x,p]=i.useState([]),g=new Set((a??[]).flatMap(j=>j.kind==="user_message_not_delivered"?[j.clientId]:[])),b=i.useRef(!1),v=i.useRef(null),y=t===!0&&c.trim().length>0&&!m,w=async()=>{if(!(!y||b.current)){b.current=!0,u(!0),f(null),v.current??=Xl();try{const j=v.current;await q.sendConsoleMessage(e,{clientId:j,text:c.trim()}),p(S=>[...S,{clientId:j,text:c.trim()}]),d(""),v.current=null}catch(j){f(Gl(j,r))}finally{b.current=!1,u(!1)}}};return s.jsx("form",{className:"ms-composer ms-console-box",onSubmit:j=>{j.preventDefault(),w()},children:s.jsxs("div",{className:"ms-composer-box",children:[s.jsx("label",{htmlFor:o,className:"ms-composer-label",children:l.consoleMessage}),s.jsx(nn,{id:o,rows:2,maxLength:4e3,value:c,disabled:t!==!0,placeholder:l.livePlaceholder,onChange:j=>{d(j.target.value),v.current=null},onKeyDown:j=>{j.key==="Enter"&&!j.shiftKey&&!j.nativeEvent.isComposing&&(j.preventDefault(),w())}}),t===!1&&s.jsx("p",{className:"ms-composer-note",children:l.consoleUnsupported}),x.filter(j=>g.has(j.clientId)).map(j=>s.jsxs("div",{className:"ms-console-lost",children:[s.jsx("span",{className:"ms-pill ms-warn",children:l.state.notDelivered})," ",s.jsx("span",{children:j.text}),s.jsx("p",{className:"ms-composer-note",role:"status",children:l.notDeliveredReason})]},j.clientId)),h&&s.jsx("p",{role:"alert",className:"ms-composer-error",children:h}),s.jsxs("div",{className:"ms-composer-foot",children:[s.jsx("span",{className:"ms-composer-hint",children:t===!0?l.liveHint:""}),n&&s.jsx(rm,{job:n,onError:f}),s.jsxs($,{type:"submit",size:"sm",variant:"accent","aria-label":l.send,disabled:!y,children:[s.jsx(F,{name:"upload",size:13,strokeWidth:1.8}),l.send]})]})]})})}function Eg(e,t=!0){const[,n]=i.useReducer(u=>u+1,0),a=i.useRef([]),r=i.useRef(new Set),l=i.useRef(new Set),o=new Map(e.map(u=>[u.id,u]));for(const u of o.keys())r.current.delete(u);const c=[],d=new Set;for(const u of a.current){const h=o.get(u.id);h?c.push(h):r.current.has(u.id)?r.current.delete(u.id):t&&c.push(u),d.add(u.id)}for(const u of e)d.has(u.id)||(c.push(u),d.add(u.id));a.current=c,l.current=new Set(o.keys());const m=i.useCallback(u=>{l.current.has(u)||r.current.has(u)||!a.current.some(h=>h.id===u)||(r.current.add(u),n())},[]);return{list:a.current.map(u=>({approval:u,leaving:!o.has(u.id)})),gone:m}}const QN=["en","it"],Jc=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),uf="",mf="",e0=QN.flatMap(e=>{const t=al(e).composition.svgRefused({file:uf,reason:mf}),[n,a]=t.split(uf),[r,l]=(a??"").split(mf);return n===void 0||r===void 0||l===void 0?[]:[new RegExp(`^(?:[^:]{1,200}:\\s*)?${Jc(n)}(.{1,300}?)${Jc(r)}([\\s\\S]+?)${Jc(l)}$`)]});function lm(e){const t=[],n=new Map;for(const a of e){let r=null;for(const m of e0)if(r=a.match(m),r)break;if(!r){t.push({kind:"plain",text:a});continue}const l=r[1],o=r[2],c=n.get(l);if(c){c.reasons.includes(o)||c.reasons.push(o);continue}const d={kind:"svg",file:l,reasons:[o]};n.set(l,d),t.push(d)}return t}const s0=e=>e.filter(t=>lm([t])[0]?.kind==="svg");function Tg(e,t,n=a=>a){return lm(e).map(a=>a.kind==="plain"?n(a.text):t.composition.svgRefusedSummary({file:a.file,count:a.reasons.length}))}const Bn=(e,t)=>e?.compositions?.find(n=>n.format===t)??null,t0=(e,t)=>vj(e,t),hf=e=>e.state==="queued"||e.state==="running",n0=(e,t)=>t!==null&&(e.key===t||e.key.startsWith(`${t}:`)),a0=(e,t)=>!e.formats?.length||e.formats.includes(t),ff=e=>e.finishedAt??e.startedAt??e.createdAt;function Rg(e,t){return bj(e,t)}function no(e,t,n,a,r){if(!e||!Bn(e,t))return null;const l=t0(a,e.n),o=n.filter(h=>h.kind==="render"&&n0(h,l)&&a0(h,t)),c=o.find(hf),d=()=>{if(rc(e,t,r)!=="rendered")return null;const h=ax(e,t);return h.length?{kind:"problem",problems:h}:{kind:"rendered"}};if(c){if(c.state==="queued")return{kind:"queued",ahead:c.queuePosition??null};const h=c.progress,f=(c.formats?.length??0)!==1;return(h?h.format===t:!f)?{kind:"rendering",pct:Rg(c,t)}:d()??{kind:"queued",ahead:null}}const m=d();if(m)return m;const u=o.filter(h=>!hf(h)).sort((h,f)=>ff(f).localeCompare(ff(h)))[0];return u?.state==="failed"?{kind:"failed",error:u.error??null}:{kind:"none"}}function pf(e,t,n){const a=t.web.exportUi.problemShort,r=l=>typeof l=="number"?r0(n,l):String(l??"");return e?.issues?.length?e.issues.map(l=>{const o=l.params;switch(l.code){case"tooLarge":return a.tooLarge({size:r(o.size),max:r(o.max)});case"durationOffTarget":return a.durationOffTarget({duration:r(o.duration),target:r(o.target)});case"durationOverMax":return a.durationOverMax({duration:r(o.duration),max:r(o.max)});case"badResolution":return a.badResolution({size:`${r(o.width)}×${r(o.height)}`,expected:`${r(o.expectedWidth)}×${r(o.expectedHeight)}`});case"notReadable":return a.notReadable;case"badExtension":return a.badExtension({ext:String(o.ext??"")});default:return""}}).filter(Boolean):Tg(e?.problems??[],t,l=>l.replace(/^[^:]{1,200}:\s*/,""))}const r0=(e,t)=>new Intl.NumberFormat(e,{maximumFractionDigits:1}).format(t);function Yd(e,t){const n=e?.export;return n?.stage==="copying"?t.copying:n?.stage==="rendering"&&n.renders?.length?t.renderingFirst({pct:n.pct??0}):t.running}const Mi=new Map,Tr=new Map,Ml={setRetry(e,t){Mi.set(e,t)},takeRetry(e){const t=Mi.get(e)??null;return Mi.delete(e),t},forget(e){Mi.delete(e)},watch(e){return Tr.set(e,(Tr.get(e)??0)+1),()=>{const t=(Tr.get(e)??1)-1;t>0?Tr.set(e,t):Tr.delete(e)}},watched(e){return Tr.has(e)}};function Xr(e){if(!e)return null;for(let t=e.length-1;t>=0;t--){const n=e[t];if(n.kind==="progress"&&n.text.trim())return n.text.trim()}return null}const xf=e=>String(e).padStart(2,"0"),Mg=(e=new Date)=>`${e.getFullYear()}-${xf(e.getMonth()+1)}-${xf(e.getDate())}`,l0=(e=new Date)=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).toISOString(),i0=(e=new Date)=>new Date(e.getFullYear(),e.getMonth(),e.getDate()+1).getTime()-e.getTime(),$g=(e,t)=>{const n=e.liveUsage?.[t];return n?_n(n.tokens):0};function o0(e,t){if(!e.today)return e;const n=e.today.jobs[t]??{offset:0,counted:0},a=(e.jobUsage?.[t]?.done??0)+$g(e,t)-n.offset;return a<=n.counted?e:{...e,today:{...e.today,tokens:e.today.tokens+a-n.counted,jobs:{...e.today.jobs,[t]:{...n,counted:a}}}}}function gf(e,t,n){const a=e.jobUsage?.[t]??{done:0,runs:0,peak:0},r=n.live?a.done:a.done+_n(n.tokens),l=r+(n.live?_n(n.tokens):0),o={done:r,runs:a.runs+(n.live?0:1),peak:Math.max(a.peak,l)};return o0({...e,jobUsage:{...e.jobUsage,[t]:o}},t)}function c0(e,t){const n=new Set([...Object.keys(e.jobUsage??{}),...Object.keys(e.liveUsage??{})]),a={};let r=t.tokens;for(const l of n){const o=$g(e,l);a[l]={offset:e.jobUsage?.[l]?.done??0,counted:o},r+=o}return e.today&&e.today.day===t.day&&(r=Math.max(r,e.today.tokens)),{...e,today:{day:t.day,tokens:r,billing:t.billing,jobs:a}}}function d0(e,t){return e&&Object.fromEntries(Object.entries(e).filter(([n])=>t.has(n)))}function u0(e,t){const n={};for(const a of t)(e?.[a.id]||a.state==="running")&&(n[a.id]=!0);return n}const $l=(e,t)=>e.partialUsage?.[t]===!0;function Fg(e,t=new Date){return e.today&&e.today.day===Mg(t)?e.today.tokens:null}function Do(e,t){const n=e.jobUsage?.[t];return n?n.peak:null}function m0(e,t){const n=e.jobUsage?.[t];return n&&n.runs>0?n.done:null}function im({problems:e,className:t}){const n=i.useMemo(()=>lm(e),[e]);return s.jsx("ul",{className:t,children:n.map((a,r)=>a.kind==="plain"?s.jsx("li",{children:a.text},`p${r}`):s.jsx(h0,{file:a.file,reasons:a.reasons},`s${r}`))})}function h0({file:e,reasons:t}){const n=V(),a=i.useId(),[r,l]=i.useState(!1);return s.jsxs("li",{children:[s.jsx("span",{children:n.composition.svgRefusedSummary({file:e,count:t.length})})," ",s.jsx($,{size:"sm",variant:"ghost","aria-expanded":r,"aria-controls":a,onClick:()=>l(o=>!o),children:n.composition.svgRefusedDetails}),r?s.jsx("ul",{id:a,lang:"en",children:t.map(o=>s.jsx("li",{children:o},o))}):null]})}const Pg=e=>e.state==="queued"||e.state==="running";function f0(e,t,n){const a=`:${t}:${n}`;return Object.values(e.jobs).find(r=>Pg(r)&&r.key.startsWith("creative:")&&r.key.endsWith(a))??null}function p0(e,t){const n=e.lastIndexOf(":");return n>0&&e.slice(0,n).endsWith(`:${t}`)?e.slice(n+1):null}function Ag(e,t,n){const a=d=>d===e.slug||!!e.variants&&jj(d)&&lc(d)===e.slug,r=Object.values(n.approvals).filter(d=>d.projectSlug===t&&d.creativeSlug!==null&&a(d.creativeSlug)).sort((d,m)=>d.createdAt.localeCompare(m.createdAt))[0]??null,l=Object.values(n.jobs).filter(d=>Pg(d)&&d.key.startsWith("creative:")).map(d=>({j:d,slug:p0(d.key,t)})).filter(d=>d.slug!==null&&a(d.slug)).sort((d,m)=>rx(Bl(d.slug),Bl(m.slug)))[0]?.j??null,o=l?Xr(n.events[l.id]):null;return{state:r?"needs":l||e.status==="working"?"running":e.status==="error"?"failed":e.status,approval:r,job:l,step:o}}const x0=["all","needs","running","ready","drafts"];function vf(e,t){switch(e){case"all":return!0;case"needs":return t==="needs";case"running":return t==="running";case"ready":return t==="ready"||t==="incomplete";case"drafts":return t==="draft"}}function g0(e,t,n){const a=e.map(c=>{const d=pt(t,c);return{id:c,preset:d,a:d?d.width/d.height:1}});if(a.length===0)return[];const r=a.reduce((c,d)=>c+d.a,0),l=n.maxWidth-n.gap*(a.length-1),o=Math.min(n.height,l/r);return a.map(({id:c,preset:d,a:m})=>({id:c,preset:d,width:Math.round(o*m),height:Math.round(o)}))}function Lg(e,t){const n=t===void 0?e:e.filter(a=>a.type==="group-turn"||!a.group&&(a.variant===void 0||a.variant===t));for(let a=n.length-1;a>=0;a--){const r=n[a];if(r.type==="group-turn"){const l=t===void 0?void 0:r.outcome.find(o=>o.variant===t);if(!l)continue;return l.status==="failed"||l.status==="stopped"?l.instruction?{text:l.instruction,direct:!0}:{}:{}}if(Eu(r))return{};if(r.type==="user"&&!r.group)return{text:r.text,...r.pins.length?{pins:r.pins}:{},direct:!0}}return{}}const v0=/\.(mp4|mov|webm|m4v)$/i,b0=/\.gif$/i;function om(e){const t=e.split(/[?#]/)[0];return v0.test(t)?"video":b0.test(t)?"animated":"image"}const tr=e=>om(e)==="video";function Ig(e){if(tr(e))return e;const t=/^(.*\/)?\.previews\/([^/]+)\.jpg$/i.exec(e);return t&&tr(t[2])?`${t[1]??""}${t[2]}`:null}const Da=(e,t,n,a)=>q.fileUrl(e,t,`outputs/v${n}/${a}`);function Nr(e,t,n,a){const r=l=>Da(e,t,n,l);return tr(a.file)?a.preview?{src:r(a.preview),video:!1}:{src:r(a.file),video:!0}:{src:r(a.file),video:!1}}function Yc(e,t,n,a,r){const l=n.at(-1)??null,o=[...e,...l?.outputs.map(c=>c.format).filter(c=>!e.includes(c))??[]];return[...new Set(o)].map(c=>{const d=a(c);return{id:c,preset:pt(t,c),...r?{labels:r}:{},out:d.n===null?null:n.find(m=>m.n===d.n)?.outputs.find(m=>m.format===d.format)??null,n:d.n}})}function zg(e,t){const n=e/t,a=r=>({width:Math.round(r),height:Math.max(24,Math.round(r/n))});return n<=.75?{width:Math.round(540*n),height:540}:n<1?a(300):n<=1.25?a(344):n<=2.5?a(420):a(520)}function gc(e){return e.preset?zg(e.preset.width,e.preset.height):{width:300,height:300}}const Og=60,j0=40,y0=140,cm=40,Dg=44,w0=50,dm=176,k0=216,$i=.1,Rr=.4,N0=40,Bg=Dg;function um(e,t=!1){return e>=.5?t?k0:dm:N0}const Fl="\0store-pack";function Bo(e,t){const n=new Map;for(const a of e){const r=t.has(a.id)?Fl:a.preset?.channel??"";n.set(r,[...n.get(r)??[],a])}return[...n.entries()]}function Ug(e,t){return Bo(e,t).flatMap(([n,a])=>n===Fl?Bo(a,new Set).map(([r,l])=>({channel:r,pack:!0,boards:l})):[{channel:n,pack:!1,boards:a}])}function Uo(e,t){return Ug(e,t).map(n=>n.pack?{boards:n.boards,alone:!0}:{boards:n.boards})}function mm(e,t,n,a,r){const l=new Set(n.storePack?jo(n.storePack):[]),o=e.map(c=>({id:c,preset:pt(t,c),out:null}));return Ug(o,l).map(c=>({label:c.channel!==""?Dn(c.channel,a):r,items:c.boards.map(d=>({id:d.id,name:xn(d.preset,d.id,a,n.formatLabels)}))}))}function S0(e,t){const n=e.boards.filter(a=>!su(a));return[...e.boards.filter(su).map(a=>({stack:!1,boards:[a],cols:1})),...n.length?[{stack:!0,boards:n,cols:Math.max(1,Math.min(t,n.length))}]:[]]}function hm(e,t,n={}){const a=w0+(n.head??0),r=e.boards.map(gc).map(m=>({width:Math.max(m.width*t,um(t,n.grouped)),height:a+m.height*t})),l=Math.max(1,Math.min(e.cols,r.length)),o=Array.from({length:l},(m,u)=>Math.max(...r.filter((h,f)=>f%l===u).map(h=>h.width))),c=Math.ceil(r.length/l),d=Array.from({length:c},(m,u)=>Math.max(...r.slice(u*l,u*l+l).map(h=>h.height)));return{width:o.reduce((m,u)=>m+u,0)+cm*t*(l-1),height:d.reduce((m,u)=>m+u,0)+Dg*t*(c-1)}}const ao=(e,t,n)=>e.reduce((a,r)=>a+hm(r,t,n).width,0)+cm*t*Math.max(0,e.length-1),C0=(e,t,n)=>e.reduce((a,r)=>a+Math.max(...r.map(l=>hm(l,t,n).height)),0)+Bg*t*Math.max(0,e.length-1);function Qd(e,t,n,a,r=1){const l=n===null?1/0:n-2*Og*t,o=cm*t,c=[];let d=!1;for(const m of e){const u=S0(m,r);if(!u.length)continue;const h=c.at(-1);if(d&&!m.alone&&h&&ao(h,t,a)+o+ao(u,t,a)<=l+1e-6){h.push(...u);continue}const f=c.length;let x=[];c.push(x);for(const p of u)x.length&&ao(x,t,a)+o+hm(p,t,a).width>l+1e-6&&(x=[],c.push(x)),x.push(p);d=!m.alone&&c.length-f===1}return c}function fm(e,t,n=null,a,r=1,l=t){let o=0,c=Bg*t*Math.max(0,e.length-1);for(const d of e){const m=Qd(d.groups,l,n,a,r);o=Math.max(o,...m.map(u=>ao(u,t,a))),c+=d.head+C0(m,t,a)}return{width:o+2*Og*t,height:c+(j0+y0)*t}}const E0=(e,t)=>e>.5+1e-9?Math.max(t,Math.round((e-.05)*20)/20):Math.max(t,Math.round((e-.01)*100)/100),T0=e=>e.some(t=>t.groups.some(n=>n.boards.length)),_g=e=>Math.max(1,...e.flatMap(t=>t.groups.map(n=>n.boards.filter(a=>!su(a)).length)));function eu(e,t,n,a,r,l=-1,o=1,c){let d=o;for(;;){if(d<=l+1e-9)return null;const m=fm(e,d,t.width,a,r,c??d);if(m.width<=t.width+1e-6&&m.height<=t.height+1e-6||d<=n+1e-9)return d;d=E0(d,n)}}function R0(e,t,n,a){if(!T0(e)||t.width<=0||t.height<=0)return null;let r={zoom:eu(e,t,n,a,1),cols:1};for(let l=2;l<=_g(e)&&!(fm(e,r.zoom,t.width,a,l).width>t.width+1e-6);l++){const o=eu(e,t,n,a,l,r.zoom);o!==null&&(r={zoom:o,cols:l})}return r}function Fi(e,t,n,a){const r=M0(e,t,n,a),l=gl.get(r);if(l!==void 0)return l;const o=$0(e,t,n,a);return gl.size>=32&&gl.delete(gl.keys().next().value),gl.set(r,o),o}const gl=new Map,M0=(e,t,n,a)=>`${t.width}x${t.height}:${n}:${a?.head??0}:${a?.grouped?1:0}|${e.map(r=>`${r.head}=${r.groups.map(l=>`${l.alone?"!":""}${l.boards.map(o=>o.preset?`${o.preset.width}x${o.preset.height}`:"-").join(",")}`).join(";")}`).join("|")}`;function $0(e,t,n,a){const r=R0(e,t,n,a);if(!r)return null;const l=e.some(c=>c.groups.some(d=>d.alone));if(r.zoom>=Rr-1e-9||l||n>=Rr)return{...r,all:r.zoom};let o=1;for(;o<_g(e)&&fm(e,Rr,t.width,a,o+1).width<=t.width+1e-6;)o++;return{zoom:Rr,cols:o,all:eu(e,t,n,a,o,-1,Rr,Rr)}}function F0(e,t,n={x:0,y:0}){return{x:e.x*t+n.x,y:e.y*t+n.y}}function pm(e){const t=(a,r)=>r?t(r,a%r):a,n=t(e.width,e.height);return e.width/n<=21&&e.height/n<=21?`${e.width/n}:${e.height/n}`:`${e.width}×${e.height}`}const su=e=>e.preset?e.preset.width/e.preset.height<=.75:!1,bf=e=>Math.round(e*1e3)/1e3,jf=e=>Math.min(1,Math.max(0,e));function xm(e,t){return!e.width||!e.height||t.detail===0?{x:.5,y:.5}:{x:jf(bf((t.clientX-e.left)/e.width)),y:jf(bf((t.clientY-e.top)/e.height))}}const _o=140,P0=3;function A0(e,t){return t&&e.some(n=>kt(n)==="identity-logo")?P0:1}function L0(e,t){return Array.from({length:e},(n,a)=>t[a]?.trim()||null)}const It=e=>e.toUpperCase();function Pi(e,t){return e.members.filter(n=>n.status==="active"||t)}function I0(e,t,n){return{job:f0(e,t,n),needs:Object.values(e.approvals).some(a=>a.projectSlug===t&&a.creativeSlug===n)}}const z0=e=>e.job!==null;function O0(e,t,n){const a=yj(e,t,n);return a.ok||a.reason==="unknown"?null:a.reason}function D0(e,t,n,a){if(t)return{kind:"missing"};if(e.status==="discarded")return{kind:"discarded"};if(n.needs)return{kind:"needs"};if(n.job?.state==="queued")return{kind:"waiting",reason:n.job.waitReason??null};if(n.job)return{kind:"working"};switch(a){case"error":return{kind:"failed"};case"interrupted":return{kind:"stopped"};case"working":return{kind:"working"};case"ready":return{kind:"ready"};case"incomplete":return{kind:"incomplete"};default:return{kind:"draft"}}}function B0(e,t){return e.map(n=>{const a=t.find(r=>r.format===n);return a?a.source==="pick"?{format:n,source:"pick",variant:a.letter,n:a.version}:{format:n,source:"default",variant:a.letter,n:a.version}:{format:n,source:"default",variant:null,n:null}})}function gm(e){return!e||e.orphan?{discarded:!1,host:!1}:{discarded:e.group.members.find(n=>n.letter===e.letter)?.status==="discarded",host:e.letter==="a"}}const U0=e=>e.map(It).join(", ");function _0(e,t){return e?e.includes("~")?Bl(e):t?.find(n=>n.slug===e)?.variants?"a":null:null}const Qc=32;function tu(e){const t=e?.trim();if(!t)return null;const n=t.split(/\s+[—–-]\s+|[:;,]\s*|[.!?](?:\s+|$)/)[0].trim()||t;if(n.length<=Qc)return n;const a=n.split(/\s+/);let r="";for(const l of a){const o=r?`${r} ${l}`:l;if(o.length>Qc-1)break;r=o}return`${r||n.slice(0,Qc-1)}…`}const qg=360,Vg=210,ro=24,vm=16,ed=12;function q0(e,t,n){const a=Math.max(qg*e,Vg);if(t<=0)return a;const r=t-2*vm;if(a>=r)return r;const l=Math.floor((r+ro)/(a+ro));return n<=l?a:(r-(l-1)*ro)/l}const V0=104,Vr=12;function K0(e,t,n=V0){const a=Math.max(1,Math.min(t,Math.floor((e+Vr)/(n+Vr))));return{cols:a,width:(e-(a-1)*Vr)/a}}const W0=150;function H0(e,t,n,a){const r=Kg(n,t)??e,l=q0(r,t,n)-2*ed,o=K0(l,Math.max(1,a),W0),c=e/r,d=t>0?t-2*vm-2*ed:1/0,m=Math.min(o.width*c,d),u=Math.max(1,Math.min(o.cols,Math.floor((d+Vr)/(m+Vr))));return{width:Math.max(Vg,2*ed+u*m+(u-1)*Vr),cols:u,cell:m,scale:c}}const G0=440,X0=320;function Z0(e,t,n,a=1){const r=gc(e),l=n?Math.min(t*1.25,G0*a):Math.min(t*16/9,X0*a);return Math.min(t/r.width,l/r.height)}function Kg(e,t,n=.5){if(e<=0||t<=0)return null;const a=(t-2*vm-(e-1)*ro)/(e*qg);return Math.max(n,Math.min(1,Math.floor(a*20+1e-9)/20))}function J0(e,t,n){const a=e.members.filter(r=>r.status==="active");return a.length<2||Object.keys(e.picks).length>0||a.some(r=>t.includes(r.letter)||n(r.letter)!=="ready")?null:a.length}function Y0(e,t,n){const a=[],r=[];for(const l of e){if(n){const d=n.find(u=>u.format===l),m=d?{format:l,letter:d.letter,slug:d.slug,n:d.version}:{format:l,letter:null,slug:null,n:null};(d?.source==="pick"?a:r).push(m);continue}const o=Object.hasOwn(t.picks,l)?t.picks[l]:void 0,c=o?t.members.find(d=>d.slug===o.slug&&d.status==="active"):void 0;o&&c?a.push({format:l,letter:c.letter,slug:c.slug,n:o.version}):r.push({format:l,letter:null,slug:null,n:null})}return{chosen:a,open:r}}const Wg=(e,t)=>`ms.variantView.${e}/${t}`;function Q0(e,t,n){try{return localStorage.getItem(Wg(e,t))==="all"?"all":"chosen"}catch{return"chosen"}}function eS(e,t,n){try{localStorage.setItem(Wg(e,t),n)}catch{}}const yf=32,sS=20,sd={head:22,grouped:!0};function tS(e,t,n){return[{groups:Uo(e,n),head:yf},...t.length?[{groups:Uo(t,n),head:yf+sS}]:[]]}const nS=20,Hg=e=>e.state==="queued"||e.state==="running",aS=e=>!Hg(e),qo=e=>e.finishedAt??e.startedAt??e.createdAt;function rS(e){const t=Object.values(e.jobs),n=Object.values(e.approvals).sort((l,o)=>l.createdAt.localeCompare(o.createdAt)),a=t.filter(Hg).sort((l,o)=>l.createdAt.localeCompare(o.createdAt)),r=t.filter(aS).sort((l,o)=>qo(o).localeCompare(qo(l))).slice(0,nS);return{approvals:n,running:a,done:r}}function Ba(e){if(e.key.startsWith("variant-directions:"))return Ba({...e,key:e.key.slice(19)});if(e.key.startsWith("group:"))return Ba({...e,key:e.key.slice(6)});const t=e.key.split(":"),n=t[0];if((n==="creative"||n==="subtitles")&&t.length>=4)return{project:t.at(-2),creative:t.at(-1)};if(n==="subtitles-translate"&&t.length>=5)return{project:t.at(-3),creative:t.at(-2)};if(n==="video-analysis"&&t.length>=4)return{project:t.at(-2),creative:null};if(n==="export"&&t.length>=5)return{project:t.at(-3),creative:t.at(-2)};if(n==="render-export"&&t.length>=6)return{project:t.at(-4),creative:t.at(-3)};if(n==="render"&&t.length>=5){const a=/^\d+$/.test(t.at(-1))&&/^v\d+$/.test(t.at(-2))?-1:0;return{project:t.at(-3+a),creative:t.at(-2+a)}}return(n==="brand"||n==="project"||n==="generate"||n==="brief")&&t.length>=3?{project:t.at(-1),creative:null}:null}function Gg(e){const t=Ba(e);return!t||!t.project?null:t.creative?es.creative(t.project,t.creative):e.kind==="brand-analysis"?es.project(t.project,"brand"):e.kind==="asset-description"||e.kind==="asset-generation"||e.kind==="video-analysis"?es.project(t.project,"assets"):e.kind==="brief"?es.newCreative(t.project):es.project(t.project)}function lS(e){if(e.kind!=="video-analysis")return null;const t=e.label.indexOf(" · ");return{jobId:e.id,name:t>=0&&e.label.slice(t+3)||null}}function iS(e){const t={},n=new Map;for(const a of e){if(a.type==="group-turn"){t[a.jobId]={group:a.outcome};continue}if(a.group)continue;const r=a.variant??"",l=n.get(r)??null;if(a.type==="agent")n.set(r,a.jobId);else if(a.type==="user")n.set(r,null);else if(l&&!t[l]){const o=Eu(a);o&&(t[l]=o.kept||o.status===null?{n:o.n,kept:!0}:{n:o.n,status:o.status})}}return t}function oS(e,t){const[n,a]=i.useState({}),r=e.filter(c=>(c.kind==="creative"||c.kind==="creative-group")&&c.state==="succeeded"&&!n[c.id]),l=[...new Set(r.map(c=>{const d=Ba(c);return d?.creative?`${d.project}
|
|
4
|
+
${d.creative}`:null}).filter(c=>c!==null))],o=t?`${l.join("|")}#${r.map(c=>c.id).join(",")}`:"";return i.useEffect(()=>{if(!o)return;let c=!0;for(const d of l){const[m,u]=d.split(`
|
|
5
|
+
`);Promise.resolve().then(()=>q.getConversation(m,u)).then(h=>{c&&a(f=>({...f,...iS(h)}))}).catch(()=>{})}return()=>{c=!1}},[o]),n}function cS(e,t){if(e.error)return e.error;for(let n=(t?.length??0)-1;n>=0;n--){const a=t[n];if(a.kind==="result"&&!a.ok&&a.error?.trim())return a.error.trim()}return null}function dS({live:e,initialTab:t,request:n=0,where:a}){const l=V().web.shell.activity,{approvals:o,running:c,done:d}=i.useMemo(()=>rS(e),[e]),[m,u]=i.useState(t??(o.length?"needs":"running")),h=Eg(o,m==="needs"),f=h.list.filter(y=>!y.leaving).length,[,x]=i.useState(0),p=i.useRef(n);i.useEffect(()=>{n!==p.current&&(p.current=n,t&&u(t))},[n,t]);const g=oS(d,m==="done"),b=`${i.useId()}-panel`,v=()=>{const y=()=>x(w=>w+1);Promise.resolve(Notification.requestPermission(y)).then(y,()=>{})};return s.jsxs("div",{className:"ms-activity","aria-label":l.label,role:"region",children:[s.jsx("div",{className:"ms-activity-head",children:s.jsx(hc,{label:l.sections,variant:"bar",value:m,onChange:u,tabs:[{value:"needs",label:l.needsYou,count:f,controls:b},{value:"running",label:l.running,count:c.length,controls:b},{value:"done",label:l.done,count:d.length,controls:b}]})}),s.jsxs("div",{id:b,role:"tabpanel",tabIndex:-1,className:"ms-activity-body",children:[m==="needs"&&hw()&&s.jsxs($,{size:"sm",variant:"outline",className:"ms-activity-ask",onClick:v,children:[s.jsx(F,{name:"bell",size:13}),l.enableNotifications]}),m==="needs"&&(h.list.length?h.list.map(({approval:y,leaving:w})=>s.jsx(mS,{approval:y,leaving:w,onGone:h.gone,where:a},y.id)):s.jsx(Rt,{icon:"check",title:l.emptyNeeds,sub:l.emptyNeedsSub})),m==="running"&&(c.length?s.jsx("ul",{className:"ms-activity-list",children:wf(c).map(y=>y.kind==="render"?s.jsx(fS,{job:y},y.id):y.kind==="export"?s.jsx(pS,{job:y},y.id):s.jsx(kf,{job:y,step:Xr(e.events[y.id]),tokens:Do(e,y.id),partial:$l(e,y.id),events:e.events[y.id],helpers:uS(c,y).map(w=>s.jsx(kf,{job:w,child:!0,step:Xr(e.events[w.id]),tokens:Do(e,w.id),partial:$l(e,w.id)},w.id))},y.id))}):s.jsx(Rt,{icon:"clock",title:l.emptyRunning,sub:l.emptyRunningSub})),m==="done"&&(d.length?s.jsx("ul",{className:"ms-activity-list",children:wf(d).map(y=>s.jsx(vS,{job:y,made:g[y.id]??null,failure:y.state==="failed"?cS(y,e.events[y.id]):null,tokens:m0(e,y.id),partial:$l(e,y.id)},y.id))}):s.jsx(Rt,{icon:"check",title:l.emptyDone,sub:l.emptyDoneSub}))]}),s.jsx(xS,{tokens:Fg(e)})]})}const wf=e=>e.filter(t=>!t.parentJobId||!e.some(n=>n.id===t.parentJobId)),uS=(e,t)=>t.kind==="creative-group"?e.filter(n=>n.parentJobId===t.id):[];function mS({approval:e,leaving:t,onGone:n,where:a}){const r=V(),l=e.creativeSlug?es.creative(e.projectSlug,e.creativeSlug):es.project(e.projectSlug);return s.jsxs("div",{className:"ms-activity-need",children:[s.jsxs("div",{className:"ms-activity-context",hidden:t,children:[s.jsx("span",{className:"ms-activity-where",children:a(e.projectSlug,e.creativeSlug)}),s.jsxs($,{size:"sm",variant:"ghost",onClick:()=>Bs(l),children:[r.web.shell.activity.open,s.jsx(F,{name:"forward",size:12})]})]}),s.jsx(ri,{approval:e,leaving:t,onGone:n})]})}function vc({job:e,className:t,children:n,after:a,nested:r}){const l=Gg(e),o=lS(e),c=o?Ba(e):null,d=o&&c?()=>hN(c.project,o):void 0;return s.jsxs("li",{className:le("ms-activity-item",a!==void 0&&"ms-activity-with-after",!!r?.length&&"ms-activity-parent"),children:[l?s.jsx("a",{className:le("ms-activity-row ms-activity-link",t),href:l,onClick:d,children:n}):s.jsx("div",{className:le("ms-activity-row",t),children:n}),a,r?.length?s.jsx("ul",{className:"ms-activity-children",children:r}):null]})}function hS(e){const t=rs(),n=i.useContext(Mn),a=Ba(e),r=a?.creative?n?.catalog.creatives[a.project]?.find(o=>o.slug===a.creative)?.formatLabels:void 0,l=o=>xn(pt(Tu,o),o,t,r);return o=>{const c=o.lastIndexOf("."),d=c>0?o.slice(c+1):"";return ei.some(m=>m.tag===d)?`${l(o.slice(0,c))} (${Js(d,t)})`:l(o)}}function fS({job:e}){const n=V().web.render,a=rs(),r=hS(e),l=e.state==="queued",o=e.progress,c=l?e.queuePosition?n.queuedAhead({count:e.queuePosition}):n.queued:o?o.phase==="media"?n.mediaProgress({format:r(o.format),done:o.done,total:o.total}):o.phase==="finishing"?n.finishing({format:r(o.format)}):n.framesProgress({format:r(o.format),done:Vs(a,o.done),total:Vs(a,o.total)}):n.starting,[d,m]=i.useState(!1),u=()=>{m(!0),Promise.resolve().then(()=>q.cancelJob(e.id)).catch(h=>{m(!1),Pe.show(n.cancelFailed({detail:pe(h)}))})};return s.jsxs(vc,{job:e,className:"ms-tall",after:s.jsx($,{size:"sm",variant:"ghost",className:"ms-activity-cancel",loading:d,disabled:d,"aria-label":n.cancelRender({label:e.label}),onClick:u,children:n.cancel}),children:[s.jsx("span",{className:le("ms-activity-glyph",l&&"ms-muted"),children:l?s.jsx(F,{name:"clock",size:14}):s.jsx(Ts,{decorative:!0})}),s.jsxs("span",{className:"ms-activity-text",children:[s.jsx("b",{children:e.label}),s.jsx("span",{className:"ms-activity-sub",children:c}),!l&&o?.phase==="frames"?s.jsx(kr,{className:"ms-activity-bar",value:Rg(e,o.format),label:c}):null]})]})}function pS({job:e}){const t=V(),n=t.web.exportUi,a=e.state==="queued",r=a?t.web.shell.activity.queued:Yd(e,n),l=e.export?.stage==="rendering"&&e.export.renders?.length?e.export.pct:null,[o,c]=i.useState(!1),d=()=>{c(!0),Promise.resolve().then(()=>q.cancelJob(e.id)).catch(m=>{c(!1),Pe.show(t.web.render.cancelFailed({detail:pe(m)}))})};return s.jsxs(vc,{job:e,className:"ms-tall",after:s.jsx($,{size:"sm",variant:"ghost",className:"ms-activity-cancel",loading:o,disabled:o,"aria-label":n.cancelOf({label:e.label}),onClick:d,children:t.web.render.cancel}),children:[s.jsx("span",{className:le("ms-activity-glyph",a&&"ms-muted"),children:a?s.jsx(F,{name:"clock",size:14}):s.jsx(Ts,{decorative:!0})}),s.jsxs("span",{className:"ms-activity-text",children:[s.jsx("b",{children:e.label}),s.jsx("span",{className:"ms-activity-sub",children:r}),l!=null?s.jsx(kr,{className:"ms-activity-bar",value:l,label:r}):null]})]})}function xS({tokens:e}){const n=V().web.usage,a=rs();return s.jsxs("div",{className:"ms-activity-foot",children:[s.jsx("span",{className:"ms-activity-today",children:e===null?n.todayUnknown:n.today({count:ia(a,e)})}),s.jsx("a",{className:"ms-activity-usage",href:es.settings("usage"),children:n.open})]})}function Xg(e){const t=i.useContext(Mn);if(e.kind!=="creative")return"";if(e.variant)return` · ${e.variant.toUpperCase()}`;const n=Ba(e),a=n?.creative?_0(n.creative,t?.catalog.creatives[n.project]):null;return a?` · ${a.toUpperCase()}`:""}function kf({job:e,step:t,tokens:n,partial:a,events:r,helpers:l,child:o}){const c=V(),d=Xg(e),m=e.state==="queued",u=e.kind==="creative-group"&&e.groupPhase&&!m?c.web.shell.activity.groupPhases[e.groupPhase]:null;return s.jsxs(vc,{job:e,className:le("ms-tall",o&&"ms-activity-child"),nested:l,after:s.jsxs(s.Fragment,{children:[e.kind==="console"&&e.state==="running"?s.jsx(gS,{job:e,events:r}):null,s.jsx(rm,{job:e,className:"ms-activity-cancel"})]}),children:[s.jsx("span",{className:le("ms-activity-glyph",m&&"ms-muted"),children:m?s.jsx(F,{name:"clock",size:14}):s.jsx(Ts,{decorative:!0})}),s.jsxs("span",{className:"ms-activity-text",children:[s.jsx("b",{children:o?d.replace(/^ /,""):`${e.label}${d}`}),s.jsx("span",{className:"ms-activity-sub",children:m?e.waitReason?c.web.variantGroup.waitReasons[e.waitReason]:c.web.shell.activity.queued:t??u??c.web.jobState.running})]}),s.jsx(ar,{tokens:n,live:!0,partial:a,className:"ms-activity-tokens"})]})}function gS({job:e,events:t}){const n=V().web.liveUi,[a,r]=i.useState(!1),[l,o]=i.useState(null),c=i.useRef(null),d=i.useRef(null),m=i.useRef(!1);return m.current=a,i.useEffect(()=>{if(!a)return;o(null),d.current=c.current?.closest('[role="tabpanel"]')??null;let u=!0;return Promise.resolve().then(()=>q.getAgentCapabilities()).then(h=>{u&&o(h?.liveInput===!0)}).catch(()=>{u&&o(!1)}),()=>{u=!1}},[a]),i.useEffect(()=>()=>{if(!m.current)return;const u=document.activeElement;(!u||u===document.body)&&d.current?.focus({preventScroll:!0})},[]),s.jsxs(s.Fragment,{children:[s.jsx($,{ref:c,size:"sm",variant:"ghost","aria-haspopup":"dialog","aria-expanded":a,onClick:()=>r(u=>!u),children:n.consoleOpen}),s.jsx(ot,{open:a,onClose:()=>r(!1),anchor:c,placement:"bottom-end",width:320,label:n.consoleMessage,children:s.jsx(YN,{jobId:e.id,liveInput:l,events:t})})]})}function vS({job:e,made:t,failure:n,tokens:a,partial:r}){const l=V(),o=Xg(e),c=l.web.shell.activity,d=rs(),m=e.state==="succeeded",u=l.web.jobState[e.state],f=(m&&e.kind==="export"&&e.export?.files?l.web.exportUi.doneRow({count:e.export.files.length,folder:e.export.destination}):null)??(t?"group"in t?kg(l,t.group):"kept"in t?c.versionKept({n:t.n}):t.status==="complete"?c.versionReady({n:t.n}):c.versionIncomplete({n:t.n}):n?`${u} · ${n}`:m&&e.notes?.length?e.notes[0]:u),x=m?[]:s0(e.notes??[]);return s.jsxs(vc,{job:e,after:x.length>0?s.jsx(im,{className:"ms-activity-details",problems:x}):void 0,children:[s.jsx("span",{className:le("ms-activity-mark",m?"ms-ok":"ms-warn"),children:s.jsx(F,{name:m?"check":"warn",size:11,strokeWidth:2})}),s.jsxs("span",{className:"ms-activity-text ms-line",children:[s.jsxs("b",{children:[e.label,o]}),s.jsx("span",{className:"ms-activity-sub",children:f})]}),s.jsxs("span",{className:"ms-activity-side",children:[s.jsx("time",{className:"ms-activity-time",dateTime:qo(e),children:ca(d,qo(e),Wr)}),s.jsx(ar,{tokens:a,partial:r,className:"ms-activity-tokens"})]})]})}const bS=2500,jS=250,yS=new Set(["video-long","transcription-choice"]),wS=2e3,td=(e,t)=>`${e}:${t.jobId??""}:${t.pending?.kind??""}:${t.file}`,kS=e=>`subtitles:${e.slug}:${e.creative}:${e.jobId}`,NS={claim:()=>()=>{},dismiss:()=>{},park:()=>{}},SS=()=>location.hash.startsWith("#/settings"),Zg=i.createContext(NS),Jg=()=>i.useContext(Zg),CS=new Set(["text","search","email","url","tel","password","number",""]);function ES(){const e=document.activeElement;return e instanceof HTMLElement?e.isContentEditable||e.tagName==="TEXTAREA"?!0:e.tagName==="INPUT"&&CS.has(e.type):!1}function TS({slug:e,live:t,onViews:n}){const{byFile:a}=Xu(e,t);return i.useEffect(()=>{n(e,a)},[e,a,n]),i.useEffect(()=>()=>n(e,null),[e,n]),null}function RS({hold:e,tick:t,watch:n,onQuestion:a}){const{slug:r,creative:l,job:o}=e,c=`${r}/${l}`,[d,m]=i.useState(null);i.useEffect(()=>{let p=!0;return Promise.resolve().then(()=>q.getCreative(r,l)).then(g=>{p&&m(g.creative.title)},()=>{p&&m(l)}),()=>{p=!1}},[r,l]);const[u,h]=i.useState(null),[f,x]=i.useState(0);return i.useEffect(()=>{let p=!0;return Promise.resolve().then(()=>q.subtitles(r,l)).then(g=>{p&&h(g.pending)},()=>{}),()=>{p=!1}},[r,l,o,t,f]),i.useEffect(()=>{if(!n)return;const p=window.setInterval(()=>x(g=>g+1),wS);return()=>window.clearInterval(p)},[n]),i.useEffect(()=>{a(c,d!==null&&u?{slug:r,creative:l,title:d,jobId:o.id,pending:u}:null)},[c,r,l,d,u,o.id,a]),i.useEffect(()=>()=>a(c,null),[c,a]),null}function MS({live:e,enabled:t=!0,children:n}){const a=i.useMemo(()=>{const A=new Set;if(!t)return[];for(const L of Object.values(e.jobs)){if(L.kind!=="video-analysis"||L.state!=="queued"||!L.waitReason||!yS.has(L.waitReason))continue;const _=Ba(L);_&&A.add(_.project)}return[...A].sort()},[e.jobs,t]),r=i.useMemo(()=>{if(!t)return[];const A=[];for(const L of Object.values(e.jobs)){if(L.kind!=="subtitles"||L.state!=="queued"||L.waitReason!=="transcription-choice")continue;const _=Ba(L);_?.creative&&A.push({slug:_.project,creative:_.creative,job:L})}return A.sort((L,_)=>`${L.slug}/${L.creative}`.localeCompare(`${_.slug}/${_.creative}`))},[e.jobs,t]),[l,o]=i.useState({}),c=i.useCallback((A,L)=>{o(_=>{if(L===null){if(!(A in _))return _;const{[A]:X,...ae}=_;return ae}return _[A]===L?_:{..._,[A]:L}})},[]),[d,m]=i.useState({}),u=i.useCallback((A,L)=>{m(_=>{if(L===null){if(!(A in _))return _;const{[A]:X,...ae}=_;return ae}return _[A]===L?_:{..._,[A]:L}})},[]),[h,f]=i.useState(()=>new Set),[x,p]=i.useState([]),g=i.useRef(0),[b,v]=i.useState(()=>new Set),y=i.useCallback(A=>v(L=>new Set([...L,A])),[]);i.useEffect(()=>{const A=()=>{SS()||v(L=>L.size===0?L:new Set)};return addEventListener("hashchange",A),()=>removeEventListener("hashchange",A)},[]);const w=i.useMemo(()=>({claim:(A,L)=>{const _=++g.current;return p(X=>[...X,{id:_,slug:A,files:L}]),()=>p(X=>X.filter(ae=>ae.id!==_))},dismiss:(A,L)=>{L.pending&&f(_=>new Set([..._,td(A,L)]))},park:(A,L)=>{L.pending&&y(td(A,L))}}),[y]),j=i.useMemo(()=>[...a.flatMap(A=>Object.values(d[A]??{}).filter(L=>L.pending!==null).map(L=>({kind:"analysis",slug:A,file:L.file,view:L,key:td(A,L)}))),...r.flatMap(A=>{const L=l[`${A.slug}/${A.creative}`];return L&&L.jobId===A.job.id?[{kind:"subtitles",slug:A.slug,file:null,sub:L,key:kS(L)}]:[]})],[a,d,r,l]),S=(A,L)=>L!==null&&x.some(_=>_.slug===A&&_.files.includes(L)),k=j.find(A=>!h.has(A.key)&&!b.has(A.key)&&!S(A.slug,A.file))??null,E=i.useRef(S);E.current=S;const[N,C]=i.useState(null),R=i.useRef(0);i.useEffect(()=>{const A=()=>{R.current=Date.now()};return document.addEventListener("keydown",A,!0),()=>document.removeEventListener("keydown",A,!0)},[]);const P=k?.key??null;i.useEffect(()=>{if(N!==null||k===null)return;const A={key:k.key,slug:k.slug,file:k.file,...k.kind==="subtitles"?{sub:k.sub}:{}},L=()=>E.current(A.slug,A.file)?!0:Jx()||ES()&&Date.now()-R.current<bS?!1:(C(A),!0);if(L())return;const _=window.setInterval(()=>{L()&&window.clearInterval(_)},jS);return()=>window.clearInterval(_)},[N,P]);const z=N!==null&&j.some(A=>A.key===N.key);i.useEffect(()=>{N!==null&&!z&&C(null)},[N,z]);const O=N!==null&&S(N.slug,N.file);i.useEffect(()=>{O&&C(null)},[O]);const[T,W]=i.useState(null);i.useEffect(()=>{N!==null&&W(N)},[N]);const Z=A=>{f(L=>new Set([...L,A])),C(L=>L?.key===A?null:L)};return s.jsxs(Zg.Provider,{value:w,children:[n,a.map(A=>s.jsx(TS,{slug:A,live:e,onViews:u},A)),r.map(A=>s.jsx(RS,{hold:A,tick:e.creativeTicks[`${A.slug}/${A.creative}`]??0,onQuestion:c,watch:N!==null&&N.sub?.slug===A.slug&&N.sub.creative===A.creative},`${A.slug}/${A.creative}`)),T?.sub?s.jsx(kN,{question:l[`${T.sub.slug}/${T.sub.creative}`]??T.sub,open:N?.key===T.key,onClose:()=>Z(T.key),onSettings:()=>{y(T.key),C(A=>A?.key===T.key?null:A)}},T.key):T&&T.file!==null?s.jsx(wg,{slug:T.slug,view:d[T.slug]?.[T.file]??null,open:N?.key===T.key,onClose:()=>Z(T.key),onSettings:()=>{y(T.key),C(A=>A?.key===T.key?null:A)}},T.key):null]})}const $S={none:"neutral",queued:"neutral",running:"neutral",waiting:"warn",ready:"ok",stale:"warn",error:"warn"};function FS({slug:e,view:t,waitReason:n,onSeek:a,onView:r}){const l=V(),o=l.videoAnalysis,[c,d]=i.useState(!1),[m,u]=i.useState(!1),[h,f]=i.useState(null),[x,p]=i.useState(!1),g=Jg();i.useEffect(()=>{x&&!t.pending&&p(!1)},[x,t.pending]);const b=t.header?.edited===!0,v=C=>Pe.show(o.actionFailed({detail:pe(C)})),y=async C=>{d(!0);try{const R=await C();return R&&r?.(R),!0}catch(R){return v(R),!1}finally{d(!1)}},w=async C=>{d(!0);try{const R=await q.analyzeVideo(e,t.file,C||void 0);r?.(R),u(!1)}catch(R){R instanceof lt&&R.code==="analysis-edited"?u(!0):v(R)}finally{d(!1)}},j=()=>b?u(!0):void w(!1),S=async()=>{h!==null&&await y(()=>q.saveAnalysisBody(e,t.file,h))&&f(null)},k=t.state==="queued"||t.state==="running",E=t.body!==null,N=t.state==="none"?o.hints.none:t.state==="queued"?n==="transcription-check"?o.hints.checkingAudio:o.hints.queued:t.state==="running"?o.hints.running:t.state==="stale"?b?o.hints.staleEdited:o.hints.stale:t.state==="waiting"&&t.pending?t.pending.kind==="long"?o.hints.long:o.hints.transcription:t.state==="error"?t.error:null;return s.jsxs("section",{className:"ms-ana","aria-label":o.section,children:[s.jsxs("div",{className:"ms-lib-row ms-ana-head",children:[s.jsx("span",{className:"ms-lib-label",children:o.section}),s.jsx(Qs,{tone:$S[t.state],spinner:k,dot:!k,children:o.states[t.state]}),b?s.jsx("span",{className:"ms-lib-faint ms-lib-small",children:o.edited}):null,s.jsxs("span",{className:"ms-ana-actions",children:[k?s.jsx($,{size:"sm",variant:"ghost",disabled:c,onClick:()=>{y(async()=>{await q.cancelVideoAnalysis(e,t.file)})},children:o.stop}):null,t.state==="waiting"&&t.pending?s.jsx($,{size:"sm",variant:"ink",onClick:()=>p(!0),children:o.answer}):null,t.state==="ready"?s.jsxs($,{size:"sm",variant:"outline",loading:c&&!m,disabled:c||h!==null,onClick:j,children:[s.jsx(F,{name:"refresh",size:12}),o.reanalyze]}):t.state==="none"||t.state==="error"||t.state==="stale"?s.jsxs($,{size:"sm",variant:"outline",loading:c&&!m,disabled:c||h!==null,onClick:()=>t.state==="stale"&&b?u(!0):void w(!1),children:[s.jsx(F,{name:"sparkle",size:12}),t.state==="none"?o.analyze:o.reanalyze]}):null,t.body!==null&&h===null&&!k?s.jsxs($,{size:"sm",variant:"ghost",disabled:c,onClick:()=>f(t.body??""),children:[s.jsx(F,{name:"edit",size:12}),o.edit]}):null]})]}),N?s.jsx("p",{className:t.state==="error"?"ms-ana-hint ms-ana-error":"ms-ana-hint",role:t.state==="error"?"alert":void 0,children:N}):null,m?s.jsxs("div",{className:"ms-ana-confirm",role:"group","aria-label":o.overwriteTitle,children:[s.jsx("b",{children:o.overwriteTitle}),s.jsx("p",{children:o.overwriteText}),s.jsxs("div",{className:"ms-ana-confirm-actions",children:[s.jsx($,{size:"sm",variant:"ghost",disabled:c,onClick:()=>u(!1),children:l.common.cancel}),s.jsx($,{size:"sm",variant:"danger",loading:c,onClick:()=>{w(!0)},children:o.overwrite})]})]}):null,h!==null?s.jsxs("div",{className:"ms-ana-editor",children:[s.jsx(nn,{rows:14,"aria-label":o.editLabel,value:h,onChange:C=>f(C.target.value)}),s.jsx("span",{className:"ms-lib-faint ms-lib-small",children:o.editHint}),s.jsxs("div",{className:"ms-ana-confirm-actions",children:[s.jsx($,{size:"sm",variant:"ghost",disabled:c,onClick:()=>f(null),children:l.common.cancel}),s.jsx($,{size:"sm",variant:"ink",loading:c,disabled:h===t.body,onClick:()=>{S()},children:l.common.save})]})]}):E?s.jsx(PS,{body:t.body,header:t.header,onSeek:a}):null,s.jsx(wg,{slug:e,view:t,open:x,onClose:()=>{g.dismiss(e,t),p(!1)},onSettings:()=>{g.park(e,t),p(!1)}})]})}function vl({title:e,children:t}){return s.jsxs("div",{className:"ms-ana-block",children:[s.jsx("span",{className:"ms-ana-title",children:e}),t]})}const Nf=(e,t)=>`${la(e)}–${la(t)}`;function PS({body:e,header:t,onSeek:n}){const r=V().videoAnalysis,l=i.useMemo(()=>wj(e),[e]);if(!l)return s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"ms-ana-hint",children:r.raw}),s.jsx("pre",{className:"ms-ana-raw",children:e})]});const o=(d,m,u,h)=>s.jsx("li",{children:s.jsx("button",{type:"button",className:"ms-ana-row","aria-label":`${r.seek({time:la(d)})} · ${m}`,onClick:()=>n(d),children:u})},h),c=t?t.hasAudio?t.transcript==="none-skipped"?r.noTranscript.skipped:t.transcript==="none-no-speech"?r.noTranscript.noSpeech:r.noTranscript.empty:r.noTranscript.noAudio:r.noTranscript.empty;return s.jsxs(s.Fragment,{children:[l.summary?s.jsx(vl,{title:r.summary,children:s.jsx("p",{className:"ms-ana-summary",children:l.summary})}):null,l.timeline.length?s.jsx(vl,{title:r.timeline,children:s.jsx("ul",{className:"ms-ana-list",children:l.timeline.map((d,m)=>o(d.from,d.onScreen,s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-ana-time",children:Nf(d.from,d.to)}),s.jsxs("span",{className:"ms-ana-text",children:[s.jsx("span",{children:d.onScreen}),d.onScreenText.length?s.jsxs("span",{className:"ms-ana-ost",children:[s.jsx("span",{className:"ms-ana-ost-label",children:r.onScreenText}),d.onScreenText.map((u,h)=>s.jsx("q",{children:u},h))]}):null,d.speech.map((u,h)=>s.jsxs("span",{className:"ms-ana-speech",children:[s.jsx("span",{className:"ms-ana-time",children:la(u.at)}),s.jsx("q",{children:u.text})]},h))]})]}),m))})}):null,l.usableMoments.length?s.jsx(vl,{title:r.moments,children:s.jsx("ul",{className:"ms-ana-list",children:l.usableMoments.map((d,m)=>o(d.from,d.why,s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-ana-time",children:Nf(d.from,d.to)}),s.jsx("span",{className:"ms-ana-text",children:d.why})]}),m))})}):null,s.jsx(vl,{title:r.transcript,children:l.transcript.length?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-lib-faint ms-lib-small",children:r.automatic}),s.jsx("ul",{className:"ms-ana-list",children:l.transcript.map((d,m)=>o(d.from,d.text,s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-ana-time",children:la(d.from)}),s.jsx("span",{className:"ms-ana-text",children:d.text})]}),m))})]}):s.jsx("span",{className:"ms-lib-muted",children:c})}),l.tags.length?s.jsx(vl,{title:r.tags,children:s.jsx("div",{className:"ms-adetail-tags",children:l.tags.map(d=>s.jsx(tn,{children:d},d))})}):null]})}function AS({small:e,className:t}){const n=V();return s.jsxs("span",{className:le("ms-nopreview",e&&"ms-sm",t),role:"img","aria-label":n.web.ui.noPreview,children:[s.jsx(F,{name:"image",size:e?14:18}),e?null:s.jsx("span",{children:n.web.ui.noPreview})]})}function li({small:e,fallbackClassName:t,onError:n,...a}){const[r,l]=i.useState(!1);return i.useEffect(()=>{l(!1)},[a.src]),r?s.jsx(AS,{small:e,className:t}):s.jsx("img",{...a,onError:o=>{l(!0),n?.(o)}})}function LS({src:e,alt:t,style:n}){const a={width:"100%",height:"100%",objectFit:"cover",display:"block",...n};return om(e)==="video"?s.jsx("video",{src:e,muted:!0,preload:"metadata","aria-label":t,style:a}):s.jsx(li,{src:e,alt:t,style:a})}function IS(e){return e.closest("[data-hover-play]")??e.parentElement??e}function Yg({src:e,video:t,onLoad:n}){const a=i.useRef(null),[r,l]=i.useState(!1);i.useEffect(()=>{const c=a.current;if(!c||!t)return;const d=IS(c),m=()=>{wr()||l(!0)},u=()=>l(!1),h=f=>{d.contains(f.relatedTarget)||u()};return d.addEventListener("pointerenter",m),d.addEventListener("pointerleave",u),d.addEventListener("focusin",m),d.addEventListener("focusout",h),()=>{d.removeEventListener("pointerenter",m),d.removeEventListener("pointerleave",u),d.removeEventListener("focusin",m),d.removeEventListener("focusout",h)}},[t]);const o=om(e)==="video";return s.jsxs("span",{ref:a,className:"ms-cover",children:[o?s.jsx("video",{src:e,muted:!0,preload:"metadata","aria-hidden":"true",onLoadedMetadata:n}):s.jsx(li,{src:e,alt:"",onLoad:n,small:!0,fallbackClassName:"ms-cover-none"}),r&&t?s.jsx(zS,{src:t}):null]})}function zS({src:e}){const t=i.useRef(null);return i.useEffect(()=>{const n=t.current;if(n){try{n.play()?.catch(()=>{})}catch{}return()=>{try{n.pause()}catch{}}}},[e]),s.jsx("video",{ref:t,className:"ms-cover-play",src:e,muted:!0,loop:!0,playsInline:!0,autoPlay:!0,preload:"auto","aria-hidden":"true"})}const Ai=new Map;let OS=0;function DS(e){let t=Ai.get(e);if(!t){const n=`ms-brand-font-${++OS}`;t=(async()=>{if(typeof FontFace>"u"||typeof document>"u"||!document.fonts)throw new Error("FontFace unavailable");const a=new FontFace(n,`url("${e.replace(/"/g,"%22")}")`);return await a.load(),document.fonts.add(a),n})(),t.catch(()=>{Ai.get(e)===t&&Ai.delete(e)}),Ai.set(e,t)}return t}function bc(e){const[t,n]=i.useState(e?{state:"loading"}:{state:"none"});return i.useEffect(()=>{if(!e){n({state:"none"});return}let a=!0;return n({state:"loading"}),DS(e).then(r=>{a&&n({state:"ready",family:r})},()=>{a&&n({state:"failed"})}),()=>{a=!1}},[e]),t}const jc=e=>e.state==="ready"?`"${e.family}", var(--sans)`:"var(--sans)";function bm({slug:e,asset:t,big:n}){const a=q.projectFileUrl(e,`assets/${t.file}`);if(t.kind==="image"||t.kind==="svg")return s.jsx("span",{className:le("ms-athumb",t.kind==="svg"&&"ms-athumb-svg",Fk(t)&&($k(t)?"ms-stage-dark":"ms-stage-light")),children:s.jsx(li,{src:a,alt:"",loading:"lazy",small:!n})});if(t.kind==="video")return s.jsxs("span",{className:"ms-athumb ms-athumb-video",children:[s.jsx(LS,{src:a,alt:""}),s.jsx("span",{className:"ms-athumb-play",children:s.jsx(F,{name:"play",size:n?14:11,fill:!0})})]});if(t.kind==="font")return s.jsx(BS,{url:a,name:On(t.file)});const r=(t.file.split(".").pop()??"").toUpperCase();return s.jsxs("span",{className:"ms-athumb ms-athumb-file",children:[s.jsx(F,{name:t.kind==="audio"?"play":"folder",size:18}),s.jsx("span",{children:r})]})}function BS({url:e,name:t}){const n=bc(e),a=jc(n);return s.jsxs("span",{className:"ms-athumb ms-athumb-font",style:{fontFamily:a},children:[s.jsx("span",{className:"ms-athumb-aa",children:"Aa"}),s.jsx("span",{className:"ms-athumb-sample",children:t.replace(/\.[a-z0-9]+$/i,"")})]})}function US({slug:e,asset:t,describing:n,busy:a,onClose:r,onSaved:l,onRenamed:o,onDescribe:c,onUse:d,onDelete:m,analysis:u,analysisWaitReason:h}){const f=V(),x=rs(),p=f.web.library.assets,g=p.detail,b=i.useRef(null);i.useLayoutEffect(()=>{Gs(b.current,{x:16,y:0})},[]);const[v,y]=i.useState(null),[w,j]=i.useState(t.tags),[S,k]=i.useState(""),[E,N]=i.useState(null),C=i.useRef(0),[R,P]=i.useState(null),[z,O]=i.useState(!1),[T,W]=i.useState(null),Z=i.useRef(null),[A,L]=i.useState(null);i.useEffect(()=>{L(null)},[u]);const _=A??u;i.useEffect(()=>{if(W(null),t.kind!=="audio")return;let Q=!0;return Promise.resolve().then(()=>q.assetWaveform(e,t.file)).then(Re=>{Q&&W(Re.peaks)}).catch(()=>{}),()=>{Q=!1}},[e,t.file,t.kind]);const X=t.tags.join(`
|
|
6
|
+
`);i.useEffect(()=>{C.current===0&&j(t.tags)},[X]),i.useEffect(()=>{v!==null&&v===t.description&&y(null)},[t.description]);const ae=Q=>Pe.show(g.saveFailed({detail:pe(Q)})),K=async()=>{if(!(v===null||v===t.description))try{l(await q.updateAsset(e,t.file,{description:v})),y(null),N("saved")}catch(Q){ae(Q)}},I=async Q=>{const Re=w;j(Q),C.current+=1;try{l(await q.updateAsset(e,t.file,{tags:Q})),N("saved")}catch(Ue){j(Re),ae(Ue)}finally{C.current-=1}},H=async()=>{const Q=(R??"").trim();if(!Q||Q===On(t.file)||z){P(null);return}O(!0);try{const Re=await q.updateAsset(e,t.file,{name:Q});Pe.show(g.renamed({name:On(Re.file)}),{tone:"ok"}),P(null),o(t.file,Re)}catch(Re){Pe.show(g.renameFailed({detail:pe(Re)}))}finally{O(!1)}},de=Q=>{Q.key==="Enter"?(Q.preventDefault(),H()):Q.key==="Escape"&&(Q.preventDefault(),Q.stopPropagation(),P(null))},J=()=>{const Q=pg(w,Po(S));k(""),Q.length!==w.length&&I(Q)},se=Q=>{Q.key==="Enter"||Q.key===","?(Q.preventDefault(),J()):Q.key==="Backspace"&&!S&&w.length&&(Q.preventDefault(),I(w.slice(0,-1)))},U=q.projectFileUrl(e,`assets/${t.file}`),[te,G]=i.useState(!1),re=i.useContext(Mn),oe=async()=>{G(!0);try{await q.updateProject(e,{icon:{asset:t.file}}),Pe.show(g.projectIconSet,{tone:"ok"}),re?.catalog.refresh()}catch(Q){Pe.show(g.projectIconFailed({detail:pe(Q)}))}finally{G(!1)}};let Ne=t.sourceUrl??"";try{t.sourceUrl&&(Ne=new URL(t.sourceUrl).hostname)}catch{}return s.jsxs("aside",{ref:b,className:"ms-adetail","aria-label":g.label,children:[s.jsxs("div",{className:"ms-adetail-head",children:[s.jsx("b",{className:"ms-adetail-name",title:t.file,children:On(t.file)}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":g.rename,title:g.rename,"aria-expanded":R!==null,onClick:()=>P(R===null?On(t.file):null),children:s.jsx(F,{name:"edit",size:12})}),E==="saved"?s.jsx("span",{className:"ms-adetail-saved",role:"status",children:g.saved}):null,s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":g.close,onClick:r,children:s.jsx(F,{name:"close",size:12})})]}),s.jsxs("div",{className:"ms-adetail-body",children:[R!==null?s.jsxs("form",{className:"ms-adetail-rename",onSubmit:Q=>{Q.preventDefault(),H()},children:[s.jsx(ms,{autoFocus:!0,value:R,"aria-label":g.renameLabel,onChange:Q=>P(Q.target.value),onKeyDown:de}),s.jsx($,{type:"submit",size:"sm",variant:"ink",loading:z,disabled:!R.trim(),children:g.renameApply}),s.jsx($,{type:"button",size:"sm",variant:"ghost",onClick:()=>P(null),children:g.renameCancel}),s.jsx("span",{className:"ms-lib-faint ms-lib-small",children:g.renameHint})]}):null,s.jsx("div",{className:le("ms-adetail-media",(t.kind==="video"||t.kind==="audio")&&"ms-adetail-player",t.kind==="video"&&"ms-adetail-sticky"),children:t.kind==="video"?s.jsx(Yw,{src:U,name:On(t.file),durationSec:t.durationSec,handle:Z}):t.kind==="audio"?s.jsx(Jw,{src:U,name:On(t.file),peaks:T,durationSec:t.durationSec}):s.jsx(bm,{slug:e,asset:t,big:!0})}),t.kind==="video"&&_?s.jsx(FS,{slug:e,view:_,waitReason:h,onSeek:Q=>Z.current?.seek(Q),onView:L}):null,s.jsxs("div",{className:"ms-adetail-field",children:[s.jsxs("div",{className:"ms-lib-row",children:[s.jsx("span",{className:"ms-lib-label",children:g.description}),s.jsx("span",{className:"ms-lib-faint ms-lib-small",children:g.descriptionHint}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,className:"ms-lib-push","aria-label":p.describeAgain,title:a?p.describeBusy:p.describeAgain,disabled:a,onClick:c,children:s.jsx(F,{name:"refresh",size:12})})]}),n?s.jsxs("div",{className:"ms-adetail-looking",children:[s.jsx(Bu,{}),g.looking]}):s.jsx(nn,{rows:5,"aria-label":g.description,placeholder:g.descriptionPlaceholder,value:v??t.description,onChange:Q=>{y(Q.target.value),N(null)},onBlur:()=>{K()}})]}),s.jsxs("div",{className:"ms-adetail-field",children:[s.jsx("span",{className:"ms-lib-label",children:g.tags}),s.jsxs("div",{className:"ms-adetail-tags",children:[w.map(Q=>s.jsxs("span",{className:"ms-adetail-tag",children:[Q,s.jsx("button",{type:"button","aria-label":g.removeTag({tag:Q}),onClick:()=>{I(w.filter(Re=>Re!==Q))},children:s.jsx(F,{name:"close",size:9})})]},Q)),w.length<hg?s.jsx("input",{className:"ms-adetail-tagin",value:S,maxLength:fg*3,"aria-label":g.addTag,placeholder:g.addTagPlaceholder,title:g.tagRules,onChange:Q=>k(Q.target.value),onKeyDown:se,onBlur:()=>{S.trim()&&J()}}):null]})]}),s.jsxs("dl",{className:"ms-adetail-meta",children:[s.jsx("dt",{children:g.file}),s.jsx("dd",{className:"ms-lib-mono",children:t.file}),t.width&&t.height?s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:g.size}),s.jsxs("dd",{children:[t.width,"×",t.height]})]}):null,t.durationSec?s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:g.duration}),s.jsx("dd",{children:la(t.durationSec)})]}):null,t.bytes!==void 0?s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:g.fileSize}),s.jsx("dd",{children:Ku(t.bytes,Q=>Vs(x,Q))})]}):null,s.jsx("dt",{children:g.added}),s.jsxs("dd",{children:[p.origins[t.origin]," · ",$u(x,t.addedAt)]}),t.sourceUrl?s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:g.source}),s.jsx("dd",{children:s.jsx("a",{href:t.sourceUrl,target:"_blank",rel:Ox(),title:t.sourceUrl,children:Ne})})]}):null,t.attribution?s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:g.credit}),s.jsx("dd",{children:t.attribution})]}):null]}),t.kind==="image"||t.kind==="svg"?s.jsxs($,{variant:"outline",loading:te,onClick:()=>{oe()},children:[s.jsx(F,{name:"image",size:13}),g.useAsProjectIcon]}):null,s.jsxs("div",{className:"ms-lib-row",children:[s.jsx($,{variant:"ink",className:"ms-grow",onClick:d,children:p.useInCreative}),s.jsx($,{variant:"danger",icon:!0,"aria-label":g.delete,title:g.delete,onClick:m,children:s.jsx(F,{name:"trash",size:14})})]})]})]})}const rr={kind:"manual",ref:null};function _S(e){let t=null,n="";for(const a of e){if(t){a===t?t=null:n+=a;continue}if(a==='"'||a==="'"){t=a;continue}if(a===",")break;n+=a}return n.replace(/\s+/g," ").trim()}function nd(e){const t=e.trim().replace(/^#/,"");return/^[0-9a-fA-F]{3}$/.test(t)?`#${[...t].map(n=>n+n).join("").toUpperCase()}`:/^[0-9a-fA-F]{6}$/.test(t)?`#${t.toUpperCase()}`:null}function Ir(e){const t=Number.parseInt(e.slice(1),16),n=[t>>16&255,t>>8&255,t&255].map(a=>{const r=a/255;return r<=.03928?r/12.92:((r+.055)/1.055)**2.4});return .2126*n[0]+.7152*n[1]+.0722*n[2]}function ad(e,t){const[n,a]=[Ir(e),Ir(t)].sort((r,l)=>l-r);return(n+.05)/(a+.05)}const Sf="#FFFFFF",Cf="#000000";function qS(e,t){let n=null;for(const l of t){if(l.hex.toUpperCase()===e.toUpperCase())continue;const o=ad(e,l.hex);(!n||o>n.ratio)&&(n={color:l.hex,name:l.name,ratio:o})}if(n&&n.ratio>=4.5)return n;const a=ad(e,Sf),r=ad(e,Cf);return a>=r?{color:Sf,name:null,ratio:a}:{color:Cf,name:null,ratio:r}}const Ef=e=>String(Math.round(e*10)/10);function jm(e,t){if(!t.length)return null;const n=[...t].sort((r,l)=>Ir(r.hex)-Ir(l.hex));if(e==="dark"){const r=n[0];return Ir(r.hex)<.08?r.hex:null}const a=n[n.length-1];return Ir(a.hex)>.6?a.hex:null}const Qg=(e,t)=>e.logos.some(n=>n.background===t||n.background==="any");function VS(e){return[{id:"palette",ok:e.colors.some(t=>t.role!=="other")},{id:"fonts",ok:e.fonts.length>0&&e.fonts.every(t=>t.file!==null)},{id:"rules",ok:e.dos.length>0&&e.donts.length>0},{id:"lightLogo",ok:Qg(e,"light")}]}const KS=e=>!!(e&&(e.genre.trim()||e.energy||e.instruments.length||e.avoid.length||e.voice)),WS=e=>!e.colors.length&&!e.fonts.length&&!e.logos.length&&!e.dos.length&&!e.donts.length&&!e.tone&&!e.photoStyle&&!KS(e.sound);function HS(e,t){return!e.kitError&&WS(e.kit)&&!e.guidelines.trim()&&e.sources.length===0&&e.proposals.length===0&&!t}function GS(e,t){return Object.values(e).filter(n=>n.key===t).sort((n,a)=>a.createdAt.localeCompare(n.createdAt))[0]}function XS(e){const t=[];for(const n of e??[])n.kind==="progress"&&n.text&&n.text!==t[t.length-1]&&t.push(n.text);return t}function ZS(e){let t=null;for(const a of e??[])a.kind==="progress"&&a.phase&&_c.includes(a.phase)&&(t=a.phase);if(t===null)return null;const n=_c.indexOf(t);return _c.map((a,r)=>({phase:a,state:r<n||t==="done"?"done":r===n?"current":"pending"}))}function yc(e){if(!e)return"";try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function ev(e){const t=e.trim();if(!t||/\s/.test(t))return null;const n=/^[a-z][a-z0-9+.-]*:/i.test(t)?t:`https://${t}`;try{const a=new URL(n);return a.protocol!=="http:"&&a.protocol!=="https:"||!a.hostname.includes(".")&&a.hostname!=="localhost"?null:n}catch{return null}}const sv=(e,t)=>[...new Set(e.filter(n=>n.kind==="website"&&(!t||t.includes(n.id))).map(n=>yc(n.url)).filter(Boolean))],wc=(e,t)=>{for(let n=1;;n++)if(!t.includes(`${e}-${n}`))return`${e}-${n}`};function JS(e){const t=[...new Set(e.split(/[\s,·]+/).filter(Boolean).map(Number).filter(n=>Number.isInteger(n)&&n>=100&&n<=900))].sort((n,a)=>n-a).slice(0,9);return t.length?t:null}const tv=e=>e==="tone"||e==="photoStyle",nv=(e,t)=>e[t];function YS(e,t){const n=structuredClone(e);for(const a of t){if(tv(a.field)){n[a.field]=a.op==="remove"?null:a.after;continue}const r=[...nv(n,a.field)];if(a.op==="remove"){r.find(o=>o.id===a.itemId)?.source?.kind!=="manual"&&(n[a.field]=r.filter(o=>o.id!==a.itemId));continue}const l=r.findIndex(o=>o.id===a.itemId);l>=0?r[l]=a.after:r.push(a.after),n[a.field]=r}return n}function QS(e,t){const n=structuredClone(e),a=(r,l)=>{n[r]=l};for(const r of[...t].reverse()){if(tv(r.field)){const c=n[r.field],d=r.op==="remove"?null:r.after;(c?.text??null)===(d?.text??null)&&a(r.field,r.before??null);continue}const l=[...nv(n,r.field)],o=l.findIndex(c=>c.id===r.itemId);r.op==="add"?o>=0&&l.splice(o,1):r.op==="update"?o>=0&&(l[o]=r.before):o<0&&r.before&&l.push(r.before),a(r.field,l)}return n}const e1=nc.map(e=>al(e).brand.droppedPrefix({list:""}));function av(e){const t=e.split(/\n\s*\n/),n=[];return{text:t.filter(r=>{const l=r.trim(),o=e1.find(c=>l.startsWith(c));return o?(n.push(...l.slice(o.length).split("; ").map(c=>c.trim()).filter(Boolean)),!1):!0}).join(`
|
|
7
|
+
|
|
8
|
+
`).trim(),details:n}}const rv=["cinematic","electronic","acoustic","hiphop","corporate","ambient","jazz","pop"],ym={cinematic:"cinematic",electronic:"electronic",acoustic:"acoustic",hiphop:"hip hop",corporate:"corporate",ambient:"ambient",jazz:"jazz",pop:"pop"};function nu(e){const t=e.trim().toLowerCase();if(!t)return null;for(const n of rv)if(ym[n]===t||nc.some(a=>al(a).web.brand.sound.genreOptions[n].toLowerCase()===t))return n;return null}function s1(e){const t=nu(e);return t?ym[t]:e.trim()}function wm(e){const t=e.split(/[\\/]+/).filter(Boolean);return t[t.length-1]??e}const rd=["image","voice","sfx","music"],t1={image:"image",voice:"volume",sfx:"volume",music:"music"},Li={image:["openai"],voice:["openai","elevenlabs"],sfx:["elevenlabs"],music:["elevenlabs"]},n1={"image/openai":"gpt-image-2","voice/openai":"gpt-4o-mini-tts","voice/elevenlabs":"eleven_multilingual_v2","sfx/elevenlabs":"eleven_text_to_sound_v2","music/elevenlabs":"music_v1"},bl={min:.5,max:30},jl={min:10,max:300};function Tf(e){return e?[s1(e.genre),e.energy?`${e.energy} energy`:"",e.instruments.length?`instruments: ${e.instruments.join(", ")}`:"",e.avoid.length?`avoid: ${e.avoid.join(", ")}`:""].filter(Boolean).join(", "):""}function a1(e,t){return t.voice&&t.voice.provider===e?t.voice.id:""}function r1(e){const t=V().web.library.generate;return s.jsx(rt,{open:e.open,onClose:e.onClose,label:t.title,width:640,children:e.open?s.jsx(l1,{...e}):null})}function l1({onClose:e,slug:t,live:n}){const r=V().web.library.generate,[l,o]=i.useState(null),[c,d]=i.useState(yo),[m,u]=i.useState("image"),[h,f]=i.useState({image:"openai",voice:"openai",sfx:"elevenlabs",music:"elevenlabs"}),[x,p]=i.useState({image:"",sfx:"",music:""}),[g,b]=i.useState(""),[v,y]=i.useState({width:1024,height:1024}),[w,j]=i.useState("auto"),[S,k]=i.useState(""),[E,N]=i.useState(""),[C,R]=i.useState("mp3"),[P,z]=i.useState(null),[O,T]=i.useState(30),[W,Z]=i.useState(!1),[A,L]=i.useState(!1),[_,X]=i.useState(""),[ae,K]=i.useState(null),[I,H]=i.useState(null),[de,J]=i.useState(!1);i.useEffect(()=>{let je=!0;return Promise.resolve().then(()=>q.getSecrets()).then(he=>{je&&o(he)}).catch(()=>{je&&o([])}),Promise.resolve().then(()=>q.getBrand(t)).then(he=>{if(!je)return;const Ke=he.kit.sound??yo;d(Ke);const we=Tf(Ke);p(ze=>({...ze,music:ze.music||we,sfx:ze.sfx})),Ke.voice&&(f(ze=>({...ze,voice:Ke.voice.provider})),k(Ke.voice.id))}).catch(()=>{}),()=>{je=!1}},[t]);const se=i.useRef(h.voice);i.useEffect(()=>{se.current!==h.voice&&(se.current=h.voice,k(a1(h.voice,c)))},[h.voice]);const U=je=>!!l?.find(he=>he.provider===je)?.configured,te=je=>Li[je].some(U),G=rd.map(je=>({value:je,label:r.kinds[je],disabled:l!==null&&!te(je)}));i.useEffect(()=>{if(l!==null){if(!te(m)){const je=rd.find(te);je&&u(je)}f(je=>({...je,voice:U(je.voice)?je.voice:U("openai")?"openai":"elevenlabs"}))}},[l]);const re=I?n.jobs[I]:void 0,oe=I?Object.values(n.approvals).filter(je=>je.jobId===I):[],Ne=de||!!(I&&(!re||_r(re))),[Q,Re]=i.useState(null);i.useEffect(()=>{!re||_r(re)||Q===re.id||(Re(re.id),re.state==="succeeded"?(Pe.show(r.done,{tone:"ok"}),e()):re.state==="failed"?(K(r.failed({error:re.error??"—"})),H(null)):(K(r.cancelled),H(null)))},[re]);const Ue=r.providerNames,is=h[m],Qe=l!==null&&!l.some(je=>je.configured),gs=i.useMemo(()=>[...new Set(rd.filter(je=>l!==null&&!te(je)).flatMap(je=>Li[je]))].map(je=>Ue[je]).join(", "),[l]),As=()=>{const je=_.trim()||void 0;if(m==="image")return x.image.trim()?!v.width||!v.height?r.errors.size:{kind:m,provider:"openai",prompt:x.image,options:{width:v.width,height:v.height,quality:w,...je?{name:je}:{}}}:r.errors.promptRequired;if(m==="voice"){if(!g.trim())return r.errors.textRequired;const he=S.trim();return{kind:m,provider:h.voice,text:g,options:{...he?{voice:he}:{},...E.trim()&&h.voice==="openai"?{instructions:E.trim()}:{},format:C,...je?{name:je}:{}}}}return m==="sfx"?x.sfx.trim()?P!==null&&(P<bl.min||P>bl.max)?r.errors.duration(bl):{kind:m,provider:"elevenlabs",prompt:x.sfx,options:{...P!==null?{durationSec:P}:{},...W?{loop:W}:{},...je?{name:je}:{}}}:r.errors.promptRequired:x.music.trim()?O===null||O<jl.min||O>jl.max?r.errors.duration(jl):{kind:m,provider:"elevenlabs",prompt:x.music,options:{durationSec:O,...A?{instrumental:A}:{},...je?{name:je}:{}}}:r.errors.promptRequired},hs=async()=>{const je=As();if(typeof je=="string"){K(je);return}K(null),J(!0);try{H((await q.generateAsset(t,je)).jobId)}catch(he){K(pe(he))}finally{J(!1)}},Oe=()=>{I&&q.cancelJob(I).catch(()=>{})},be=`ms-gen-panel-${m}`,Fe=l!==null&&!te(m);return s.jsxs("div",{className:"ms-gen",children:[s.jsxs("header",{className:"ms-gen-head",children:[s.jsx("h2",{children:r.title}),s.jsx($,{size:"sm",variant:"ghost",onClick:e,children:r.close})]}),s.jsx(hc,{label:r.tabs,tabs:G.map(je=>({...je,controls:`ms-gen-panel-${je.value}`})),value:m,onChange:je=>{Ne||(u(je),K(null))}}),l!==null&&gs?s.jsxs("p",{className:"ms-gen-note",role:"status",children:[Qe?r.noKeysAtAll:r.noKeyTitle({providers:gs})," ",s.jsx("a",{href:es.settings("paid"),onClick:e,children:r.openSettings})]}):null,s.jsx("div",{id:be,role:"tabpanel",className:"ms-gen-body","aria-busy":Ne,children:Fe?null:s.jsxs("fieldset",{className:"ms-gen-fields",disabled:Ne,children:[Li[m].length>1?s.jsxs("div",{className:"ms-gen-row",children:[s.jsx("span",{className:"ms-gen-label",children:r.providerLabel}),s.jsx(At,{label:r.providerLabel,value:is,onChange:je=>f(he=>({...he,[m]:je})),options:Li[m].map(je=>({value:je,label:Ue[je],disabled:!U(je)}))})]}):null,s.jsx("p",{className:"ms-gen-note",children:r.providerLine({provider:Ue[is],model:n1[`${m}/${is}`]})}),m==="voice"?s.jsxs(s.Fragment,{children:[s.jsx("label",{className:"ms-gen-label",htmlFor:"ms-gen-text",children:r.text}),s.jsx(nn,{id:"ms-gen-text",rows:4,value:g,placeholder:r.textPlaceholder,maxLength:is==="openai"?4096:5e3,onChange:je=>b(je.target.value)}),s.jsx("label",{className:"ms-gen-label",htmlFor:"ms-gen-voice",children:r.voiceId}),s.jsx(ms,{id:"ms-gen-voice",value:S,placeholder:r.voicePlaceholder,maxLength:64,onChange:je=>k(je.target.value)}),c.voice&&c.voice.provider===is?s.jsx("p",{className:"ms-gen-note",children:r.brandVoice({name:c.voice.name??c.voice.id})}):null,is==="openai"?s.jsxs(s.Fragment,{children:[s.jsx("label",{className:"ms-gen-label",htmlFor:"ms-gen-instr",children:r.instructions}),s.jsx(ms,{id:"ms-gen-instr",value:E,placeholder:r.instructionsPlaceholder,maxLength:1e3,onChange:je=>N(je.target.value)})]}):null,s.jsxs("div",{className:"ms-gen-row",children:[s.jsx("span",{className:"ms-gen-label",children:r.format}),s.jsx(it,{label:r.format,value:C,onChange:R,options:[{value:"mp3",label:"MP3"},{value:"wav",label:"WAV"}]})]})]}):s.jsxs(s.Fragment,{children:[s.jsx("label",{className:"ms-gen-label",htmlFor:"ms-gen-prompt",children:r.prompt}),s.jsx(nn,{id:"ms-gen-prompt",rows:4,value:x[m],maxLength:m==="image"?32e3:1e3,placeholder:m==="image"?r.imagePlaceholder:m==="sfx"?r.soundPlaceholder:r.musicPlaceholder,onChange:je=>p(he=>({...he,[m]:je.target.value}))}),m==="music"&&Tf(c)?s.jsx("p",{className:"ms-gen-note",children:r.brandStyle}):null]}),m==="image"?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ms-gen-row",children:[s.jsx(Tt,{label:r.width,prefix:"W",unit:"px",min:64,max:3840,step:64,decimals:0,value:v.width,onChange:je=>y(he=>({...he,width:je}))}),s.jsx(Tt,{label:r.height,prefix:"H",unit:"px",min:64,max:3840,step:64,decimals:0,value:v.height,onChange:je=>y(he=>({...he,height:je}))})]}),s.jsx("p",{className:"ms-gen-note",children:r.sizeNote}),s.jsxs("div",{className:"ms-gen-row",children:[s.jsx("span",{className:"ms-gen-label",children:r.quality}),s.jsx(it,{label:r.quality,value:w,onChange:j,options:["auto","low","medium","high"].map(je=>({value:je,label:r.qualities[je]}))})]})]}):null,m==="sfx"?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ms-gen-row",children:[s.jsx(Tt,{label:r.duration,prefix:"DUR",unit:r.seconds,min:bl.min,max:bl.max,step:.5,decimals:1,value:P,startAt:2,onChange:z}),s.jsxs("span",{className:"ms-gen-inline",children:[s.jsx(Un,{size:"sm",on:W,onChange:Z,label:r.loop})," ",r.loop]})]}),s.jsx("p",{className:"ms-gen-note",children:r.sfxLimits})]}):null,m==="music"?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ms-gen-row",children:[s.jsx(Tt,{label:r.duration,prefix:"DUR",unit:r.seconds,min:jl.min,max:jl.max,step:5,decimals:0,value:O,startAt:30,onChange:T}),s.jsxs("span",{className:"ms-gen-inline",children:[s.jsx(Un,{size:"sm",on:A,onChange:L,label:r.instrumental})," ",r.instrumental]})]}),s.jsx("p",{className:"ms-gen-note",children:r.musicLimits})]}):null,s.jsx("label",{className:"ms-gen-label",htmlFor:"ms-gen-name",children:r.name}),s.jsx(ms,{id:"ms-gen-name",value:_,placeholder:r.namePlaceholder,maxLength:60,onChange:je=>X(je.target.value)})]})}),s.jsxs("p",{className:"ms-gen-note",children:[s.jsx(F,{name:t1[m],size:12})," ",r.paidNote]}),oe.map(je=>s.jsx("div",{className:"ms-gen-approval",children:s.jsx(ri,{approval:je})},je.id)),ae?s.jsx(oa,{children:ae}):null,s.jsxs("footer",{className:"ms-gen-foot",children:[Ne?s.jsxs("span",{className:"ms-gen-running",role:"status",children:[s.jsx(Ts,{size:14})," ",I?r.running:r.starting]}):null,s.jsx("div",{className:"ms-grow"}),I&&Ne?s.jsx($,{variant:"outline",onClick:Oe,children:r.stop}):s.jsx($,{variant:"outline",onClick:e,children:r.cancel}),s.jsx($,{variant:"ink",loading:de,disabled:Ne||Fe||l===null,onClick:()=>{hs()},children:r.submit})]})]})}const i1=["website","upload","generated","stock","google-fonts","codebase"],ld=e=>Array.from(e.dataTransfer?.types??[]).includes("Files");function o1(e,t,n){const a=Object.values(e).sort((r,l)=>l.createdAt.localeCompare(r.createdAt));return t?a.find(r=>r.key===t):a.find(r=>_r(r)&&r.key.startsWith("brand:")&&r.key.endsWith(`:${n}`))}function c1({slug:e,live:t}){const a=V().web.library.assets,r=t.projectTicks[e]??0,[l,o]=i.useState(0),c=i.useCallback(()=>o(b=>b+1),[]),[d,m]=i.useState(null),[u,h]=i.useState(null),[f,x]=i.useState(null),[p,g]=i.useState(null);return i.useEffect(()=>{let b=!0;return Promise.resolve().then(()=>q.listAssets(e)).then(v=>{b&&(m(v),h(null))}).catch(v=>{b&&h(pe(v))}),()=>{b=!1}},[e,r,l]),i.useEffect(()=>{let b=!0;return Promise.resolve().then(()=>q.getBrand(e)).then(v=>{b&&x(v.jobKey)}).catch(()=>{}),Promise.resolve().then(()=>q.getProject(e)).then(v=>{b&&g(v.project.name)}).catch(()=>{}),()=>{b=!1}},[e]),!d&&u?s.jsx("div",{className:"ms-lib-center",children:s.jsx(Rt,{icon:"warn",title:a.loadFailed({detail:u}),action:s.jsx($,{onClick:()=>{h(null),c()},children:a.retry})})}):d?s.jsx(d1,{slug:e,live:t,listing:d,setListing:m,reload:c,job:o1(t.jobs,f,e),projectName:p??e}):s.jsx("div",{className:"ms-lib-center",children:s.jsx(Ts,{size:20})})}function d1({slug:e,live:t,listing:n,setListing:a,reload:r,job:l,projectName:o}){const c=V(),d=ul(e,t),m=Xu(e,t),u=c.web.library.assets,h=Ra([]),[f,x]=i.useState("all"),[p,g]=i.useState(null),[b,v]=i.useState(null),[y,w]=i.useState(""),[j,S]=i.useState("date"),[k,E]=i.useState(!1),N=n.creativeReferences??[],[C,R]=i.useState(()=>new Set),[P,z]=i.useState(null),[O,T]=i.useState(()=>new Set),[W,Z]=i.useState([]),[A,L]=i.useState(!1),[_,X]=i.useState(()=>new Set),[ae,K]=i.useState(!1),I=i.useRef(0),H=i.useRef(null),de=i.useRef(!0);i.useEffect(()=>{de.current=!1},[]);const J=Yu(ne=>{a(Ee=>Ee&&{...Ee,assets:Ee.assets.filter(Ce=>!ne.includes(Oa("asset",e,Ce.file)))})}),se=i.useMemo(()=>n.assets.filter(ne=>!O.has(ne.file)&&!Ju(Oa("asset",e,ne.file))),[n.assets,O,e,J]),U=`${f}
|
|
9
|
+
${p??""}
|
|
10
|
+
${b??""}
|
|
11
|
+
${y.trim()}`,te=i.useRef(U);i.useEffect(()=>{te.current!==U&&(te.current=U,R(ne=>ne.size?new Set:ne))},[U]),i.useEffect(()=>{const ne=new Set(se.map(Ee=>Ee.file));R(Ee=>[...Ee].every(Ce=>ne.has(Ce))?Ee:new Set([...Ee].filter(Ce=>ne.has(Ce)))),z(Ee=>Ee&&!ne.has(Ee)?null:Ee)},[se]);const[G,re]=i.useState(null);fN(e,re),i.useEffect(()=>{if(!G||se.length===0||!m.loaded)return;const ne=Object.values(m.byFile).find(Xe=>Xe.jobId===G.jobId)?.file,Ee=se.filter(Xe=>Xe.kind==="video"&&On(Xe.file)===G.name),Ce=ne?.startsWith("assets/")?ne.slice(7):Ee.length===1?Ee[0].file:null;Ce&&se.some(Xe=>Xe.file===Ce)&&z(Ce),re(null)},[G,se,m.byFile,m.loaded]);const[oe,Ne]=i.useState(null),Q=oe?t.jobs[oe.jobId]:void 0,Re=!!(Q&&!_r(Q));i.useEffect(()=>{!oe||!Q||_r(Q)||(Q.state==="succeeded"&&Pe.show(u.described,{tone:"ok"}),Ne(null),r())},[oe,Q,u,r]);const Ue=_r(l),is=i.useMemo(()=>oe&&!Re?new Set(oe.files):l&&Ue&&eo(l)?new Set(se.filter(ne=>!ne.description.trim()).map(ne=>ne.file)):new Set,[oe,Re,l,Ue,se]),Qe=Ue||!!(oe&&!Re),gs=i.useCallback(async ne=>{if(ne.length===0)return!1;try{const Ee=await q.describeAssets(e,ne);return Ne({jobId:Ee.id,files:ne}),!0}catch(Ee){return Pe.show(u.describeFailed({detail:pe(Ee)})),!1}},[e,u]),As=i.useCallback(async ne=>{if(ne.length===0||n.error)return;const Ee=ne.map(Ce=>Ce.name);Z(Ce=>[...Ce,...Ee]);try{const Xe=(await q.uploadFiles(e,"assets",ne)).assets??[];X(ue=>new Set([...ue,...Xe.map(xe=>xe.file)])),a(ue=>ue&&{...ue,assets:[...ue.assets.filter(xe=>!Xe.some(Be=>Be.file===xe.file)),...Xe]}),Pe.show(u.uploaded({count:Xe.length}),{tone:"ok"}),r()}catch(Ce){Pe.show(u.uploadFailed({detail:pe(Ce)}))}finally{Z(Ce=>Ce.filter(Xe=>!Ee.includes(Xe)))}},[e,n.error,u,a,r]),hs=i.useCallback(async ne=>{if(ne.length===0)return;R(new Set),z(xe=>xe&&ne.includes(xe)?null:xe);const Ee=[...h.current?.querySelectorAll("[data-file]")??[]].filter(xe=>ne.includes(xe.dataset.file??""));if((await Promise.all(Ee.map(xe=>gr(xe,{y:6,ms:qs.s})))).includes(!1))return;T(xe=>new Set([...xe,...ne]));const Xe=(xe=ne)=>T(Be=>new Set([...Be].filter(_e=>!xe.includes(_e))));let ue=null;Qu({text:u.deleted({count:ne.length,name:On(ne[0])}),undoLabel:u.undo,ms:cg,keys:ne.map(xe=>Oa("asset",e,xe)),commit:async()=>{const xe=await Promise.allSettled(ne.map(_e=>q.deleteAsset(e,_e,Zu))),Be=ne.filter((_e,ge)=>xe[ge].status==="rejected");if(Be.length){ue=Be;const _e=ne.filter(ge=>!Be.includes(ge));throw a(ge=>ge&&{...ge,assets:ge.assets.filter(qe=>!_e.includes(qe.file))}),xe[ne.indexOf(Be[0])].reason}a(_e=>_e&&{..._e,assets:_e.assets.filter(ge=>!ne.includes(ge.file))}),Xe(),r()},restore:()=>Xe(ue??ne),onError:xe=>{Pe.show(u.deleteFailed({detail:pe(xe)})),r()}})},[e,u,h,a,r]),Oe=i.useCallback(ne=>{oN(e,ne.map(Ee=>`assets/${Ee}`)),Bs(es.newCreative(e))},[e]),be=i.useCallback(ne=>{a(Ee=>Ee&&{...Ee,assets:Ee.assets.map(Ce=>Ce.file===ne.file?ne:Ce)})},[a]),Fe=i.useCallback((ne,Ee)=>{a(Ce=>Ce&&{...Ce,assets:Ce.assets.map(Xe=>Xe.file===ne?Ee:Xe)}),R(Ce=>Ce.has(ne)?new Set([...Ce].map(Xe=>Xe===ne?Ee.file:Xe)):Ce),z(Ce=>Ce===ne?Ee.file:Ce),r()},[a,r]),je=i.useCallback(async(ne,Ee)=>{const Ce=Po(Ee);if(Ce.length){try{for(const Xe of ne){const ue=n.assets.find(Be=>Be.file===Xe);if(!ue)continue;const xe=pg(ue.tags,Ce);xe.length!==ue.tags.length&&be(await q.updateAsset(e,Xe,{tags:xe}))}Pe.show(u.tagsAdded({count:ne.length}),{tone:"ok"})}catch(Xe){Pe.show(u.tagsFailed({detail:pe(Xe)}))}r()}},[n.assets,e,u,be,r]),he=async()=>{try{await q.registerAssets(e,n.unregistered),r()}catch(ne){Pe.show(u.registerFailed({detail:pe(ne)}))}},Ke=Ak(se,j).filter(ne=>(f==="all"||ne.kind===f)&&(!p||ne.origin===p)&&(!b||ne.tags.includes(b))&&(!y.trim()||`${ne.file} ${ne.description} ${ne.tags.join(" ")}`.toLowerCase().includes(y.trim().toLowerCase()))),we=f!=="all"||p!==null||b!==null||y.trim()!=="",ze=()=>{x("all"),g(null),v(null),w("")},We=i.useMemo(()=>{const ne=new Map;for(const Ee of se)for(const Ce of Ee.tags)ne.set(Ce,(ne.get(Ce)??0)+1);return[...ne.entries()].sort((Ee,Ce)=>Ce[1]-Ee[1]||Ee[0].localeCompare(Ce[0])).slice(0,12).map(([Ee])=>Ee)},[se]),Rs=se.filter(ne=>!ne.description.trim()).map(ne=>ne.file),us=P?se.find(ne=>ne.file===P):void 0,fs=ne=>R(Ee=>{const Ce=new Set(Ee);return Ce.has(ne)?Ce.delete(ne):Ce.add(ne),Ce}),fe=!n.error,Ge=ne=>{!fe||!ld(ne)||(ne.preventDefault(),I.current+=1,K(!0))},De=ne=>{fe&&ld(ne)&&ne.preventDefault()},os=ne=>{!fe||!ld(ne)||(I.current=Math.max(0,I.current-1),I.current===0&&K(!1))},Ze=ne=>{ne.preventDefault(),I.current=0,K(!1),fe&&As(Array.from(ne.dataTransfer?.files??[]))},vs=()=>H.current?.click(),Le=l&&!Ue&&eo(l)&&l.state==="failed";return s.jsxs("div",{ref:h,className:le("ms-assets",us&&"ms-with-detail"),onDragEnter:Ge,onDragOver:De,onDragLeave:os,onDrop:Ze,children:[s.jsx("input",{ref:H,type:"file",multiple:!0,hidden:!0,"aria-label":u.uploadInput,onChange:ne=>{As(Array.from(ne.target.files??[])),ne.target.value=""}}),s.jsxs("aside",{className:"ms-assets-side",children:[s.jsxs("nav",{className:"ms-assets-filters","aria-label":u.filters,children:[s.jsxs("div",{className:"ms-lib-group",children:[s.jsx("span",{className:"ms-lib-cap",children:u.type}),s.jsx(Ii,{on:!k&&f==="all",icon:"grid",count:se.length,onClick:()=>{E(!1),x("all")},children:u.kinds.all}),mg.map(ne=>{const Ee=se.filter(Ce=>Ce.kind===ne).length;return s.jsx(Ii,{on:!k&&f===ne,icon:m1[ne],count:Ee,dim:Ee===0,onClick:()=>{E(!1),x(ne)},children:u.kinds[ne]},ne)})]}),s.jsxs("div",{className:"ms-lib-group",children:[s.jsx("span",{className:"ms-lib-cap",children:u.origin}),i1.map(ne=>{const Ee=se.filter(Ce=>Ce.origin===ne).length;return s.jsx(Ii,{on:!k&&p===ne,count:Ee,dim:Ee===0,onClick:()=>{E(!1),g(p===ne?null:ne)},children:u.origins[ne]},ne)})]}),s.jsxs("div",{className:"ms-lib-group",children:[s.jsx("span",{className:"ms-lib-cap",children:u.refsGroup}),s.jsx(Ii,{on:k,icon:"pin",count:N.length,dim:N.length===0,onClick:()=>E(ne=>!ne),children:u.refsFilter})]}),We.length>0?s.jsxs("div",{className:"ms-lib-group",children:[s.jsx("span",{className:"ms-lib-cap",children:u.tags}),s.jsx("div",{className:"ms-assets-tags",children:We.map(ne=>s.jsx(sn,{on:b===ne,onClick:()=>v(b===ne?null:ne),children:ne},ne))})]}):null]}),s.jsx("div",{className:"ms-grow"}),s.jsx(h1,{count:Rs.length,total:se.length,describing:is.size>0,busy:Qe,onDescribe:()=>{gs(Rs)}})]}),k?s.jsx(u1,{slug:e,refs:N,reload:r}):s.jsxs("main",{className:"ms-assets-main",children:[s.jsxs("div",{className:"ms-assets-head","data-enter":!0,children:[s.jsx("h1",{children:u.title}),s.jsx("span",{className:"ms-lib-muted",children:u.count({shown:Ke.length,total:se.length})}),C.size?s.jsxs("span",{className:"ms-lib-muted",children:["· ",u.selectedCount({count:C.size})]}):null,we?s.jsx($,{size:"sm",variant:"ghost",onClick:ze,children:u.clearFilters}):null,s.jsx("div",{className:"ms-grow"}),s.jsx(At,{className:"ms-assets-sort",variant:"pill",label:u.sort.label,value:j,onChange:ne=>S(ne),options:Pk.map(ne=>({value:ne,label:u.sort[ne]}))}),s.jsxs("label",{className:"ms-lib-search",children:[s.jsx(F,{name:"search",size:14}),s.jsx("input",{type:"search",value:y,onChange:ne=>w(ne.target.value),placeholder:u.searchPlaceholder,"aria-label":u.search})]}),s.jsxs($,{variant:"outline",disabled:!fe,onClick:()=>L(!0),children:[s.jsx(F,{name:"sparkle",size:13,strokeWidth:1.7}),c.web.library.generate.open]}),s.jsxs($,{variant:"ink",disabled:!fe,onClick:vs,children:[s.jsx(F,{name:"upload",size:13,strokeWidth:1.7}),u.upload]})]}),s.jsx(r1,{open:A,onClose:()=>L(!1),slug:e,live:t}),n.error?s.jsx(oa,{children:u.listUnreadable({detail:n.error})}):null,n.unregistered.length>0?s.jsx(oa,{action:s.jsx($,{size:"sm",variant:"outline",onClick:()=>{he()},children:u.register}),children:u.unregistered({count:n.unregistered.length})}):null,d.state?s.jsx(vr,{slug:e,state:d.state,reload:d.reload}):null,Le?s.jsx(oa,{children:rN(l,c)}):null,l&&!Ue&&eo(l)?(l.notes??[]).map(ne=>s.jsx(oa,{children:ne},ne)):null,se.length===0&&W.length===0?s.jsx("div",{className:"ms-lib-empty",children:s.jsx(Rt,{icon:"image",title:u.emptyTitle,sub:u.emptyBody,action:s.jsxs($,{variant:"ink",disabled:!fe,onClick:vs,children:[s.jsx(F,{name:"upload",size:13}),u.upload]})})}):Ke.length===0&&W.length===0?s.jsx("div",{className:"ms-lib-empty",children:s.jsx(Rt,{icon:"search",title:u.noMatchTitle,sub:u.noMatchBody,action:s.jsx($,{size:"sm",variant:"outline",onClick:ze,children:u.clearFilters})})}):s.jsxs("div",{className:"ms-assets-grid",children:[Ke.map((ne,Ee)=>s.jsx(f1,{slug:e,asset:ne,index:Ee,cascade:de.current,fresh:_.has(ne.file),selected:C.has(ne.file),active:P===ne.file,describing:is.has(ne.file),analysed:m.byFile[`assets/${ne.file}`]?.state==="ready",onSelect:()=>fs(ne.file),onOpen:()=>z(ne.file)},ne.file)),W.map((ne,Ee)=>s.jsx(p1,{name:ne},`${ne}-${Ee}`)),fe?s.jsxs("button",{type:"button",className:"ms-assets-drop",onClick:vs,children:[s.jsx(F,{name:"upload",size:20}),s.jsx("b",{children:u.dropTitle}),s.jsx("span",{children:u.dropBody})]}):null]})]}),s.jsx("div",{className:"ms-assets-detail",children:us&&!k?s.jsx(US,{slug:e,asset:us,describing:is.has(us.file),busy:Qe,onClose:()=>z(null),onSaved:be,onRenamed:Fe,onDescribe:()=>{gs([us.file])},onUse:()=>Oe([us.file]),onDelete:()=>{hs([us.file])},analysis:m.byFile[`assets/${us.file}`],analysisWaitReason:t.jobs[m.byFile[`assets/${us.file}`]?.jobId??""]?.waitReason},us.file):null}),C.size?s.jsx(x1,{count:C.size,busy:Qe,onDescribe:()=>{const ne=[...C];R(new Set),gs(ne)},onAddTags:ne=>je([...C],ne),onUse:()=>Oe([...C]),onDelete:()=>{hs([...C])},onClear:()=>R(new Set)}):null,ae&&fe?s.jsx("div",{className:"ms-lib-dropzone","aria-hidden":"true",children:s.jsx("span",{children:u.dropOverlay({project:o})})}):null]})}function u1({slug:e,refs:t,reload:n}){const a=V().web.library.assets,[r,l]=i.useState(()=>new Set),o=async c=>{l(d=>new Set([...d,c.file]));try{await q.setAssetReference(e,c.file,!1),Pe.show(a.savedToAssets({name:On(c.file)}),{tone:"ok"}),n()}catch(d){Pe.show(a.saveToAssetsFailed({detail:pe(d)}))}finally{l(d=>new Set([...d].filter(m=>m!==c.file)))}};return s.jsxs("main",{className:"ms-assets-main",children:[s.jsxs("div",{className:"ms-assets-head","data-enter":!0,children:[s.jsx("h1",{children:a.refsFilter}),s.jsx("span",{className:"ms-lib-muted",children:t.length})]}),s.jsx("p",{className:"ms-lib-muted ms-assets-refs-intro",children:a.refsIntro}),t.length===0?s.jsx("div",{className:"ms-lib-empty",children:s.jsx(Rt,{icon:"pin",title:a.refsEmpty,sub:a.refsEmptyBody})}):s.jsx("div",{className:"ms-assets-grid",role:"list","aria-label":a.refsFilter,children:t.map(c=>{const d=On(c.file);return s.jsxs("div",{role:"listitem","data-file":c.file,className:"ms-acard ms-acard-ref",children:[s.jsx("div",{className:"ms-acard-media",children:s.jsx(bm,{slug:e,asset:c})}),s.jsxs("div",{className:"ms-acard-body",children:[s.jsx("b",{className:"ms-acard-name",title:c.file,children:d}),s.jsx("span",{className:"ms-acard-desc",children:c.usedBy.length===0?s.jsx("span",{className:"ms-lib-faint",children:a.refsUnused}):s.jsxs(s.Fragment,{children:[a.refsUsedBy," ",c.usedBy.map((m,u)=>s.jsxs("span",{children:[u>0?", ":"",s.jsx("a",{className:"ms-link",href:es.creative(e,m.slug),children:m.title})]},m.slug))]})}),s.jsxs($,{size:"sm",variant:"outline",className:"ms-acard-save",loading:r.has(c.file),"aria-label":`${a.saveToAssets}: ${d}`,onClick:()=>{o(c)},children:[s.jsx(F,{name:"check",size:12}),a.saveToAssets]})]})]},c.file)})})]})}const m1={image:"image",svg:"edit",video:"video",font:"text",audio:"play",other:"folder"};function Ii({on:e,icon:t,count:n,dim:a,onClick:r,children:l}){return s.jsx(dn,{icon:t,count:n,"aria-pressed":e,className:le(e&&"ms-on",a&&"ms-dim"),onClick:r,children:l})}function h1({count:e,total:t,describing:n,busy:a,onDescribe:r}){const o=V().web.library.assets;return t===0?null:s.jsx("div",{className:"ms-assets-describe",children:n?s.jsxs("span",{className:"ms-lib-row",children:[s.jsx(Ts,{decorative:!0,size:12}),o.describing]}):e===0?s.jsxs("span",{className:"ms-lib-row ms-lib-muted",children:[s.jsx(F,{name:"check",size:12}),o.allDescribed]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{children:o.undescribed({count:e})}),s.jsxs($,{size:"sm",variant:"outline",disabled:a,onClick:r,children:[s.jsx(F,{name:"sparkle",size:12}),o.describeMissing({count:e})]}),a?s.jsx("span",{className:"ms-lib-note",children:o.describeBusy}):null]})})}function f1({slug:e,asset:t,index:n,cascade:a,fresh:r,selected:l,active:o,describing:c,analysed:d,onSelect:m,onOpen:u}){const h=V(),f=h.web.library.assets,x=i.useRef(null),p=On(t.file);return i.useLayoutEffect(()=>{Gs(x.current,r?{y:14,scale:.96}:{y:8,delay:a?Math.min(n,12)*30:0})},[]),s.jsxs("div",{ref:x,"data-file":t.file,className:le("ms-acard",l&&"ms-sel",o&&"ms-active"),children:[s.jsxs("div",{className:"ms-acard-media",children:[s.jsx(bm,{slug:e,asset:t}),t.width&&t.height&&(t.kind==="image"||t.kind==="video")?s.jsxs("span",{className:"ms-acard-dims",children:[t.width,"×",t.height]}):null,d?s.jsx("span",{className:"ms-acard-analysed",role:"img","aria-label":h.videoAnalysis.analyzedMark,title:h.videoAnalysis.analyzedMark,children:s.jsx(F,{name:"sparkle",size:11})}):null,t.durationSec&&(t.kind==="video"||t.kind==="audio")?s.jsx("span",{className:"ms-acard-dur",title:f.durationBadge({time:la(t.durationSec)}),children:la(t.durationSec)}):null,c?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-shimmer","aria-hidden":"true"}),s.jsx(Qs,{spinner:!0,className:"ms-acard-describing",children:f.describing})]}):null]}),s.jsxs("div",{className:"ms-acard-body",children:[s.jsx("b",{className:"ms-acard-name",title:t.file,children:p}),c?s.jsxs("span",{className:"ms-acard-skeleton","aria-hidden":"true",children:[s.jsx("i",{}),s.jsx("i",{})]}):t.description.trim()?s.jsx("span",{className:"ms-acard-desc",children:t.description}):s.jsx("span",{className:"ms-acard-desc ms-lib-faint",children:f.noDescription}),s.jsxs("span",{className:"ms-acard-meta",children:[t.tags.slice(0,2).map(g=>s.jsx(tn,{children:g},g)),t.tags.length>2?s.jsx("span",{className:"ms-lib-faint",children:f.more({count:t.tags.length-2})}):null,s.jsx("span",{className:"ms-acard-origin",children:f.originShort[t.origin]})]})]}),s.jsx("button",{type:"button",className:"ms-acard-open","aria-label":f.open({name:p}),"aria-expanded":o,onClick:u}),s.jsx("span",{className:"ms-acard-check",children:s.jsx(Rn,{on:l,onChange:m,label:f.select({name:p})})})]})}function p1({name:e}){const t=V(),n=i.useRef(null);return i.useLayoutEffect(()=>{Gs(n.current,{y:14,scale:.96})},[]),s.jsxs("div",{ref:n,className:"ms-acard ms-acard-uploading","aria-busy":"true",children:[s.jsxs("div",{className:"ms-acard-media",children:[s.jsx("span",{className:"ms-athumb ms-athumb-file",children:s.jsx(Ts,{decorative:!0,size:18})}),s.jsx("span",{className:"ms-shimmer","aria-hidden":"true"})]}),s.jsxs("div",{className:"ms-acard-body",children:[s.jsx("b",{className:"ms-acard-name",children:e}),s.jsx("span",{className:"ms-acard-desc ms-lib-faint",children:t.web.library.assets.uploading})]})]})}function x1({count:e,busy:t,onDescribe:n,onAddTags:a,onUse:r,onDelete:l,onClear:o}){const d=V().web.library.assets,m=i.useRef(null),u=i.useRef(null),[h,f]=i.useState(!1),[x,p]=i.useState(""),[g,b]=i.useState(!1);i.useLayoutEffect(()=>{Gs(m.current,{y:16})},[]);const v=async y=>{y.preventDefault(),!(!Po(x).length||g)&&(b(!0),await a(x),b(!1),p(""),f(!1))};return s.jsxs("div",{className:"ms-selbar-wrap",children:[s.jsxs("div",{ref:m,className:"ms-selbar",role:"toolbar","aria-label":d.selection,children:[s.jsx("b",{children:d.selectedCount({count:e})}),s.jsx("button",{type:"button",className:"ms-selbar-btn",disabled:t,title:t?d.describeBusy:void 0,onClick:n,children:d.describeAgain}),s.jsx("button",{ref:u,type:"button",className:"ms-selbar-btn","aria-expanded":h,onClick:()=>f(y=>!y),children:d.addTags}),s.jsx("button",{type:"button",className:"ms-selbar-btn",onClick:r,children:d.useInCreative}),s.jsx("span",{className:"ms-selbar-sep","aria-hidden":"true"}),s.jsx("button",{type:"button",className:"ms-selbar-btn ms-selbar-danger",onClick:l,children:d.delete}),s.jsx("button",{type:"button",className:"ms-selbar-btn ms-selbar-x","aria-label":d.clearSelection,onClick:o,children:s.jsx(F,{name:"close",size:11})})]}),s.jsx(ot,{open:h,onClose:()=>f(!1),anchor:u,placement:"top-start",width:280,children:s.jsxs("form",{className:"ms-lib-pop",onSubmit:y=>{v(y)},children:[s.jsx(ms,{autoFocus:!0,value:x,onChange:y=>p(y.target.value),"aria-label":d.addTagsLabel,placeholder:d.addTagsPlaceholder}),s.jsx($,{type:"submit",size:"sm",variant:"ink",loading:g,disabled:!Po(x).length,children:d.addTagsApply})]})})]})}const g1=1800,lo=600;function v1(e,t,n){const[a,r]=i.useState(t),[l,o]=i.useState({saving:!1,saved:!1,error:null}),c=i.useRef(t),d=i.useRef(!1),m=i.useRef(!1),u=i.useRef(0),h=i.useRef(null),f=i.useRef(null),x=i.useRef(null),p=i.useRef(!1),g=i.useRef(n);g.current=n,i.useEffect(()=>{if(t){if(d.current||m.current){p.current=!0;return}c.current=t,r(t)}},[t]);const b=()=>{u.current++,f.current&&clearTimeout(f.current),o(C=>({...C,saving:!0,saved:!1}))},v=(C,R,P)=>{if(u.current--,R!==null){x.current=P,o({saving:u.current>0,saved:!1,error:{target:C,message:R}});return}const z=u.current===0&&!d.current;o(O=>({saving:!z,saved:z,error:O.error?.target===C?null:O.error})),z&&(f.current&&clearTimeout(f.current),f.current=setTimeout(()=>o(O=>({...O,saved:!1})),g1),C==="kit"&&p.current&&(p.current=!1,g.current()))},y=i.useCallback(async()=>{if(h.current&&(clearTimeout(h.current),h.current=null),m.current||!d.current||!c.current)return;const C=c.current;d.current=!1,m.current=!0,b();let R=!0;try{await q.saveBrandKit(e,C),v("kit",null,()=>{})}catch(P){R=!1,d.current=!0,v("kit",pe(P),()=>{y()})}finally{m.current=!1}R&&d.current&&await y()},[e]),w=i.useCallback((C,R=0)=>{const P=c.current;if(!P)return;const z=typeof C=="function"?C(P):C;c.current=z,r(z),d.current=!0,h.current&&clearTimeout(h.current),R>0?h.current=setTimeout(()=>{y()},R):y()},[y]),j=i.useCallback(()=>{h.current&&y()},[y]),S=i.useCallback(async C=>{b();try{return await q.saveGuidelines(e,C),v("guidelines",null,()=>{}),!0}catch(R){return v("guidelines",pe(R),()=>{S(C)}),!1}},[e]),k=i.useCallback(()=>{x.current?.()},[]),E=i.useCallback(()=>d.current||m.current||h.current!==null,[]),N=i.useCallback((C,R)=>{if(!d.current&&!m.current){c.current=C,r(C);return}const P=R(c.current??C);c.current=P,r(P),d.current=!0,!m.current&&!h.current&&y()},[y]);return i.useEffect(()=>()=>{f.current&&clearTimeout(f.current),h.current&&y()},[y]),{kit:a,status:l,edit:w,flush:j,saveGuidelines:S,retry:k,rebase:N,pending:E}}const b1=/\.(png|jpe?g|webp|gif|svg|avif)$/i,id=3,io=e=>!!(e&&(e.state==="queued"||e.state==="running")),lv=i.createContext(null),Gt=()=>i.useContext(lv);function ii(e){const{settled:t}=Gt();i.useLayoutEffect(()=>{t.current&&Gs(e.current,{y:6,scale:.96,ms:qs.m})},[])}async function kc(e,t){await il(e)&&t()}function j1({overview:e,projectName:t}){const a=V().web.brand,r=rs(),{slug:l,kit:o}=Gt(),c=o.logos.find(p=>p.variant==="primary")??o.logos[0],d=c?jm(c.background==="dark"?"dark":"light",o.colors):null,m=e.sources.map(p=>p.lastAnalyzedAt).filter(p=>!!p).sort().at(-1),u=sv(e.sources).join(", "),h=[...e.proposals].filter(p=>p.status!=="discarded"&&p.summary.trim()).sort((p,g)=>g.createdAt.localeCompare(p.createdAt))[0]?.summary,f=av(h??""),x=t??l;return s.jsxs("section",{"data-sec":"overview",className:"ms-boverview","aria-label":a.nav.overview,"data-enter":!0,children:[s.jsx("div",{className:le("ms-boverview-tile",!c&&"ms-initials",c?.background==="dark"&&!d&&"ms-dark"),style:d?{background:d}:void 0,children:c?s.jsx("img",{src:q.projectFileUrl(l,c.file),alt:a.logos.alt({file:c.file})}):s.jsx("span",{"aria-hidden":"true",children:ai(x)})}),s.jsxs("div",{className:"ms-boverview-text",children:[s.jsx("h1",{children:x}),s.jsx("p",{children:f.text||a.overview.intro}),s.jsx(iv,{details:f.details}),s.jsx("span",{className:"ms-faint",children:m&&u?a.overview.learnedFrom({hosts:u,when:ll(r,m)}):a.overview.notAnalyzed})]})]})}function iv({details:e}){const t=V().web.brand,[n,a]=i.useState(!1),r=i.useId();return e.length?s.jsxs("div",{className:"ms-bdetails",children:[s.jsxs("button",{type:"button",className:"ms-bdetails-toggle","aria-expanded":n,"aria-controls":r,onClick:()=>a(l=>!l),children:[s.jsx(F,{name:"chevron",size:12,className:le("ms-bdetails-chev",n&&"ms-open")}),t.overview.details]}),n?s.jsx("ul",{id:r,className:"ms-bdetails-list",children:e.map((l,o)=>s.jsx("li",{children:l},o))}):null]}):null}function ov({note:e,field:t,label:n,placeholder:a,empty:r}){const o=V().web.brand.voice,{locked:c,saver:d}=Gt(),[m,u]=i.useState(!1),[h,f]=i.useState(""),x=()=>{f(e?.text??""),u(!0)},p=g=>{g.preventDefault();const b=h.trim();d.edit(v=>({...v,[t]:b?{id:t==="tone"?"tone":"photo-style",text:b,source:rr}:null})),u(!1)};return m?s.jsxs("form",{className:"ms-bnote-edit",onSubmit:p,children:[s.jsx(nn,{rows:4,value:h,"aria-label":n,placeholder:a,autoFocus:!0,onChange:g=>f(g.target.value)}),s.jsxs("span",{className:"ms-brow",children:[s.jsx($,{type:"submit",variant:"ink",size:"sm",children:o.save}),s.jsx($,{variant:"ghost",size:"sm",onClick:()=>u(!1),children:o.cancel})]})]}):s.jsxs(s.Fragment,{children:[e?s.jsx("p",{className:"ms-btext",children:e.text}):s.jsx("p",{className:"ms-bempty-line",children:r}),s.jsx($,{variant:"ghost",size:"sm",className:"ms-blink ms-bstart",disabled:c,onClick:x,children:e?o.edit:o.write})]})}function y1(){const e=V(),t=e.web.brand.voice,{kit:n}=Gt();return s.jsxs("section",{"data-sec":"voice",className:"ms-bvoice","aria-label":e.web.brand.nav.voice,"data-enter":!0,children:[s.jsxs("div",{className:"ms-card ms-bcard",children:[s.jsx("h2",{children:e.web.brand.nav.voice}),s.jsx(ov,{note:n.tone,field:"tone",label:t.toneLabel,placeholder:t.placeholder,empty:t.empty})]}),s.jsx(Rf,{kind:"dos"}),s.jsx(Rf,{kind:"donts"})]})}function Rf({kind:e}){const n=V().web.brand.voice,{kit:a,locked:r,saver:l}=Gt(),o=a[e],[c,d]=i.useState(!1),[m,u]=i.useState(!1),[h,f]=i.useState(""),x=e==="dos"?n.do:n.avoid,p=b=>{b.preventDefault();const v=h.trim();v&&(l.edit(y=>({...y,[e]:[...y[e],{id:wc(e==="dos"?"do":"avoid",y[e].map(w=>w.id)),text:v,source:rr}]})),f(""),u(!1),d(!0))},g=c?o:o.slice(0,id);return s.jsxs("div",{className:"ms-card ms-bcard ms-brules",children:[s.jsxs("span",{className:"ms-brules-head",children:[s.jsx("span",{className:le("ms-brules-icon",e==="dos"?"ms-ok":"ms-warn"),"aria-hidden":"true",children:s.jsx(F,{name:e==="dos"?"check":"close",size:9,strokeWidth:2.4})}),s.jsx("h3",{children:x}),s.jsx("span",{className:"ms-faint",children:o.length})]}),o.length?s.jsx("ul",{className:"ms-brules-list","aria-label":x,children:g.map((b,v)=>s.jsx(w1,{n:b,kind:e,first:v===0},b.id))}):s.jsx("p",{className:"ms-bempty-line",children:n.noRules}),s.jsxs("span",{className:"ms-brow",children:[o.length>id?s.jsx("button",{type:"button",className:"ms-blink-btn",onClick:()=>d(!c),children:c?n.less:n.more({count:o.length-id})}):null,s.jsx("button",{type:"button",className:"ms-blink-btn ms-bpush",disabled:r,onClick:()=>{u(!m),f("")},children:n.addRule})]}),m?s.jsxs("form",{className:"ms-brow",onSubmit:p,children:[s.jsx(ms,{className:"ms-grow ms-bsmall",autoFocus:!0,value:h,"aria-label":e==="dos"?n.doLabel:n.avoidLabel,placeholder:e==="dos"?n.doPlaceholder:n.avoidPlaceholder,onChange:b=>f(b.target.value)}),s.jsx($,{type:"submit",variant:"ink",size:"sm",disabled:!h.trim(),children:n.add})]}):null]})}function w1({n:e,kind:t,first:n}){const a=V(),r=a.web.brand.voice,{kit:l,locked:o,saver:c}=Gt(),d=i.useRef(null);ii(d);const m=()=>{const u=l[t].findIndex(h=>h.id===e.id);kc(d.current,()=>{c.edit(h=>({...h,[t]:h[t].filter(f=>f.id!==e.id)})),Pe.show(r.ruleRemoved,{action:{label:a.web.brand.undo,run:()=>c.edit(h=>h[t].some(f=>f.id===e.id)?h:{...h,[t]:[...h[t].slice(0,u),e,...h[t].slice(u)]})}})})};return s.jsxs("li",{ref:d,className:le("ms-brule",n&&"ms-first"),children:[s.jsx("span",{children:e.text}),s.jsx($,{variant:"ghost",size:"sm",icon:!0,className:"ms-brule-x",disabled:o,"aria-label":r.removeRule({text:e.text}),onClick:m,children:s.jsx(F,{name:"close",size:11})})]})}function k1({references:e}){const n=V().web.brand,{slug:a,kit:r}=Gt(),l=e.filter(o=>o.useForBrand&&b1.test(o.file)).slice(0,3);return s.jsxs("section",{"data-sec":"photo",className:"ms-card ms-bcard","aria-labelledby":"ms-bphoto","data-enter":!0,children:[s.jsx("h2",{id:"ms-bphoto",children:n.nav.photo}),s.jsx(ov,{note:r.photoStyle,field:"photoStyle",label:n.photo.label,placeholder:n.photo.placeholder,empty:n.photo.empty}),l.length?s.jsx("div",{className:"ms-bphotos",children:l.map(o=>s.jsx("img",{src:q.projectFileUrl(a,`references/${o.file}`),alt:o.note||o.file},o.file))}):null]})}function N1({text:e,onSaved:t}){const n=V(),a=n.web.brand.guidelines,{saver:r}=Gt(),[l,o]=i.useState(!1),[c,d]=i.useState(!1),[m,u]=i.useState(e),[h,f]=i.useState(!1),x=j=>{u(e),d(j),o(!0)},p=async()=>{f(!0);const j=await r.saveGuidelines(m);f(!1),j&&(t(m),d(!1))},g=c&&m!==e,[b,v]=i.useState(null),y=j=>{if(g){v(j);return}w(j)},w=j=>{v(null),u(e),j==="close"||!e.trim()?o(!1):d(!1)};return s.jsxs("section",{"data-sec":"guidelines",className:"ms-card ms-bcard","aria-labelledby":"ms-bguide","data-enter":!0,children:[s.jsxs("div",{className:"ms-bsection-head",children:[s.jsx("h2",{id:"ms-bguide",children:n.web.brand.nav.guidelines}),e.trim()?s.jsx($,{variant:"ghost",size:"sm",className:"ms-blink",onClick:()=>x(!1),children:a.open}):null]}),e.trim()?s.jsx("div",{className:"ms-bguide-preview",children:s.jsx(Ro,{text:e,headings:!0})}):s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"ms-bempty-line",children:a.empty}),s.jsxs($,{size:"sm",className:"ms-bstart",onClick:()=>x(!0),children:[s.jsx(F,{name:"edit",size:13}),a.write]})]}),s.jsx(rt,{open:l,onClose:()=>o(!1),label:n.web.brand.nav.guidelines,width:760,dismissible:!g&&!h,children:s.jsxs("div",{className:"ms-bguide-dialog",children:[s.jsxs("div",{className:"ms-bguide-head",children:[s.jsx("h2",{children:n.web.brand.nav.guidelines}),c?null:s.jsxs($,{size:"sm",onClick:()=>{u(e),d(!0)},children:[s.jsx(F,{name:"edit",size:13}),a.edit]}),s.jsx($,{variant:"ghost",size:"sm",icon:!0,"aria-label":a.close,disabled:h,onClick:()=>y("close"),children:s.jsx(F,{name:"close",size:12})})]}),s.jsx("div",{className:"ms-bguide-body",children:c?s.jsx(nn,{rows:18,className:"ms-mono",value:m,"aria-label":a.label,onChange:j=>u(j.target.value)}):s.jsx(Ro,{text:e,headings:!0})}),c&&b?s.jsxs("div",{className:"ms-bguide-foot ms-bguide-ask",role:"group","aria-label":a.discardQ,children:[s.jsx("span",{className:"ms-bwarn",children:a.discardQ}),s.jsx($,{variant:"ghost",onClick:()=>v(null),children:a.keep}),s.jsx($,{variant:"danger",autoFocus:!0,onClick:()=>w(b),children:a.discard})]}):c?s.jsxs("div",{className:"ms-bguide-foot",children:[s.jsx($,{variant:"ghost",disabled:h,onClick:()=>y("cancel"),children:a.cancel}),s.jsx($,{variant:"ink",loading:h,disabled:m===e,onClick:()=>{p()},children:a.save})]}):null]})})]})}const S1=["colors","fonts","logos","tone","dos","donts","photoStyle","guidelines"],yl="__guidelines",cv=e=>e.op==="remove"?e.before:e.after;function C1(e){const t=V();return s.jsx(rt,{open:e.open,onClose:e.onClose,label:t.web.brandReview.dialog,width:1140,children:s.jsx(E1,{...e},e.proposal.id)})}function E1({slug:e,proposal:t,kit:n,guidelines:a,sources:r,onClose:l,onApplied:o,onUndo:c,onChanged:d}){const u=V().web.brandReview,h=i.useMemo(()=>[...t.changes.map(A=>A.id),...t.guidelines?[yl]:[]],[t]),[f,x]=i.useState(()=>new Set(h)),[p,g]=i.useState(null),[b,v]=i.useState(null),[y,w]=i.useState(null),[j,S]=i.useState(!1),k=A=>A==="guidelines"?t.guidelines?[yl]:[]:t.changes.filter(L=>L.field===A).map(L=>L.id),E=S1.filter(A=>k(A).length>0),N=i.useMemo(()=>av(t.summary),[t.summary]),C=h.filter(A=>f.has(A)).length,R=(A,L)=>x(_=>{const X=new Set(_);return L?X.add(A):X.delete(A),X}),P=(A,L)=>x(_=>{const X=new Set(_);for(const ae of k(A))L?X.add(ae):X.delete(ae);return X}),z=sv(r,t.sourceIds),O=[...n.colors,...t.changes.filter(A=>A.field==="colors"&&A.after).map(A=>A.after)],T=async()=>{g("apply"),v(null);const A=f.has(yl),L=t.changes.filter(_=>f.has(_.id));try{const _=await q.applyProposal(e,t.id,L.map(ae=>ae.id),A),X={proposalId:t.id,kit:_.kit,changes:L,guidelines:A&&t.guidelines?{before:a,after:t.guidelines.proposed}:null};o(X),l(),Pe.show(u.applied({count:C}),{tone:"ok",action:{label:u.undo,run:()=>c(X)}})}catch(_){v(pe(_))}finally{g(null)}},W=async()=>{g("discard"),v(null);try{await q.discardProposal(e,t.id),l(),d(),Pe.show(u.discarded)}catch(A){v(pe(A))}finally{g(null)}},Z=A=>{w(A),document.querySelector(`[data-rg="${A}"]`)?.scrollIntoView?.({behavior:"smooth",block:"start"})};return s.jsxs("div",{className:"ms-review",children:[s.jsxs("header",{className:"ms-review-head",children:[s.jsx("span",{className:"ms-bready-icon ms-big","aria-hidden":"true",children:s.jsx(F,{name:"sparkle",size:18})}),s.jsxs("div",{className:"ms-review-title",children:[s.jsx("h2",{children:u.title({hosts:z.length?z.join(", "):u.yourSources})}),s.jsx("span",{className:"ms-muted",children:u.sub({count:h.length})})]}),s.jsx($,{variant:"ghost",icon:!0,"aria-label":u.close,className:"ms-review-close",onClick:l,children:s.jsx(F,{name:"close",size:12,strokeWidth:1.6})})]}),h.length===0?s.jsx("div",{className:"ms-review-nothing",children:s.jsx(Rt,{icon:"check",title:u.nothing,sub:u.nothingSub})}):s.jsxs("div",{className:"ms-review-main",children:[s.jsxs("nav",{className:"ms-review-nav","aria-label":u.groupsLabel,children:[E.map(A=>{const L=k(A),_=L.filter(X=>f.has(X)).length;return s.jsxs("button",{type:"button",className:le("ms-review-group",y===A&&"ms-on"),onClick:()=>Z(A),children:[s.jsx(R1,{g:A,proposal:t,slug:e}),s.jsx("span",{className:"ms-grow ms-ell",children:u.groups[A]}),s.jsx("span",{className:le("ms-review-count",_>0&&_<L.length&&"ms-partial"),children:`${_}/${L.length}`})]},A)}),t.assetsAdded.length?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"ms-review-sep"}),s.jsx("span",{className:"ms-review-assets",children:u.assetsAdded({count:t.assetsAdded.length})})]}):null]}),s.jsxs("div",{className:"ms-review-list",children:[N.text?s.jsx("p",{className:"ms-review-summary",children:N.text}):null,s.jsx(iv,{details:N.details}),E.map(A=>{const L=k(A),_=L.filter(X=>f.has(X)).length;return s.jsx(T1,{g:A,title:u.groups[A],note:u.selected({n:_,m:L.length}),allOn:_===L.length,onAll:X=>P(A,X),children:A==="guidelines"?s.jsx(F1,{proposed:t.guidelines.proposed,replaces:!!t.guidelines.current.trim(),on:f.has(yl),onToggle:X=>R(yl,X)}):s.jsx("div",{className:le("ms-review-grid",`ms-g-${A}`),children:t.changes.filter(X=>X.field===A).map(X=>s.jsx(M1,{c:X,slug:e,palette:O,on:f.has(X.id),onToggle:ae=>R(X.id,ae)},X.id))})},A)})]})]}),s.jsxs("footer",{className:"ms-review-foot",children:[b?s.jsx("span",{className:"ms-bwarn",role:"alert",children:b}):j?null:s.jsx("span",{className:"ms-muted ms-bsmall-text",children:u.footnote}),s.jsx("div",{className:"ms-grow"}),h.length===0?s.jsx($,{variant:"ink",size:"lg",loading:p==="discard",onClick:()=>{W()},children:u.close}):j?s.jsxs("span",{className:"ms-review-confirm",role:"group","aria-label":u.discardAll,children:[s.jsx("span",{className:"ms-bwarn",children:u.confirmDiscard({count:h.length})}),s.jsx($,{variant:"ghost",size:"lg",disabled:p!==null,onClick:()=>S(!1),children:u.keepReviewing}),s.jsx($,{variant:"danger",size:"lg",loading:p==="discard",autoFocus:!0,onClick:()=>{W()},children:u.discardAll})]}):s.jsxs(s.Fragment,{children:[s.jsx($,{variant:"ghost",size:"lg",disabled:p!==null,onClick:()=>S(!0),children:u.discardAll}),s.jsx($,{variant:"ink",size:"lg",loading:p==="apply",disabled:C===0||p!==null,onClick:()=>{T()},children:u.apply({n:C,m:h.length})})]})]})]})}function T1({g:e,title:t,note:n,allOn:a,onAll:r,children:l}){const o=V(),c=i.useId();return s.jsxs("section",{className:"ms-review-sec","data-rg":e,"aria-labelledby":c,children:[s.jsxs("div",{className:"ms-review-sec-head",children:[s.jsx("h3",{id:c,children:t}),s.jsx("span",{className:"ms-muted ms-bsmall-text",children:n}),s.jsx("button",{type:"button",className:"ms-blink-btn ms-bpush",onClick:()=>r(!a),children:a?o.web.brandReview.deselectAll:o.web.brandReview.selectAll})]}),l]})}function R1({g:e,proposal:t,slug:n}){if(e==="colors"){const r=t.changes.filter(l=>l.field==="colors").map(l=>cv(l)?.hex).filter(Boolean).slice(0,3);return s.jsx("span",{className:"ms-review-dots","aria-hidden":"true",children:r.map((l,o)=>s.jsx("i",{style:{background:l}},`${l}${o}`))})}if(e==="logos"){const r=t.changes.find(o=>o.field==="logos"&&o.after),l=r?r.after.file:null;return s.jsx("span",{className:"ms-review-glyph ms-thumb","aria-hidden":"true",children:l?s.jsx("img",{src:q.projectFileUrl(n,l),alt:""}):null})}const a={fonts:"Aa",tone:"“",dos:s.jsx(F,{name:"check",size:12,strokeWidth:2.2}),donts:s.jsx(F,{name:"close",size:11,strokeWidth:2.2}),photoStyle:s.jsx(F,{name:"image",size:13}),guidelines:"¶"};return s.jsx("span",{className:le("ms-review-glyph",e==="dos"&&"ms-ok",e==="donts"&&"ms-warn"),"aria-hidden":"true",children:a[e]})}function oo({source:e}){const t=V();if(!e||e.kind==="manual"||!e.ref)return null;const n=e.kind==="website"?t.web.source.website({host:yc(e.ref)}):e.kind==="codebase"?`${t.web.identity.sourceCodebase} · ${e.ref}`:t.web.source.image({name:e.ref.split("/").pop()??""});return s.jsx("span",{className:"ms-faint ms-bsmall-text ms-ell",title:e.ref,children:n})}function Pl({on:e,label:t,onToggle:n,className:a,children:r}){const l=V();return s.jsxs("div",{className:le("ms-rcard",e&&"ms-on",a),onClick:o=>{o.target.closest("a")||n(!e)},children:[r,s.jsx(Rn,{on:e,label:l.web.brandReview.keep({label:t}),onChange:n,className:"ms-rcard-check"})]})}function co({op:e}){const t=V();return e==="add"?null:s.jsx(tn,{className:le("ms-review-op",e==="remove"&&"ms-remove"),children:t.web.brandReview.ops[e]})}function M1({c:e,slug:t,palette:n,on:a,onToggle:r}){const l=V(),o=l.web.brandReview,c=cv(e);if(!c)return null;const d=c.source;switch(e.field){case"colors":{const m=c,u=e.op==="update"?e.before:null;return s.jsxs(Pl,{on:a,label:m.name,onToggle:r,className:le("ms-rcolor",e.op==="remove"&&"ms-removing"),children:[s.jsxs("span",{className:"ms-rcolor-swatch",children:[u?s.jsx("i",{style:{background:u.hex}}):null,s.jsx("i",{"data-testid":`swatch-${m.id}`,style:{background:m.hex}})]}),s.jsxs("span",{className:"ms-rcard-body",children:[s.jsxs("span",{className:"ms-brow ms-bnowrap",children:[s.jsx("b",{className:"ms-ell",children:m.name}),s.jsx(co,{op:e.op})]}),s.jsx("span",{className:"ms-mono ms-muted",children:`${m.hex.slice(1)} · ${l.web.labels.colorRoles[m.role]}`}),s.jsx(oo,{source:d})]})]})}case"fonts":return s.jsx($1,{c:e,font:c,slug:t,on:a,onToggle:r});case"logos":{const m=c,u=jm(m.background==="dark"?"dark":"light",n),h=m.background==="light"?l.web.brand.logos.onLight:m.background==="dark"?l.web.brand.logos.onDark:l.web.brand.logos.onAny;return s.jsxs(Pl,{on:a,label:m.file,onToggle:r,className:le("ms-rlogo",e.op==="remove"&&"ms-removing"),children:[s.jsx("span",{className:le("ms-rlogo-stage",`ms-bg-${m.background}`),style:u?{background:u}:void 0,children:s.jsx("img",{src:q.projectFileUrl(t,m.file),alt:l.web.brand.logos.alt({file:m.file})})}),s.jsxs("span",{className:"ms-rcard-body",children:[s.jsxs("span",{className:"ms-brow ms-bnowrap",children:[s.jsx("b",{children:l.web.labels.logoVariants[m.variant]}),s.jsx(tn,{children:h}),s.jsx(co,{op:e.op})]}),s.jsx("span",{className:"ms-mono ms-faint ms-ell",title:m.file,children:m.file}),s.jsx(oo,{source:d})]})]})}default:{const m=c,u=e.op==="update"?e.before:null;return s.jsx(Pl,{on:a,label:e.field==="tone"||e.field==="photoStyle"?o.groups[e.field]:m.text,onToggle:r,className:le("ms-rnote",e.op==="remove"&&"ms-removing"),children:s.jsxs("span",{className:"ms-rcard-body",children:[s.jsx("span",{className:le("ms-rnote-text",e.op==="remove"&&"ms-struck"),children:m.text}),u?s.jsx("span",{className:"ms-muted ms-bsmall-text",children:o.replaces({text:u.text})}):null,s.jsxs("span",{className:"ms-brow",children:[s.jsx(co,{op:e.op}),s.jsx(oo,{source:d})]})]})})}}}function $1({c:e,font:t,slug:n,on:a,onToggle:r}){const l=V(),o=l.web.brandReview,c=bc(t.file?q.projectFileUrl(n,t.file):null),d=jc(c);return s.jsx(Pl,{on:a,label:t.family,onToggle:r,className:le("ms-rfont",e.op==="remove"&&"ms-removing"),children:s.jsxs("span",{className:"ms-rcard-body",children:[s.jsx("span",{className:"ms-rfont-specimen",style:{fontFamily:d},children:l.web.brand.fonts.specimen}),s.jsx("span",{className:"ms-rfont-sample",style:{fontFamily:d},children:l.web.brand.fonts.sample}),s.jsxs("span",{className:"ms-brow ms-bnowrap",children:[s.jsx("b",{className:"ms-ell",children:t.family}),s.jsx(tn,{children:l.web.labels.fontRoles[t.role]}),s.jsx(co,{op:e.op})]}),s.jsx("span",{className:"ms-mono ms-muted",children:t.weights.join(" · ")}),c.state==="none"?s.jsx("span",{className:"ms-bnote",children:o.fontNoFile}):null,c.state==="failed"?s.jsx("span",{className:"ms-bnote",children:o.fontFailed}):null,s.jsx(oo,{source:t.source})]})})}function F1({proposed:e,replaces:t,on:n,onToggle:a}){const l=V().web.brandReview;return s.jsx(Pl,{on:n,label:l.groups.guidelines,onToggle:a,className:"ms-rguide",children:s.jsxs("span",{className:"ms-rcard-body",children:[s.jsxs("span",{className:"ms-brow",children:[s.jsx("b",{children:l.useGuidelines}),t?s.jsx(tn,{className:"ms-review-op",children:l.replacesGuidelines}):null]}),s.jsx("div",{className:"ms-rguide-doc",children:s.jsx(Ro,{text:e,headings:!0})})]})})}const dv=2**31-1,P1=6e4,A1=5e3;function uv(e,t=Date.now){const[n,a]=i.useState(0);return i.useEffect(()=>{if(!e)return;const r=Math.min(dv,Math.max(A1,e-t()-P1)),l=setTimeout(()=>a(o=>o+1),r);return()=>clearTimeout(l)},[e,t]),n}const L1=300,I1=24,z1=["Sans Serif","Serif","Display","Handwriting","Monospace"],O1=["heading","body","accent","other"];function D1({f:e,selected:t,onPick:n}){const r=V().web.brand.fonts.google,l=bc(e.previewUrl);return s.jsxs("button",{type:"button",className:le("ms-gf-row",t&&"ms-on"),"aria-pressed":t,onClick:n,children:[s.jsx("span",{className:"ms-gf-name",style:{fontFamily:jc(l)},children:e.family}),s.jsxs("span",{className:"ms-gf-meta ms-muted",children:[e.category?r.categories[e.category]??e.category:"",e.variable?` · ${r.variable}`:"",l.state==="failed"?` · ${r.previewFailed}`:""]})]})}function B1({open:e,slug:t,locked:n,onClose:a,onAdded:r}){const l=V(),o=l.web.brand.fonts.google,[c,d]=i.useState(""),[m,u]=i.useState(""),[h,f]=i.useState(null),[x,p]=i.useState(null),[g,b]=i.useState(!1),[v,y]=i.useState(null),[w,j]=i.useState([]),[S,k]=i.useState(!1),[E,N]=i.useState("body"),[C,R]=i.useState(!1),P=i.useRef(0),z=i.useRef(0),O=uv(h?.previewExpiresAt);i.useEffect(()=>{if(!e)return;const A=++P.current;b(!0);const L=setTimeout(()=>{Promise.resolve().then(()=>q.searchGoogleFonts({q:c.trim(),category:m,limit:I1})).then(_=>{P.current===A&&(f(_),p(null),b(!1))},_=>{P.current===A&&(p(pe(_)),b(!1))})},c&&O===z.current?L1:0);return z.current=O,()=>clearTimeout(L)},[e,c,m,O]);const T=A=>{y(A),j(A.weights.includes(400)?[400]:[A.weights[0]]),k(!1)},W=(A,L)=>j(_=>(L?[..._,A]:_.filter(X=>X!==A)).sort((X,ae)=>X-ae)),Z=async()=>{if(!(!v||!w.length)){R(!0);try{const{font:A,updated:L}=await q.addGoogleFont(t,{family:v.family,weights:w,italic:S&&v.italic,role:E});r(A),Pe.show(L?o.updated({family:A.family}):o.added({family:A.family}),{tone:"ok"}),a()}catch(A){Pe.show(o.addFailed({error:pe(A)}))}finally{R(!1)}}};return s.jsx(rt,{open:e,onClose:a,label:o.title,width:760,children:s.jsxs("div",{className:"ms-gf",children:[s.jsx("h2",{className:"ms-gf-title",children:o.title}),s.jsxs("div",{className:"ms-gf-bar",children:[s.jsx(ms,{value:c,"aria-label":o.search,placeholder:o.searchHint,onChange:A=>d(A.target.value),autoFocus:!0}),s.jsx(At,{value:m,label:o.category,onChange:u,options:[{value:"",label:o.categoryAll},...z1.map(A=>({value:A,label:o.categories[A]}))]})]}),h?.fallback?s.jsx("p",{className:"ms-bnote",role:"status",children:o.fallback}):null,h?.stale&&!h.fallback?s.jsx("p",{className:"ms-bnote",role:"status",children:o.stale}):null,x?s.jsx("p",{className:"ms-bwarn",role:"alert",children:o.failed({error:x})}):null,s.jsxs("div",{className:"ms-gf-body",children:[s.jsxs("div",{className:"ms-gf-list",role:"group","aria-label":o.results,"aria-busy":g,children:[g&&!h?s.jsx(Ts,{size:16}):null,h&&!h.families.length&&!g?s.jsx("p",{className:"ms-bempty-line",children:o.empty}):null,h?.families.map(A=>s.jsx(D1,{f:A,selected:A.family===v?.family,onPick:()=>T(A)},A.family))]}),s.jsx("div",{className:"ms-gf-side",children:v?s.jsxs(s.Fragment,{children:[s.jsx("b",{children:v.family}),s.jsxs("div",{className:"ms-bpop-field",children:[s.jsx("span",{children:o.weights}),s.jsx("div",{className:"ms-gf-weights",children:v.weights.map(A=>s.jsxs("label",{className:"ms-gf-weight",children:[s.jsx(Rn,{on:w.includes(A),onChange:L=>W(A,L),label:o.weight({weight:A})}),s.jsx("span",{className:"ms-mono",children:A})]},A))})]}),v.italic?s.jsxs("div",{className:"ms-gf-weight",children:[s.jsx(Un,{on:S,onChange:k,label:o.italic,size:"sm"}),s.jsx("span",{children:o.italic})]}):null,s.jsxs("div",{className:"ms-bpop-field",children:[s.jsx("span",{children:o.role}),s.jsx(At,{value:E,label:o.role,onChange:A=>N(A),options:O1.map(A=>({value:A,label:l.web.labels.fontRoles[A]}))})]}),s.jsx("small",{className:"ms-muted",children:o.license}),s.jsx($,{variant:"accent",disabled:n||C||!w.length,onClick:()=>{Z()},children:C?o.adding:o.add})]}):s.jsx("p",{className:"ms-muted",children:o.choose})})]}),s.jsx("div",{className:"ms-gf-foot",children:s.jsx($,{variant:"ghost",onClick:a,children:o.close})})]})})}const U1=300,_1=["elevenlabs","openai"];function q1({open:e,value:t,onClose:n,onPick:a}){const l=V().web.brand.sound.picker,[o,c]=i.useState(t?.provider??"elevenlabs"),[d,m]=i.useState(""),[u,h]=i.useState(null),[f,x]=i.useState(null),[p,g]=i.useState(!1),[b,v]=i.useState(null),y=i.useRef(null),w=i.useRef(0),j=i.useRef(0),S=uv(u?.previewExpiresAt),k=()=>{const R=y.current;y.current=null,R&&(R.pause(),R.removeAttribute("src")),v(null)};i.useEffect(()=>(e||k(),k),[e]),i.useEffect(()=>{if(!e)return;const R=++w.current;g(!0);const P=setTimeout(()=>{Promise.resolve().then(()=>q.listVoices({provider:o,q:d.trim()})).then(z=>{w.current===R&&(h(z),x(null),g(!1))},z=>{w.current===R&&(h(null),x(pe(z)),g(!1))})},d&&S===j.current?U1:0);return j.current=S,()=>clearTimeout(P)},[e,o,d,S]);const E=(R,P)=>{if(b===R){k();return}k();const z=new Audio(P);y.current=z,v(R);const O=()=>{y.current===z&&(k(),Pe.show(l.previewFailed))};z.addEventListener("ended",()=>{y.current===z&&k()}),z.addEventListener("error",O),Promise.resolve(z.play()).catch(O)},N=R=>{k(),h(null),c(R)},C=u!==null&&!u.configured;return s.jsx(rt,{open:e,onClose:n,label:l.title,width:620,children:s.jsxs("div",{className:"ms-gf ms-vp",children:[s.jsx("h2",{className:"ms-gf-title",children:l.title}),s.jsxs("div",{className:"ms-vp-bar",children:[s.jsx(it,{value:o,label:l.provider,onChange:N,options:_1.map(R=>({value:R,label:l.providers[R]}))}),s.jsx(ms,{value:d,"aria-label":l.search,placeholder:l.searchHint,disabled:C,onChange:R=>m(R.target.value),autoFocus:!0})]}),C?s.jsxs("p",{className:"ms-bnote ms-vp-nokey",role:"status",children:[l.noKey({provider:l.providers[o]})," ",s.jsx("a",{href:es.settings("paid"),onClick:n,children:l.openSettings})]}):null,o==="openai"&&u&&!C?s.jsx("p",{className:"ms-bnote",children:l.openaiNote}):null,f?s.jsx("p",{className:"ms-bwarn",role:"alert",children:l.failed({error:f})}):null,s.jsxs("div",{className:"ms-vp-list",role:"group","aria-label":l.results,"aria-busy":p,children:[p&&!u?s.jsx(Ts,{size:16}):null,u&&!C&&!u.voices.length&&!p?s.jsx("p",{className:"ms-bempty-line",children:l.empty}):null,C?null:u?.voices.map(R=>{const P=t?.provider===o&&t.id===R.id,z=Object.values(R.labels).filter(Boolean).slice(0,4).join(" · ");return s.jsxs("div",{className:le("ms-vp-row",P&&"ms-on"),children:[s.jsxs("button",{type:"button",className:"ms-vp-pick","aria-pressed":P,"aria-label":l.use({name:R.name}),onClick:()=>a({provider:o,id:R.id,name:R.name}),children:[s.jsx("b",{className:"ms-ell",children:R.name}),z?s.jsx("span",{className:"ms-muted ms-ell",children:z}):null,P?s.jsx("span",{className:"ms-bok",children:l.selected}):null]}),R.previewUrl?s.jsx($,{variant:"ghost",size:"sm",icon:!0,"aria-label":b===R.id?l.stop({name:R.name}):l.play({name:R.name}),onClick:()=>E(R.id,R.previewUrl),children:s.jsx(F,{name:b===R.id?"pause":"play",size:13})}):s.jsx("span",{className:"ms-faint ms-vp-nop",children:l.noPreview})]},R.id)})]}),s.jsx("div",{className:"ms-gf-foot",children:s.jsx($,{variant:"ghost",onClick:n,children:l.close})})]})})}const V1=["primary","secondary","accent","background","text","other"];function K1(){const t=V().web.brand,{kit:n,locked:a,saver:r}=Gt(),[l,o]=i.useState(null),c=()=>{const d=wc("color",n.colors.map(m=>m.id));r.edit(m=>({...m,colors:[...m.colors,{id:d,name:t.colors.newName,hex:"#A3A3A3",role:"other",source:rr}]})),o(d)};return s.jsxs("section",{"data-sec":"colors",className:"ms-bsection","aria-labelledby":"ms-bcolors","data-enter":!0,children:[s.jsxs("div",{className:"ms-bsection-head",children:[s.jsx("h2",{id:"ms-bcolors",children:t.nav.colors}),n.colors.length?s.jsx("span",{className:"ms-faint",children:t.colors.hint}):null,s.jsx($,{variant:"ghost",size:"sm",className:"ms-blink",disabled:a,onClick:c,children:t.colors.add})]}),n.colors.length?s.jsx("div",{className:"ms-bswatches",children:n.colors.map(d=>s.jsx(W1,{c:d,autoOpen:l===d.id},d.id))}):s.jsx("p",{className:"ms-bempty-line",children:t.colors.empty})]})}function W1({c:e,autoOpen:t}){const n=V(),a=n.web.brand,{kit:r,locked:l,saver:o}=Gt(),c=i.useRef(null),d=i.useRef(null),[m,u]=i.useState(t),[h,f]=i.useState(e.name),[x,p]=i.useState(e.hex.slice(1));ii(c),i.useEffect(()=>{m||(f(e.name),p(e.hex.slice(1)))},[e.name,e.hex,m]);const g=qS(e.hex,r.colors),b=(j,S=0)=>o.edit(k=>({...k,colors:k.colors.map(E=>E.id===e.id?{...E,...j,source:rr}:E)}),S),v=()=>{u(!1),o.flush()},y=nd(x)!==null,w=()=>{u(!1);const j=r.colors.findIndex(S=>S.id===e.id);kc(c.current,()=>{o.edit(S=>({...S,colors:S.colors.filter(k=>k.id!==e.id)})),Pe.show(a.colors.removed({name:e.name}),{action:{label:a.undo,run:()=>o.edit(S=>S.colors.some(k=>k.id===e.id)?S:{...S,colors:[...S.colors.slice(0,j),e,...S.colors.slice(j)]})}})})};return s.jsxs("div",{className:"ms-bswatch-wrap",ref:c,children:[s.jsxs("button",{ref:d,type:"button",className:le("ms-bswatch",m&&"ms-on"),"aria-label":a.colors.edit({name:e.name}),"aria-expanded":m,onClick:()=>m?v():u(!0),children:[s.jsx("span",{className:"ms-bswatch-color",style:{background:e.hex},children:s.jsx("span",{className:"ms-bswatch-aa",style:{color:g.color},title:a.colors.contrast({ratio:Ef(g.ratio),name:g.name??g.color}),children:`Aa ${Ef(g.ratio)}`})}),s.jsxs("span",{className:"ms-bswatch-meta",children:[s.jsx("b",{children:e.name}),s.jsx("span",{className:"ms-mono",children:e.hex.slice(1)}),s.jsx("span",{className:"ms-faint",children:n.web.labels.colorRoles[e.role]})]})]}),s.jsx(ot,{open:m,onClose:v,anchor:d,width:250,children:s.jsxs("div",{className:"ms-bpop",children:[s.jsx("span",{className:"ms-cap",children:a.colors.popTitle}),s.jsxs("label",{className:"ms-bpop-field",children:[s.jsx("span",{children:a.colors.name}),s.jsx(ms,{value:h,disabled:l,"aria-label":a.colors.name,"aria-invalid":!h.trim()||void 0,onChange:j=>{f(j.target.value),j.target.value.trim()&&b({name:j.target.value.trim()},lo)}})]}),s.jsxs("div",{className:"ms-bpop-field",children:[s.jsx("span",{children:a.colors.hex}),s.jsxs("div",{className:"ms-bhex",children:[s.jsx(Hx,{size:22,value:nd(x)??e.hex,disabled:l,onPick:j=>{p(j.slice(1).toUpperCase()),b({hex:j},lo)}}),s.jsx(bw,{prefix:"#",className:"ms-grow",children:s.jsx("input",{value:x,maxLength:7,disabled:l,"aria-label":a.colors.hex,"aria-invalid":!y||void 0,spellCheck:!1,onChange:j=>{const S=j.target.value.replace(/[^0-9a-fA-F#]/g,"").replace(/^#/,"").toUpperCase();p(S);const k=nd(S);k&&b({hex:k},lo)}})})]}),y?null:s.jsx("small",{className:"ms-bwarn",children:a.colors.hexInvalid})]}),s.jsxs("div",{className:"ms-bpop-field",children:[s.jsx("span",{children:a.colors.role}),s.jsx("div",{className:"ms-bchips",children:V1.map(j=>s.jsx(sn,{on:e.role===j,onClick:l?void 0:()=>b({role:j}),children:n.web.labels.colorRoles[j]},j))})]}),s.jsxs($,{variant:"danger",size:"sm",disabled:l,onClick:w,children:[s.jsx(F,{name:"trash",size:13}),a.colors.remove]})]})})]})}function H1(){const t=V().web.brand,{kit:n,locked:a,saver:r,slug:l,reloadAssets:o}=Gt(),[c,d]=i.useState(null),[m,u]=i.useState(!1),h=x=>{r.edit(p=>p.fonts.some(g=>g.id===x.id)?{...p,fonts:p.fonts.map(g=>g.id===x.id?x:g)}:{...p,fonts:[...p.fonts,x]}),o(),d(null)},f=()=>{const x=wc("font",n.fonts.map(p=>p.id));r.edit(p=>({...p,fonts:[...p.fonts,{id:x,family:t.fonts.newFamily,role:"body",weights:[400],file:null,source:rr}]})),d(x)};return s.jsxs("section",{"data-sec":"type",className:"ms-bsection","aria-labelledby":"ms-btype","data-enter":!0,children:[s.jsxs("div",{className:"ms-bsection-head",children:[s.jsx("h2",{id:"ms-btype",children:t.nav.type}),s.jsx("span",{className:"ms-faint",children:t.fonts.hint}),s.jsxs("span",{className:"ms-bsection-actions",children:[s.jsx($,{variant:"ghost",size:"sm",className:"ms-blink",disabled:a,onClick:()=>u(!0),children:t.fonts.addGoogle}),s.jsx($,{variant:"ghost",size:"sm",className:"ms-blink",disabled:a,onClick:f,children:t.fonts.add})]})]}),s.jsx(B1,{open:m,slug:l,locked:a,onClose:()=>u(!1),onAdded:h}),n.fonts.length?s.jsx("div",{className:"ms-bfonts",children:n.fonts.map(x=>s.jsx(G1,{f:x,autoOpen:c===x.id},x.id))}):s.jsx("p",{className:"ms-bempty-line",children:t.fonts.empty})]})}function G1({f:e,autoOpen:t}){const n=V(),a=n.web.brand,{slug:r}=Gt(),l=i.useRef(null),o=i.useRef(null),[c,d]=i.useState(t);ii(l);const m=bc(e.file?q.projectFileUrl(r,e.file):null),u=jc(m);return s.jsxs("div",{className:"ms-card ms-bfont",ref:l,children:[s.jsxs("div",{className:"ms-bfont-top",children:[s.jsx(tn,{children:n.web.labels.fontRoles[e.role]}),e.file?s.jsx("span",{className:"ms-bok",children:a.fonts.inProject}):s.jsx("span",{className:"ms-bwarn",children:a.fonts.noFile})]}),s.jsx("span",{className:"ms-bfont-specimen",style:{fontFamily:u},children:a.fonts.specimen}),s.jsx("span",{className:"ms-bfont-sample",style:{fontFamily:u},children:a.fonts.sample}),m.state==="none"?s.jsx("span",{className:"ms-bnote",children:a.fonts.noPreview}):null,m.state==="failed"?s.jsx("span",{className:"ms-bnote",children:a.fonts.loadFailed}):null,s.jsxs("div",{className:"ms-bfont-foot",children:[s.jsx("b",{className:"ms-ell",children:e.family}),s.jsx("span",{className:"ms-mono ms-muted",children:e.weights.join(" · ")}),s.jsx("button",{ref:o,type:"button",className:"ms-blink-btn","aria-label":a.fonts.edit({family:e.family}),"aria-expanded":c,onClick:()=>d(!c),children:n.web.brand.voice.edit})]}),s.jsx(X1,{f:e,open:c,onClose:()=>d(!1),anchor:o,wrap:l})]})}function X1({f:e,open:t,onClose:n,anchor:a,wrap:r}){const l=V(),o=l.web.brand,{kit:c,locked:d,saver:m,assets:u}=Gt(),[h,f]=i.useState(e.family),[x,p]=i.useState(e.weights.join(", ")),[g,b]=i.useState(null);i.useEffect(()=>{t||(f(e.family),p(e.weights.join(", ")),b(null))},[t,e.family,e.weights]);const v=N=>m.edit(C=>({...C,fonts:C.fonts.map(R=>R.id===e.id?{...R,...N,source:rr}:R)})),y=()=>{const N=h.trim(),C=_S(N);C&&(b(C!==N?o.fonts.familyNormalized({family:C}):null),f(C),C!==e.family&&v({family:C}))},w=()=>{const N=JS(x);N&&N.join()!==e.weights.join()&&v({weights:N}),p((N??e.weights).join(", "))},j=()=>{y(),w(),n()},S=u.filter(N=>N.kind==="font"),k=[{value:"",label:o.fonts.noFileOption},...S.map(N=>({value:`assets/${N.file}`,label:N.file}))];e.file&&!k.some(N=>N.value===e.file)&&k.push({value:e.file,label:e.file});const E=()=>{n();const N=c.fonts.findIndex(C=>C.id===e.id);kc(r.current,()=>{m.edit(C=>({...C,fonts:C.fonts.filter(R=>R.id!==e.id)})),Pe.show(o.fonts.removed({family:e.family}),{action:{label:o.undo,run:()=>m.edit(C=>C.fonts.some(R=>R.id===e.id)?C:{...C,fonts:[...C.fonts.slice(0,N),e,...C.fonts.slice(N)]})}})})};return s.jsx(ot,{open:t,onClose:j,anchor:a,width:280,placement:"bottom-end",children:s.jsxs("form",{className:"ms-bpop",onSubmit:N=>{N.preventDefault(),y(),w()},children:[s.jsx("span",{className:"ms-cap",children:o.fonts.popTitle}),s.jsxs("label",{className:"ms-bpop-field",children:[s.jsx("span",{children:o.fonts.family}),s.jsx(ms,{value:h,disabled:d,"aria-label":o.fonts.family,"aria-invalid":!h.trim()||void 0,onChange:N=>{f(N.target.value),b(null)},onBlur:y}),h.trim()?g?s.jsx("small",{className:"ms-bnote",role:"status",children:g}):null:s.jsx("small",{className:"ms-bwarn",children:o.fonts.familyRequired})]}),s.jsxs("div",{className:"ms-bpop-field",children:[s.jsx("span",{children:o.fonts.role}),s.jsx(At,{disabled:d,value:e.role,label:o.fonts.role,onChange:N=>v({role:N}),options:Object.keys(l.web.labels.fontRoles).map(N=>({value:N,label:l.web.labels.fontRoles[N]}))})]}),s.jsxs("label",{className:"ms-bpop-field",children:[s.jsx("span",{children:o.fonts.weights}),s.jsx(ms,{value:x,disabled:d,"aria-label":o.fonts.weights,placeholder:o.fonts.weightsHint,onChange:N=>p(N.target.value),onBlur:w})]}),s.jsxs("div",{className:"ms-bpop-field",children:[s.jsx("span",{children:o.fonts.file}),s.jsx(At,{disabled:d,value:e.file??"",label:o.fonts.file,onChange:N=>v({file:N||null}),options:k}),S.length?null:s.jsx("small",{className:"ms-bnote",children:o.fonts.noFontAssets})]}),s.jsxs($,{variant:"danger",size:"sm",disabled:d,onClick:E,children:[s.jsx(F,{name:"trash",size:13}),o.fonts.remove]})]})})}function Z1({uploading:e}){const n=V().web.brand,{kit:a,locked:r,upload:l}=Gt(),o=i.useRef(null),[c,d]=i.useState(!1),m=["light","dark"].filter(u=>!Qg(a,u));return s.jsxs("section",{"data-sec":"logos",className:"ms-bsection","aria-labelledby":"ms-blogos","data-enter":!0,children:[s.jsxs("div",{className:"ms-bsection-head",children:[s.jsx("h2",{id:"ms-blogos",children:n.nav.logos}),e?s.jsxs("span",{className:"ms-faint ms-brow",children:[s.jsx(Ts,{decorative:!0,size:12}),n.logos.uploading]}):null,s.jsx($,{ref:o,variant:"ghost",size:"sm",className:"ms-blink",disabled:r,"aria-expanded":c,onClick:()=>d(!c),children:n.logos.add}),s.jsx(mv,{open:c,onClose:()=>d(!1),anchor:o,background:"any"})]}),s.jsxs("div",{className:"ms-blogos",children:[a.logos.map(u=>s.jsx(Y1,{l:u},u.id)),m.map(u=>s.jsx(J1,{bg:u,disabled:r||e,onUpload:()=>l(u)},u))]})]})}function J1({bg:e,disabled:t,onUpload:n}){const r=V().web.brand,l=i.useRef(null),[o,c]=i.useState(!1);return s.jsxs("div",{className:"ms-blogo-missing",children:[s.jsx("b",{children:e==="light"?r.logos.missingLight:r.logos.missingDark}),s.jsx("span",{children:e==="light"?r.logos.missingLightSub:r.logos.missingDarkSub}),s.jsxs("span",{className:"ms-brow",children:[s.jsxs($,{size:"sm",variant:"outline",disabled:t,onClick:n,children:[s.jsx(F,{name:"upload",size:13}),r.logos.uploadLogo]}),s.jsx($,{ref:l,size:"sm",variant:"ghost",disabled:t,"aria-expanded":o,onClick:()=>c(!o),children:r.logos.fromAssets})]}),s.jsx(mv,{open:o,onClose:()=>c(!1),anchor:l,background:e})]})}function mv({open:e,onClose:t,anchor:n,background:a}){const l=V().web.brand,{slug:o,kit:c,assets:d,upload:m,addLogoFromAsset:u}=Gt(),h=d.filter(f=>(f.kind==="image"||f.kind==="svg")&&!c.logos.some(x=>x.file===`assets/${f.file}`));return s.jsx(ot,{open:e,onClose:t,anchor:n,width:280,placement:"bottom-end",children:s.jsxs("div",{className:"ms-bpop ms-bpicker",children:[s.jsxs("button",{type:"button",className:"ms-bmenu-row","data-row":!0,onClick:()=>{t(),m(a)},children:[s.jsx(F,{name:"upload",size:14}),l.logos.upload]}),s.jsx("span",{className:"ms-cap",children:l.logos.fromAssets}),h.length?s.jsx("div",{className:"ms-bpicker-list",children:h.map(f=>s.jsxs("button",{type:"button",className:"ms-bmenu-row","data-row":!0,onClick:()=>{t(),u(`assets/${f.file}`,a)},children:[s.jsx("img",{src:q.projectFileUrl(o,`assets/${f.file}`),alt:""}),s.jsx("span",{className:"ms-ell",children:f.file})]},f.file))}):s.jsx("span",{className:"ms-bnote",children:l.logos.noAssets})]})})}function Y1({l:e}){const t=V(),n=t.web.brand,{slug:a,kit:r,locked:l,saver:o}=Gt(),c=i.useRef(null),d=i.useRef(null),[m,u]=i.useState(!1);ii(c);const h=jm(e.background==="dark"?"dark":"light",r.colors),f=g=>o.edit(b=>({...b,logos:b.logos.map(v=>v.id===e.id?{...v,...g,source:rr}:v)})),x=()=>{u(!1);const g=r.logos.findIndex(b=>b.id===e.id);kc(c.current,()=>{o.edit(b=>({...b,logos:b.logos.filter(v=>v.id!==e.id)})),Pe.show(n.logos.removed,{action:{label:n.undo,run:()=>o.edit(b=>b.logos.some(v=>v.id===e.id)?b:{...b,logos:[...b.logos.slice(0,g),e,...b.logos.slice(g)]})}})})},p=e.background==="light"?n.logos.onLight:e.background==="dark"?n.logos.onDark:n.logos.onAny;return s.jsxs("div",{className:"ms-card ms-blogo",ref:c,children:[s.jsx("button",{ref:d,type:"button",className:le("ms-blogo-stage",`ms-bg-${e.background}`),style:h?{background:h}:void 0,"aria-label":n.logos.edit({file:e.file}),"aria-expanded":m,onClick:()=>u(!m),children:s.jsx("img",{src:q.projectFileUrl(a,e.file),alt:n.logos.alt({file:e.file})})}),s.jsxs("div",{className:"ms-blogo-meta",children:[s.jsxs("span",{className:"ms-brow",children:[s.jsx("b",{children:t.web.labels.logoVariants[e.variant]}),s.jsx(tn,{children:p})]}),s.jsx("span",{className:"ms-mono ms-faint ms-ell",title:e.file,children:e.file})]}),s.jsx(ot,{open:m,onClose:()=>u(!1),anchor:d,width:260,children:s.jsxs("div",{className:"ms-bpop",children:[s.jsx("span",{className:"ms-cap",children:n.logos.popTitle}),s.jsxs("div",{className:"ms-bpop-field",children:[s.jsx("span",{children:n.logos.variant}),s.jsx(At,{disabled:l,value:e.variant,label:n.logos.variant,onChange:g=>f({variant:g}),options:Object.keys(t.web.labels.logoVariants).map(g=>({value:g,label:t.web.labels.logoVariants[g]}))})]}),s.jsxs("div",{className:"ms-bpop-field",children:[s.jsx("span",{children:n.logos.background}),s.jsx(it,{value:e.background,label:n.logos.background,disabled:l,onChange:g=>f({background:g}),options:["light","dark","any"].map(g=>({value:g,label:t.web.labels.logoBackgrounds[g]}))})]}),s.jsxs($,{variant:"danger",size:"sm",disabled:l,onClick:x,children:[s.jsx(F,{name:"trash",size:13}),n.logos.remove]})]})})]})}const Q1=20,Mf=60,eC=["low","medium","high"];function $f({label:e,placeholder:t,items:n,locked:a,onChange:r}){const l=V().web.brand.sound,[o,c]=i.useState(""),d=n.length>=Q1,m=u=>{u.preventDefault();const h=o.trim().slice(0,Mf);!h||d||(n.some(f=>f.toLowerCase()===h.toLowerCase())||r([...n,h]),c(""))};return s.jsxs("div",{className:"ms-bpop-field",children:[s.jsx("span",{id:`ms-bsl-${e}`,children:e}),n.length?s.jsx("ul",{className:"ms-bchips ms-bsound-chips","aria-labelledby":`ms-bsl-${e}`,children:n.map(u=>s.jsx("li",{children:s.jsxs(sn,{children:[u,s.jsx("button",{type:"button",className:"ms-bsound-x",disabled:a,"aria-label":l.remove({text:u}),onClick:()=>r(n.filter(h=>h!==u)),children:s.jsx(F,{name:"close",size:10})})]})},u))}):s.jsx("span",{className:"ms-faint",children:l.none}),s.jsxs("form",{className:"ms-brow",onSubmit:m,children:[s.jsx(ms,{className:"ms-grow ms-bsmall",value:o,disabled:a||d,"aria-label":e,placeholder:t,maxLength:Mf,onChange:u=>c(u.target.value)}),s.jsx($,{type:"submit",variant:"ink",size:"sm",disabled:a||d||!o.trim(),children:l.add})]}),d?s.jsx("small",{className:"ms-bnote",children:l.full}):null]})}function sC(){const t=V().web.brand,n=t.sound,{kit:a,locked:r,saver:l}=Gt(),o=a.sound??yo,[c,d]=i.useState(o.genre),[m,u]=i.useState(!1);i.useEffect(()=>{d(o.genre)},[o.genre]);const h=(p,g=0)=>l.edit(b=>({...b,sound:{...b.sound??yo,...p}}),g),f={none:n.energyNone,low:n.energyLow,medium:n.energyMedium,high:n.energyHigh},x=o.voice;return s.jsxs("section",{"data-sec":"sound",className:"ms-card ms-bcard ms-bsound","aria-labelledby":"ms-bsound","data-enter":!0,children:[s.jsxs("div",{className:"ms-bsection-head",children:[s.jsx("h2",{id:"ms-bsound",children:t.nav.sound}),s.jsx("span",{className:"ms-faint",children:n.hint})]}),s.jsxs("div",{className:"ms-bpop-field",children:[s.jsx("span",{children:n.genre}),s.jsx(ms,{value:c,disabled:r,maxLength:200,"aria-label":n.genre,placeholder:n.genrePlaceholder,onChange:p=>{d(p.target.value),h({genre:p.target.value.trim()},lo)},onBlur:()=>l.flush()}),s.jsx("div",{className:"ms-bchips",role:"group","aria-label":n.genreSuggestions,children:rv.map(p=>s.jsx(sn,{on:nu(o.genre)===p,onClick:r?void 0:()=>{const b=nu(o.genre)===p?"":ym[p];d(b),h({genre:b})},children:n.genreOptions[p]},p))})]}),s.jsxs("div",{className:"ms-bpop-field",children:[s.jsx("span",{children:n.energy}),s.jsx(it,{value:o.energy??"none",label:n.energy,disabled:r,onChange:p=>h({energy:p==="none"?null:p}),options:["none",...eC].map(p=>({value:p,label:f[p]}))})]}),s.jsx($f,{label:n.instruments,placeholder:n.instrumentsPlaceholder,items:o.instruments,locked:r,onChange:p=>h({instruments:p})}),s.jsx($f,{label:n.avoid,placeholder:n.avoidPlaceholder,items:o.avoid,locked:r,onChange:p=>h({avoid:p})}),s.jsxs("div",{className:"ms-bpop-field",children:[s.jsx("span",{children:n.voice}),s.jsxs("div",{className:"ms-brow",children:[x?s.jsx("b",{className:"ms-ell",children:n.voiceOf({provider:n.picker.providers[x.provider],name:x.name??x.id})}):s.jsx("span",{className:"ms-faint",children:n.noVoice}),s.jsx($,{variant:"outline",size:"sm",disabled:r,onClick:()=>u(!0),children:x?n.changeVoice:n.chooseVoice}),x?s.jsx($,{variant:"ghost",size:"sm",disabled:r,onClick:()=>h({voice:null}),children:n.clearVoice}):null]})]}),s.jsx(q1,{open:m,value:x,onClose:()=>u(!1),onPick:p=>{h({voice:p}),u(!1)}})]})}const Zl=.1,au=e=>Math.round(e*1e3)/1e3,zi=e=>Math.min(1,Math.max(0,e));function Oi(e,t){for(const n of e.tracks)for(const a of n.clips)if(a.id===t)return a;return null}function ru(e,t){const n=[];for(const a of e.tracks)for(const r of a.clips)t>=r.start-1e-6&&t<=r.start+r.duration+1e-6&&n.push(r);return n}const km=e=>e.name??e.id;function tC(e,t,n){if(n?.bounds&&n.scale>0&&e.width>0&&e.height>0){const m=n.bounds;return{x:zi((m.x+m.width/2)/n.scale/e.width),y:zi((m.y+m.height/2)/n.scale/e.height)}}const a="props"in t?t.props:{},r=m=>typeof a[m]=="number"&&Number.isFinite(a[m])?a[m]:null,[l,o,c,d]=[r("x"),r("y"),r("width"),r("height")];return l!==null&&o!==null&&c!==null&&d!==null&&e.width>0&&e.height>0?{x:zi((l+c/2)/e.width),y:zi((o+d/2)/e.height)}:{x:.5,y:.5}}function uo(e){const t=tC(e.comp,e.clip,e.drawn);return{format:e.format,x:t.x,y:t.y,timeSec:au(e.time),clipId:e.clip.id,clipName:wo(km(e.clip)),...e.note?{note:e.note}:{}}}function hv(e){const t=au(Math.max(0,Math.min(e.start,e.end))),n=au(Math.min(e.duration,Math.max(e.start,e.end)));return n-t<Zl?null:{format:e.format,x:.5,y:.5,timeSec:t,range:{start:t,end:n},...e.note?{note:e.note}:{}}}const Ff=(e,t)=>Vs(e,t,{minimumFractionDigits:1,maximumFractionDigits:1}),br=(e,t)=>({a:Ff(e,t.start),b:Ff(e,t.end)});function nC(e,t,n,a){const r=n.web.conversation,l=e.clipName??e.clipId;return e.clipId&&e.animation?(e.animation==="in"?r.chipClipAnimIn:r.chipClipAnimOut)({format:t,name:l}):e.clipId&&e.element?r.chipClipElement({format:t,name:l,element:e.element.name}):e.clipId&&e.range?r.chipClipRange({format:t,name:l,...br(a,e.range)}):e.clipId?r.chipClip({format:t,name:l}):e.range?r.chipRange({format:t,...br(a,e.range)}):null}const aC=(e,t,n)=>{const{a,b:r}=br(t,n);return e.web.canvas.seconds({n:`${a}–${r}`})},Nm={approvals:{},jobs:{},events:{},creativeTicks:{},projectTicks:{}},Pf=2e3,rC=new Set(["succeeded","failed","cancelled"]);function Af(e,t){if(!e.liveUsage||!(t in e.liveUsage))return e.liveUsage;const{[t]:n,...a}=e.liveUsage;return a}function lC(e,t){if(!e.ready||!(t in e.ready))return e.ready;const{[t]:n,...a}=e.ready;return a}function iC(e,t){switch(t.type){case"usage-today":return c0(e,t);case"snapshot":return{...e,snapshots:(e.snapshots??0)+1,jobs:Object.fromEntries(t.jobs.map(n=>[n.id,n])),liveUsage:Object.fromEntries(Object.entries(e.liveUsage??{}).filter(([n])=>t.jobs.some(a=>a.id===n&&a.state==="running"))),jobUsage:d0(e.jobUsage,new Set(t.jobs.map(n=>n.id))),ready:Object.fromEntries(Object.entries(t.ready??e.ready??{}).filter(([n])=>t.jobs.some(a=>a.id===n&&a.state==="running"))),partialUsage:u0(e.partialUsage,t.jobs),approvals:Object.fromEntries((t.approvals??[]).map(n=>[n.id,n])),language:t.locale?{locale:t.locale,setting:t.languageSetting??"system",systemLocale:t.systemLocale??t.locale}:e.language,creativeTicks:Object.fromEntries(Object.entries(e.creativeTicks).map(([n,a])=>[n,a+1])),projectTicks:Object.fromEntries(Object.entries(e.projectTicks).map(([n,a])=>[n,a+1]))};case"locale":return{...e,language:{locale:t.locale,setting:t.setting,systemLocale:t.systemLocale}};case"approval":return{...e,approvals:{...e.approvals,[t.approval.id]:t.approval}};case"approval_resolved":{const{[t.id]:n,...a}=e.approvals;return{...e,approvals:a}}case"job":return{...e,jobs:{...e.jobs,[t.job.id]:t.job},...rC.has(t.job.state)?{liveUsage:Af(e,t.job.id),ready:lC(e,t.job.id)}:{}};case"formatReady":{const{[t.format]:n,...a}=e.ready?.[t.jobId]??{},r=t.hash===null?a:{...a,[t.format]:{n:t.n,hash:t.hash}};return{...e,ready:{...e.ready,[t.jobId]:r}}}case"agent":{const n=t.event;if(n.kind==="usage"&&n.live)return gf({...e,liveUsage:{...e.liveUsage,[t.jobId]:n}},t.jobId,n);const a=[...e.events[t.jobId]??[],n],r=n.kind==="usage"?Af(e,t.jobId):e.liveUsage,l={...e,liveUsage:r,events:{...e.events,[t.jobId]:a.length>Pf?a.slice(-Pf):a}};return n.kind==="usage"?gf(l,t.jobId,n):l}case"analysis-wait":{const n=`${t.project}/${t.creative}`,a=(e.analysisSeq??0)+1;return{...e,analysisSeq:a,analysisWaits:{...e.analysisWaits,[n]:{files:t.files,seq:a}},creativeTicks:{...e.creativeTicks,[n]:(e.creativeTicks[n]??0)+1}}}case"video-analysis":{const n=(e.analysisSeq??0)+1;return{...e,analysisSeq:n,analyses:{...e.analyses,[t.project]:{...e.analyses?.[t.project],[t.file]:{view:t.view,seq:n}}}}}case"subtitles":case"creative":{const n=`${t.project}/${t.creative}`;return{...e,creativeTicks:{...e.creativeTicks,[n]:(e.creativeTicks[n]??0)+1}}}case"project":case"brand":case"library":return{...e,projectTicks:{...e.projectTicks,[t.project]:(e.projectTicks[t.project]??0)+1}};case"brief-session":{const n={...e.briefTicks,[t.project]:(e.briefTicks?.[t.project]??0)+1};if(!t.fill)return{...e,briefTicks:n};const a=Math.max(0,...Object.values(e.briefFills??{}).flat().map(l=>l.seq))+1,r=[...e.briefFills?.[t.project]??[],{sessionId:t.sessionId,seq:a,written:t.fill.written,reclaimed:t.fill.reclaimed??[]}];return{...e,briefTicks:n,briefFills:{...e.briefFills,[t.project]:r.slice(-20)}}}}}const oC=1e3;function cC({slug:e,creative:t,queued:n,working:a,onChanged:r,ops:l}){const o=V(),c=o.web.liveUi,d=i.useId(),[m,u]=i.useState(null);i.useEffect(()=>{u(null)},[n]),i.useEffect(()=>{if(!f||n.some(de=>de.clientId===f))return;const I=b.current,H=p.trim();I&&H&&H!==I.text.trim()&&y({text:H,pins:I.pins}),x(null)},[n]);const h=m??n,[f,x]=i.useState(null),[p,g]=i.useState(""),b=i.useRef(null),[v,y]=i.useState(null),[w,j]=i.useState(null),[S,k]=i.useState(""),[E,N]=i.useState(!1),C=i.useRef(null),[R,P]=i.useState(null),z=i.useRef(null),O=i.useRef(a),[T,W]=i.useState(!1);if(i.useEffect(()=>{const I=O.current&&!a;if(O.current=a,a){W(!1);return}if(!I)return;W(!0);const H=setTimeout(()=>W(!1),oC);return()=>clearTimeout(H)},[a]),i.useEffect(()=>{W(!1)},[n]),i.useEffect(()=>{f&&z.current?.focus()},[f]),n.length===0&&!m?.length&&!v)return null;const Z=I=>{u(null),j(Gl(I,o)),r()},A=async I=>{N(!0),j(null);try{await I(),r()}catch(H){Z(H)}finally{N(!1)}},L=(I,H)=>{if(E||I===H||H<0||H>=h.length)return;const de=[...h],[J]=de.splice(I,1);de.splice(H,0,J),u(de),k(c.moved({n:I+1,to:H+1})),A(()=>q.reorderQueue(e,t,de.map(se=>se.clientId))).catch(()=>{})},_=I=>{b.current=I,x(I.clientId),g(I.text),j(null)},X=I=>{const H=p.trim();!H&&I.pins.length===0||(x(null),A(async()=>{try{await q.editQueued(e,t,I.clientId,{text:H,pins:I.pins})}catch(de){if(de?.code==="not-queued"&&H){y({text:H,pins:I.pins});return}throw de}}))},ae=()=>{if(!v?.text.trim())return;const I={clientId:Xl(),text:v.text.trim(),pins:v.pins,mode:"queued"};A(async()=>{await q.postLiveMessage(e,t,I),y(null)})},K=v&&s.jsxs("div",{className:"ms-queue-kept",role:"group","aria-label":c.draftKeptLabel,children:[s.jsx("p",{className:"ms-queue-kept-why",role:"status",children:c.draftKept}),s.jsx(nn,{rows:2,maxLength:4e3,"aria-label":c.draftField,value:v.text,onChange:I=>y({...v,text:I.target.value})}),s.jsxs("div",{className:"ms-queue-edit-actions",children:[s.jsx($,{size:"sm",variant:"ghost",onClick:()=>y(null),children:c.draftDiscard}),s.jsx($,{size:"sm",variant:"outline",disabled:E||!v.text.trim(),onClick:ae,children:c.draftQueue})]})]});return h.length===0?s.jsxs("section",{className:"ms-queue","aria-label":c.draftKeptLabel,children:[K,w&&s.jsx("p",{role:"alert",className:"ms-composer-error",children:w})]}):s.jsxs("section",{className:"ms-queue","aria-labelledby":d,children:[K,s.jsxs("div",{className:"ms-queue-head",children:[s.jsx("h3",{id:d,className:"ms-queue-title",children:c.queueTitle({count:h.length})}),!a&&!T&&!l&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-queue-paused",children:c.queuePaused}),s.jsxs($,{size:"sm",variant:"outline",disabled:E,onClick:()=>{A(()=>q.runNext(e,t))},children:[s.jsx(F,{name:"play",size:12}),c.runNext]})]})]}),s.jsx("ol",{className:"ms-queue-list","aria-label":c.queueLabel,children:h.map((I,H)=>{const de=H+1,J=f===I.clientId;return s.jsxs("li",{className:le("ms-queue-item",R===I.clientId&&"ms-over"),draggable:!J&&!l,"aria-label":c.item({n:de}),onDragStart:se=>{if(C.current=I.clientId,se.dataTransfer){se.dataTransfer.effectAllowed="move";try{se.dataTransfer.setData("text/plain",I.clientId)}catch{}}},onDragOver:se=>{C.current&&C.current!==I.clientId&&(se.preventDefault(),P(I.clientId))},onDragLeave:()=>P(se=>se===I.clientId?null:se),onDrop:se=>{se.preventDefault();const U=h.findIndex(te=>te.clientId===C.current);C.current=null,P(null),U>=0&&L(U,H)},onDragEnd:()=>{C.current=null,P(null)},children:[l?null:s.jsx("span",{className:"ms-queue-grip","aria-hidden":"true",title:c.drag({n:de}),children:s.jsx(F,{name:"menu",size:12})}),s.jsx("div",{className:"ms-queue-body",children:J?s.jsxs(s.Fragment,{children:[s.jsx(nn,{ref:z,rows:2,maxLength:4e3,"aria-label":c.editField,value:p,onChange:se=>g(se.target.value)}),s.jsxs("div",{className:"ms-queue-edit-actions",children:[s.jsx($,{size:"sm",variant:"ghost",onClick:()=>x(null),children:c.cancelEdit}),s.jsx($,{size:"sm",variant:"outline",disabled:!p.trim()&&I.pins.length===0,onClick:()=>X(I),children:c.save})]})]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-queue-text","data-text":"",children:I.text}),s.jsxs("span",{className:"ms-queue-meta",children:[s.jsx("span",{className:"ms-pill ms-neutral",children:c.state.queued}),I.pins.length>0&&s.jsxs("span",{className:"ms-chip",children:[s.jsx(F,{name:"comment",size:11}),c.pins({count:I.pins.length})]})]})]})}),!J&&l&&s.jsx("div",{className:"ms-queue-actions",children:s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":c.remove({n:de}),disabled:E,onClick:()=>{A(()=>l.remove(I.clientId))},children:s.jsx(F,{name:"trash",size:12})})}),!J&&!l&&s.jsxs("div",{className:"ms-queue-actions",children:[s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":c.moveUp({n:de}),disabled:E||H===0,onClick:()=>L(H,H-1),children:s.jsx(F,{name:"chevron",size:12,className:"ms-queue-up"})}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":c.moveDown({n:de}),disabled:E||H===h.length-1,onClick:()=>L(H,H+1),children:s.jsx(F,{name:"chevron",size:12})}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":c.edit({n:de}),disabled:E,onClick:()=>_(I),children:s.jsx(F,{name:"edit",size:12})}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":c.remove({n:de}),disabled:E,onClick:()=>{A(()=>q.removeQueued(e,t,I.clientId))},children:s.jsx(F,{name:"trash",size:12})})]})]},I.clientId)})}),s.jsx("span",{role:"status",className:"ms-queue-said",children:S}),w&&s.jsx("p",{role:"alert",className:"ms-composer-error",children:w})]})}function fv(e){const t=new Set(e.primaries.map(a=>a.id)),n=e.groups?.map(a=>({label:a.label,items:a.items.filter(r=>t.has(r.id))})).filter(a=>a.items.length);return n?.length&&n.reduce((a,r)=>a+r.items.length,0)===t.size?n:[{label:null,items:e.primaries.map(a=>({id:a.id,name:a.label}))}]}function dC(e,t,n){const a=n.web.chat;if(t===null)return a.appliesAll;if(t.length===1)return e.primaries.find(o=>o.id===t[0])?.label??t[0];const r=fv(e),l=r.length>1?r.find(o=>t.every(c=>o.items.some(d=>d.id===c))):void 0;return l?.label?a.appliesInGroup({group:l.label,count:t.length}):a.appliesCount({count:t.length})}function uC({state:e}){return s.jsx("span",{className:le("ms-check",e!==!1&&"ms-on"),"aria-hidden":"true",children:s.jsx("svg",{width:11,height:11,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:2.2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:s.jsx("path",{d:e==="mixed"?Ya.minus:Ya.check})})})}function mC({appliesTo:e,targets:t,onChange:n}){const a=V(),r=a.web.chat,[l,o]=i.useState(!1),c=i.useRef(null),d=i.useRef(null),m=i.useId(),u=e.primaries.map(y=>y.id),h=new Set(t??[]),f=y=>{const w=u.filter(j=>y.has(j));n(w.length===0||w.length===u.length?null:w)},x=y=>{const w=new Set(h),j=y.every(S=>w.has(S));for(const S of y)j?w.delete(S):w.add(S);f(w)},p=y=>{const w=[...d.current?.querySelectorAll('[role="menuitemcheckbox"]')??[]],j=w.indexOf(document.activeElement),S=y.key==="ArrowLeft"||y.key==="ArrowRight"?null:Ma(y.key,j<0?0:j,w.length);S!==null&&(y.preventDefault(),w[S]?.focus())},g=fv(e),b=dC(e,t,a),v=(y,w,j,S,k,E)=>s.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":w,"data-row":"",className:le("ms-navitem ms-applies-item",E),onClick:S,children:[s.jsx(uC,{state:w}),s.jsx("span",{className:"ms-applies-name",children:j}),k?s.jsxs("span",{className:"ms-applies-follows",title:k.title,children:[s.jsx(F,{name:"link",size:11}),k.text]}):null]},y);return s.jsxs("div",{className:"ms-composer-applies",children:[s.jsxs("button",{ref:c,type:"button",className:"ms-applies-btn","aria-haspopup":"menu","aria-expanded":l,"aria-describedby":m,"aria-label":r.appliesButton({choice:b}),onClick:()=>o(y=>!y),children:[s.jsxs("span",{className:"ms-applies-label",children:[r.appliesTo,":"]}),s.jsx("b",{className:"ms-applies-choice",children:b}),s.jsx(F,{name:"chevron",size:12})]}),s.jsx("span",{id:m,hidden:!0,children:r.appliesHint}),s.jsx(ot,{open:l,onClose:()=>o(!1),anchor:c,placement:"top-start",width:300,children:s.jsxs("div",{ref:d,role:"menu","aria-label":r.appliesTo,className:"ms-applies-menu",onKeyDown:p,children:[v("all",t===null,r.appliesAll,()=>n(null),void 0,"ms-applies-all"),g.map((y,w)=>{const j=y.items.map(k=>k.id),S=j.filter(k=>h.has(k)).length;return s.jsxs("div",{role:"group","aria-label":y.label??r.appliesTo,className:"ms-applies-group",children:[y.label?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"ms-cap ms-applies-head","aria-hidden":"true",children:y.label}),g.length>1&&y.items.length>1?v(`g:${w}`,S===0?!1:S===j.length?!0:"mixed",r.appliesWholeGroup({group:y.label}),()=>x(j),void 0,"ms-applies-whole"):null]}):null,y.items.map(k=>{const E=e.primaries.find(C=>C.id===k.id),N=E.followers.length?{text:E.followers.join(", "),title:E.followers.map(C=>r.followsBoth({follower:C,primary:E.label})).join(`
|
|
12
|
+
`)}:void 0;return v(k.id,h.has(k.id),k.name,()=>x([k.id]),N)})]},w)})]})})]})}function Al(e,t){const{brief:n,exportPicks:a}=e.creative,r=kj(n.links,n.formats),l={},o=new Map((e.formats??[]).map(d=>[d.id,d])),c=d=>o.get(d)?.star??qc(e.versions,d,a,r);for(const d of n.formats){const m=o.get(d),u=c(d),h=u.follows!==null?c(u.follows).version:null,f=m?.exportVersion!==void 0?m.exportVersion:u.follows!==null?Nj(e.versions,d,h,r):u.version;l[d]={id:d,history:m?.history??mh(e.versions,d),star:u,defaultVersion:qc(e.versions,d,void 0,r).version,exportVersion:f,starFileMissing:m?.starFileMissing??(u.follows!==null&&h!==null&&f===null),linkable:m?.linkable??n.formats.filter(x=>x!==d).map(x=>{const p=Sj(n,e.versions,t,d,x);return p.ok?{primary:x,ok:!0}:{primary:x,ok:!1,reason:p.reason}}),follows:u.follows,...m?.subtitlesTrack!==void 0?{subtitlesTrack:m.subtitlesTrack}:{}}}for(const d of e.versions)for(const m of d.outputs){if(l[m.format])continue;const u=qc(e.versions,m.format,void 0,void 0);l[m.format]={id:m.format,history:mh(e.versions,m.format),star:u,defaultVersion:u.version,exportVersion:u.version,starFileMissing:!1,linkable:[],follows:null}}return l}function Vo(e,t){return Object.values(e).filter(n=>n.follows===t).map(n=>n.id)}function Nc(e,t){return e?t!==void 0&&e.history.includes(t)?t:e.star.version??e.history.at(-1)??null:null}function ja(e,t,n){if(!t||n===null)return null;const a=e.find(r=>r.n===n);return!a||!(a.outputs.some(r=>r.format===t.id)||a.compositions?.some(r=>r.format===t.id))?null:[...t.history].reverse().find(r=>r<=n)??null}function ga(e,t,n){const a=e[t],r=a?.follows&&e[a.follows]?a.follows:t;return{format:r,n:Nc(e[r],n[r])}}const hC=e=>e!==void 0&&(e.state==="queued"||e.state==="running");function lu(e,t){if(!hC(e))return new Set;if(!e.formats?.length)return"all";const n=new Set(e.formats);for(const a of Object.values(t))a.follows&&n.has(a.follows)&&n.add(a.id);return n}const mo=(e,t)=>e==="all"||e.has(t);function fC(e,t,n){const a=new Set(e.map(t)),r=n.filter(l=>a.has(l));return r.length===0||r.length===n.length?null:r}function pC({group:e,current:t,all:n,missing:a=[],onSelect:r}){const l=V().web.variantGroup,o=e.members.filter(m=>m.status==="active"),c=o.filter(m=>!a.includes(m.letter)),d=[...o.map(m=>({value:m.letter,label:It(m.letter),disabled:a.includes(m.letter),...a.includes(m.letter)?{title:l.missingFolder}:{}})),...c.length>1?[{value:"all",label:l.selectorAll,title:l.allHint}]:[]];return s.jsxs("div",{className:"ms-vsel","data-variant-selector":!0,children:[s.jsx(it,{label:l.selectorLabel,value:n?"all":t,options:d,onChange:r}),s.jsx("p",{className:"ms-vsel-hint",role:"note",children:n?l.allHint:l.sendToHint({letter:It(t)})})]})}const Zr=e=>{const t=e?.code;return typeof t=="string"?t:void 0},xC=5,gC=15,vC=2,bC=e=>new Promise(t=>setTimeout(t,e)),iu=e=>t=>new Promise((n,a)=>{if(e.aborted){a(e.reason);return}const r=setTimeout(n,t);e.addEventListener("abort",()=>{clearTimeout(r),a(e.reason)},{once:!0})});async function pv(e,t=bC){for(let n=0;;n++)try{return await e()}catch(a){if(Zr(a)!=="hashes-pending"||n>=vC)throw a;const r=a.retryAfterSec,l=typeof r=="number"&&Number.isFinite(r)&&r>=0?Math.min(r,gC):xC;await t(l*1e3)}}function xv(e,t,n){const a=t.web.formatVersions.errors,r=n.primary??"";switch(Zr(e)){case"hashes-pending":return a.hashesPending;case"pick-follower":return a.pickFollower({label:n.label,primary:r});case"format-not-in-brief":return a.notInBrief({label:n.label});case"pick-no-file":return a.pickNoFile({label:n.label,n:n.n??0});case"pick-file-missing":return a.pickFileMissing({label:n.label,n:n.n??0});case"version-not-found":return n.n!==void 0?a.versionNotFound({n:n.n}):a.failed({detail:pe(e)});case"link-self":return a.linkSelf;case"link-chain":return a.linkChain({label:n.label,primary:r});case"link-incompatible":return n.reason?a.linkIncompatible({label:n.label,primary:r,reason:t.errors.followReason[n.reason]}):pe(e);case"job-running":return a.jobRunning;case"formats-not-in-brief":return a.formatsNotInBrief;default:return a.failed({detail:pe(e)})}}function gv(e,t){const n=t.web.exportUi.errors,a=pe(e);switch(Zr(e)){case"hashes-pending":return t.web.formatVersions.errors.hashesPending;case"export-invalid-picks":return n.invalidPicks;case"export-pick-follower":return n.pickFollower;case"export-pick-no-file":return n.pickNoFile({detail:a});case"export-follow-mismatch":return n.followMismatch({detail:a});case"export-file-missing":return n.fileMissing({detail:a});case"export-name-collision":return n.nameCollision({detail:a});case"export-name-empty":return n.nameEmpty;case"export-invalid-pattern":return n.invalidPattern;case"export-invalid-destination":return n.invalidDestination;case"export-invalid-date":return n.invalidDate;default:return a}}const jC={openai:["openai"],elevenlabs:["elevenlabs"],stock:["pexels","unsplash"]},ou={openai:"OpenAI",elevenlabs:"ElevenLabs",pexels:"Pexels",unsplash:"Unsplash"};function Sc(){const[e,t]=i.useState(null);return i.useEffect(()=>{let n=!0;return Promise.resolve().then(()=>q.getSecrets()).then(a=>{n&&t(new Set(a.filter(r=>r.configured).map(r=>r.provider)))}).catch(()=>{}),()=>{n=!1}},[]),e}function Cc(){const[e,t]=i.useState(null);return i.useEffect(()=>{let n=!0;return Promise.resolve().then(()=>q.getKeyChecks()).then(a=>{n&&t(a)}).catch(()=>{}),()=>{n=!1}},[]),e}const yC={images:["openai"],voice:["openai","elevenlabs"],music:["elevenlabs"],sfx:["elevenlabs"]};function vv(e,t,n){return yC[e].flatMap(a=>{if(t&&!t.has(a))return[];const r=Cu(n?.[a],lx(e,a));return r?[{provider:a,...r.permission?{permission:r.permission}:{}}]:[]})}function bv(e,t,n){const a=t.web.services,r=ac({services:e}),l=ko.filter(d=>r[d]!=="auto").map(d=>a.summaryPart({kind:a.kinds[d],choice:a.choices[r[d]]})),o=n?ko.filter(d=>r[d]==="auto").flatMap(d=>n(d).map(m=>a.summarySkipped({kind:a.kinds[d],provider:ou[m.provider]}))):[],c=[...l,...o];return c.length?c.join(" · "):a.summaryAuto}function wC(e,t){const n=t.web.services,a=ac({services:e}),r=[...new Set(ko.map(l=>a[l]).filter(l=>l!=="auto"&&l!=="none"))].map(l=>n.choices[l]);return r.length===0?n.chip:r.length>2?`${r.slice(0,2).join(" · ")} +${r.length-2}`:r.join(" · ")}function Sm({value:e,onChange:t,configured:n,checks:a,disabled:r}){const o=V().web.services,c=i.useId(),d=ac({services:e}),m=(u,h)=>{const f=jC[h];if(!f)return null;const x=h==="stock"?o.stockProviders:ou[f[0]],p=n?f.filter(v=>n.has(v)):f;if(n&&p.length===0)return o.needsKey({choice:o.choices[h],provider:x});const g=p.map(v=>Cu(a?.[v],lx(u,v)));if(g.some(v=>v===null))return null;const b=[...new Set(g.flatMap(v=>v?.permission?[v.permission]:[]))];return b.length?o.missingPermission({choice:o.choices[h],provider:x,permission:b.join(", ")}):o.keyRefused({choice:o.choices[h],provider:x})};return s.jsx("div",{className:"ms-services",children:ko.map(u=>{const h=Cj[u],f=h.map(b=>m(u,b)).filter(b=>b!==null),x=d[u]==="auto"?vv(u,n,a):[],p=h.filter(b=>!x.some(v=>v.provider===b)).map(b=>m(u,b)).filter(b=>b!==null),g=`${c}-${u}-why`;return s.jsxs("div",{className:"ms-services-row",children:[s.jsx("span",{className:"ms-services-kind","aria-hidden":"true",children:o.kinds[u]}),s.jsx(it,{className:"ms-services-seg",label:o.group({kind:o.kinds[u]}),value:d[u],disabled:r,describedBy:f.length||x.length?g:void 0,onChange:b=>t({...e,[u]:b}),options:h.map(b=>{const v=m(u,b);return{value:b,label:o.choices[b],...v?{disabled:!0,title:v}:{}}})}),f.length||x.length?s.jsxs("p",{id:g,className:"ms-services-why",children:[x.map(b=>o.autoSkipped({kind:o.kinds[u],provider:ou[b.provider],why:b.permission?o.whyPermission({permission:b.permission}):o.whyKeyRefused})).join(" "),x.length?s.jsxs(s.Fragment,{children:[" ",s.jsx("a",{href:es.settings("paid"),children:o.testInSettings})," "]}):null,p.join(" "),p.length&&!x.length?s.jsxs(s.Fragment,{children:[" ",s.jsx("a",{href:es.settings("paid"),children:o.openSettings})]}):null]}):null]},u)})})}function kC({slug:e,creative:t,brief:n,busy:a,onSaved:r}){const l=V(),o=l.web.services,c=i.useRef(null),[d,m]=i.useState(!1),[u,h]=i.useState(!1),[f,x]=i.useState(null),[p,g]=i.useState(null),b=Sc(),v=Cc(),y=p??n.services;i.useEffect(()=>{g(null)},[n]);const w=bv(y,l,k=>vv(k,b,v)),j=wC(y,l),S=async k=>{x(null),h(!0),g(k);try{await q.updateCreative(e,t,{services:k}),r()}catch(E){g(null),x(o.saveFailed({detail:pe(E)}))}finally{h(!1)}};return s.jsxs(s.Fragment,{children:[s.jsx(pn,{label:a?`${o.chipAria({summary:w})} · ${o.busy}`:o.chipAria({summary:w}),whenHidden:".ms-services-chip-label",children:s.jsxs($,{ref:c,size:"sm",variant:"ghost",className:"ms-services-chip","aria-haspopup":"dialog","aria-expanded":d,"aria-label":o.chipAria({summary:w}),onClick:()=>m(k=>!k),children:[s.jsx(F,{name:"plug",size:12}),s.jsx("span",{className:"ms-services-chip-label",children:j}),j===o.chip?s.jsx("span",{className:"ms-services-chip-sum",children:w}):null]})}),s.jsx(ot,{open:d,onClose:()=>m(!1),anchor:c,placement:"top-start",width:420,label:o.title,children:s.jsxs("div",{className:"ms-services-pop",children:[s.jsx("b",{children:o.title}),s.jsx("p",{className:"ms-services-hint",children:o.hint}),s.jsx(Sm,{value:y,configured:b,checks:v,disabled:a||u,onChange:k=>{S(k)}}),s.jsx("p",{className:"ms-services-hint",role:"status",children:a?o.busy:u?o.saving:o.nextTurn}),f?s.jsx("p",{role:"alert",className:"ms-services-error",children:f}):null]})})]})}const NC=/[()[\]{}*?\\]/,jv=e=>e.split("/").filter(Boolean).pop()??e;function SC(e,t){return e.startsWith("/")||e.startsWith("~")?NC.test(e)?t.errors.codebaseGlobChars({path:e}):null:t.web.codebase.needAbsolute}function yv({label:e,menuLabel:t,items:n,disabled:a,className:r,size:l}){const[o,c]=i.useState(!1),d=i.useRef(null),m=i.useRef(null),u=h=>{const f=[...m.current?.querySelectorAll('[role="menuitem"]')??[]],x=f.indexOf(document.activeElement),p=h.key==="ArrowLeft"||h.key==="ArrowRight"?null:Ma(h.key,x<0?0:x,f.length);p!==null&&(h.preventDefault(),f[p]?.focus())};return s.jsxs(s.Fragment,{children:[s.jsx($,{ref:d,type:"button",variant:"ghost",icon:!0,...l?{size:l}:{},className:le("ms-plus",r),"aria-label":e,title:e,"aria-haspopup":"menu","aria-expanded":o,disabled:a,onClick:()=>c(h=>!h),children:s.jsx(F,{name:"plus",size:l==="sm"?16:18})}),s.jsx(ot,{open:o,onClose:()=>c(!1),anchor:d,placement:"top-start",width:300,children:s.jsx("div",{ref:m,role:"menu","aria-label":t,className:"ms-brief-menu",onKeyDown:u,children:n.map(h=>s.jsxs("button",{type:"button",role:"menuitem","data-row":"",className:"ms-brief-mi",onClick:()=>{c(!1),h.run(d.current)},children:[s.jsx(F,{name:h.icon,size:16}),s.jsxs("span",{children:[s.jsx("b",{children:h.title}),h.hint?s.jsx("small",{children:h.hint}):null]})]},h.key))})})]})}function CC({onFolder:e,onLibrary:t,onUpload:n,disabled:a}){const r=V().web.briefSession;return s.jsx(yv,{label:r.add,menuLabel:r.addMenu,disabled:a,className:"ms-brief-plus",items:[{key:"folder",icon:"folder",title:r.folder.title,hint:r.folder.hint,run:e},{key:"library",icon:"image",title:r.library.title,hint:r.library.hint,run:t},{key:"upload",icon:"upload",title:r.upload.title,hint:r.upload.hint,run:n}]})}function EC({pins:e,onRemove:t,thumb:n,mark:a}){const r=V().web.briefSession;return e.length===0?null:s.jsx("div",{className:"ms-composer-pins ms-brief-pins",children:e.map(l=>{const o=l.kind==="folder"?l.path:jv(l.path),c=l.kind==="asset"?n(l.path):null;return s.jsxs("span",{className:le("ms-chip ms-on ms-composer-pin ms-brief-pin",l.kind==="folder"&&"ms-brief-folder"),title:l.path,children:[l.kind==="asset"?s.jsx("span",{className:"ms-brief-swatch","aria-hidden":"true",style:c?{backgroundImage:`url("${c}")`}:void 0}):null,s.jsx("span",{className:"ms-brief-pin-name",children:o}),l.kind==="asset"?a?.(l.path):null,s.jsx("button",{type:"button",className:"ms-x","aria-label":r.removePin({name:o}),onClick:()=>t(l),children:s.jsx(F,{name:"close",size:10})})]},`${l.kind}:${l.path}`)})})}function Lf({context:e,onChange:t,disabled:n}){const a=V().web.briefSession,r=e.codebases.length,l=e.assets.length;return s.jsxs("div",{className:"ms-brief-ctx",children:[s.jsx(If,{icon:"folder",label:r?a.folders({count:r}):a.noFolders,title:a.foldersTitle,disabled:n,items:e.codebases.map(o=>({key:o.path,text:o.path,mono:!0})),onRemove:o=>t({...e,codebases:e.codebases.filter(c=>c.path!==o)})}),s.jsx(If,{icon:"image",label:l?a.assets({count:l}):a.noAssets,title:a.assetsTitle,disabled:n,items:e.assets.map(o=>({key:o,text:jv(o),mono:!1})),onRemove:o=>t({...e,assets:e.assets.filter(c=>c!==o)})})]})}function If({icon:e,label:t,title:n,items:a,onRemove:r,disabled:l}){const o=V().web.briefSession,[c,d]=i.useState(!1),m=i.useRef(null);return s.jsxs(s.Fragment,{children:[s.jsxs($,{ref:m,size:"sm",variant:"ghost","aria-haspopup":"dialog","aria-expanded":c,disabled:l||a.length===0,onClick:()=>d(u=>!u),children:[s.jsx(F,{name:e,size:14}),t,s.jsx(F,{name:"chevron",size:12})]}),s.jsx(ot,{open:c&&a.length>0,onClose:()=>d(!1),anchor:m,placement:"top-start",width:300,label:n,children:s.jsx("ul",{className:"ms-brief-ctx-list",children:a.map(u=>s.jsxs("li",{children:[s.jsx("span",{className:le("ms-brief-ctx-item",u.mono&&"ms-mono"),title:u.key,children:u.text}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":o.removeContext({name:u.text}),title:o.removeContext({name:u.text}),onClick:()=>r(u.key),children:s.jsx(F,{name:"close",size:11})})]},u.key))})})]})}const TC=/^(image|svg|video)$/,RC=e=>e.split("/").pop()??e,Ll=e=>`assets/${e}`;function cu({slug:e,path:t,entry:n,small:a}){const r=n?.kind??(tr(t)?"video":/\.(png|jpe?g|webp|gif|avif|svg)$/i.test(t)?"image":"other"),l=q.projectFileUrl(e,t);return TC.test(r)?r==="video"?s.jsxs(s.Fragment,{children:[s.jsx("video",{className:le("ms-nc-face",a&&"ms-sm"),src:l,muted:!0,preload:"metadata","aria-hidden":"true"}),a?null:s.jsx("span",{className:"ms-nc-face-play","aria-hidden":"true",children:s.jsx(F,{name:"play",size:10,fill:!0})})]}):s.jsx("img",{className:le("ms-nc-face",r==="svg"&&"ms-nc-face-svg",a&&"ms-sm"),src:l,alt:""}):a?s.jsx("span",{className:"ms-nc-face ms-sm ms-nc-face-file","aria-hidden":"true",children:s.jsx(F,{name:"folder",size:10})}):s.jsxs("span",{className:"ms-nc-face ms-nc-face-file","aria-hidden":"true",children:[s.jsx(F,{name:r==="audio"?"play":"folder",size:14}),s.jsx("span",{children:RC(t)})]})}function Cm({slug:e,projectName:t,open:n,onClose:a,anchor:r,placement:l="bottom-end",library:o,onRetry:c,chosen:d,onToggle:m,extra:u=[],onUpload:h}){const f=V().web.newCreative,x=o.value??[],p=[...x,...u.filter(b=>!x.some(v=>v.file===b.file))].filter(b=>b.kind!=="font"),g=()=>{a(),Bs(es.project(e,"assets"))};return s.jsx(ot,{open:n,onClose:a,anchor:r,placement:l,width:360,children:s.jsxs("div",{role:"dialog","aria-label":f.libraryTitle({project:t}),className:"ms-nc-picker",children:[s.jsx("span",{className:"ms-nc-cap ms-nc-ell",children:f.libraryTitle({project:t})}),o.value===null&&!o.error?s.jsxs("div",{className:"ms-nc-pick-state",role:"status",children:[s.jsx(Ts,{size:14,decorative:!0}),f.libraryLoading]}):o.error&&o.value===null?s.jsxs("div",{className:"ms-nc-pick-state ms-nc-wrap",role:"alert",children:[s.jsx("span",{children:f.libraryFailed({detail:o.error})}),s.jsx($,{size:"sm",variant:"outline",onClick:c,children:f.tryAgain})]}):null,o.error&&o.value!==null?s.jsxs("p",{className:"ms-nc-pick-warn",role:"status",children:[s.jsx(F,{name:"warn",size:13}),s.jsx("span",{children:f.libraryPartial({detail:o.error})})]}):null,o.value===null?null:p.length===0?s.jsx(Rt,{icon:"image",title:f.libraryEmpty,sub:f.libraryEmptyBody,action:h?s.jsxs("span",{className:"ms-nc-pick-actions",children:[s.jsxs($,{size:"sm",variant:"ink",onClick:()=>{a(),h()},children:[s.jsx(F,{name:"upload",size:13}),f.uploadFromComputer]}),s.jsx($,{size:"sm",variant:"ghost",onClick:g,children:f.openAssets})]}):s.jsx($,{size:"sm",variant:"outline",onClick:g,children:f.openAssets})}):s.jsx("div",{className:"ms-nc-pick-grid",children:p.map(b=>{const v=Ll(b.file),y=d.includes(v);return s.jsxs("button",{type:"button","data-row":!0,className:le("ms-nc-pick",y&&"ms-on"),"aria-pressed":y,"aria-label":b.file,title:b.description?`${b.file}
|
|
13
|
+
${b.description}`:b.file,onClick:()=>m(v),children:[s.jsx("span",{className:"ms-nc-pick-face",children:s.jsx(cu,{slug:e,path:v,entry:b})}),s.jsx("span",{className:"ms-nc-pick-name","aria-hidden":"true",children:b.file}),y?s.jsx("span",{className:"ms-nc-tick","aria-hidden":"true",children:s.jsx(F,{name:"check",size:10,strokeWidth:2.4})}):null]},b.file)})})]})})}const wv=e=>{const t=ix(e);return t==="image"||t==="svg"?"image":t==="video"?"video":t==="audio"?"music":"folder"};let MC=0;function $C({slug:e,chosen:t,onAdd:n,onRemove:a,onError:r,onPending:l,disabled:o}){const c=V(),d=c.web.chat,u=i.useContext(Mn)?.catalog.projects?.find(w=>w.slug===e)?.name??e,[h,f]=i.useState({value:null,error:null}),[x,p]=i.useState(!1),g=i.useRef(null),b=i.useRef(null),v=()=>{f(w=>({value:w.value,error:null})),q.listAssets(e).then(w=>f({value:w.assets,error:w.error})).catch(w=>f(j=>({value:j.value,error:pe(w)})))},y=async w=>{if(w.length===0)return;r(null);const j=++MC;l({started:{id:j,names:w.map(S=>S.name)}});try{const k=((await q.uploadFiles(e,"assets",w)).assets??[]).map(E=>Ll(E.file));k.length&&n(k,j),h.value!==null&&v()}catch(S){r(c.web.briefSession.uploadFailed({detail:pe(S)}),j)}finally{l({settled:j})}};return s.jsxs(s.Fragment,{children:[s.jsx(yv,{label:d.attach,menuLabel:d.attachMenu,disabled:o,size:"sm",className:"ms-composer-attach",items:[{key:"computer",icon:"upload",title:d.attachComputer.title,hint:d.attachComputer.hint,run:()=>b.current?.click()},{key:"library",icon:"image",title:d.attachLibrary.title,hint:d.attachLibrary.hint,run:w=>{g.current=w,v(),p(!0)}}]}),s.jsx("input",{ref:b,type:"file",multiple:!0,hidden:!0,"aria-hidden":"true",tabIndex:-1,"data-testid":"attach-input",onChange:w=>{const j=[...w.target.files??[]];w.target.value="",y(j)}}),s.jsx(Cm,{slug:e,projectName:u,open:x,onClose:()=>p(!1),anchor:g,placement:"top-start",library:h,onRetry:v,chosen:t,onUpload:()=>b.current?.click(),onToggle:w=>t.includes(w)?a(w):n([w])})]})}function FC({slug:e,path:t}){const[n,a]=i.useState(!1),r=ix(t);return(r==="image"||r==="svg")&&!n?s.jsx("img",{className:"ms-attach-thumb",src:q.projectFileUrl(e,t),alt:"",onError:()=>a(!0)}):s.jsx(F,{name:wv(t),size:11})}function PC({slug:e,paths:t,pending:n,onRemove:a,onCancel:r}){const l=V(),o=l.web.briefSession,c=n.flatMap(d=>d.names.map((m,u)=>({key:`${d.id}:${u}`,id:d.id,name:m})));return t.length===0&&c.length===0?null:s.jsxs("div",{className:"ms-composer-pins ms-brief-pins",children:[t.map(d=>{const m=d.split("/").pop()??d;return s.jsxs("span",{className:"ms-chip ms-on ms-composer-pin ms-brief-pin",title:d,children:[s.jsx(FC,{slug:e,path:d}),s.jsx("span",{className:"ms-brief-pin-name",children:m}),s.jsx("button",{type:"button",className:"ms-x","aria-label":o.removePin({name:m}),onClick:()=>a(d),children:s.jsx(F,{name:"close",size:10})})]},d)}),c.map(d=>s.jsxs("span",{role:"status","aria-label":l.web.chat.uploading({name:d.name}),className:"ms-chip ms-composer-pin ms-brief-pin ms-attach-pending",children:[s.jsx(Ts,{size:11,decorative:!0}),s.jsx("span",{className:"ms-brief-pin-name",children:d.name}),s.jsx("button",{type:"button",className:"ms-x","aria-label":l.web.chat.cancelUpload({name:d.name}),onClick:()=>r(d.id),children:s.jsx(F,{name:"close",size:10})})]},d.key))]})}const AC=6e4;function kv(e,t){const n=URL.createObjectURL(e),a=document.createElement("a");a.href=n,a.download=t,a.rel="noopener",a.style.display="none",document.body.appendChild(a),a.click(),a.remove(),setTimeout(()=>URL.revokeObjectURL(n),AC)}const LC=["srt","vtt"];function zf(e,t){try{return new Intl.DisplayNames([t],{type:"language"}).of(e)??e}catch{return e}}function Nv({slug:e,creative:t,lang:n,className:a}){const r=V().subtitles,[l,o]=i.useState({kind:"idle"}),c=async()=>{o({kind:"busy"});try{await q.startSubtitles(e,t,{mode:"retime",lang:n}),o({kind:"started"})}catch(d){o({kind:"error",text:r.retimeFailed({detail:pe(d)})})}};return s.jsxs(s.Fragment,{children:[s.jsxs($,{size:"sm",variant:"outline",disabled:l.kind==="busy"||l.kind==="started","aria-busy":l.kind==="busy"||void 0,onClick:()=>{c()},children:[s.jsx(F,{name:"refresh",size:13}),r.retime]}),l.kind==="started"?s.jsx("span",{role:"status",className:a,children:r.retimeStarted}):null,l.kind==="error"?s.jsx("span",{role:"alert",className:a,children:l.text}):null]})}const Di=new Map;function IC(e,t,n){const a=`${e}/${t}`;let r=Di.get(a);(!r||r.tick!==n)&&(r={tick:n,users:0,sets:Promise.resolve().then(()=>q.subtitles(e,t)).then(o=>o.sets,()=>null)},Di.set(a,r));const l=r;return l.users++,{sets:l.sets,release:()=>{--l.users===0&&Di.get(a)===l&&Di.delete(a)}}}function zC({slug:e,creative:t,lang:n}){const a=V(),r=rs(),l=i.useContext(Mn)?.live.creativeTicks[`${e}/${t}`]??0,[o,c]=i.useState(null);return i.useEffect(()=>{let d=!0;const m=IC(e,t,l),u=h=>h?.origin==="translation"?"follows":h?.timingChanged??!1;return m.sets.then(h=>{d&&c(h===null?!0:u(h.find(f=>f.lang===n)))}),()=>{d=!1,m.release()}},[e,t,n,l]),s.jsxs("div",{className:"ms-convo-version ms-convo-subtitles",role:"group","aria-label":a.subtitles.timingChanged,children:[s.jsx(F,{name:"warn",size:14,className:"ms-convo-subtitles-warn"}),s.jsx("b",{children:a.subtitles.timingChanged}),s.jsx(Qs,{children:Js(n,r)}),s.jsx("span",{className:"ms-grow"}),s.jsx("a",{className:"ms-btn ms-sm ms-outline",href:es.subtitles(e,t,n),children:a.subtitles.openEditor}),o===!0?s.jsx(Nv,{slug:e,creative:t,lang:n,className:"ms-convo-version-summary"}):null,o===!1?s.jsx("span",{className:"ms-convo-version-summary",children:a.subtitles.timingAligned}):null]})}function OC({slug:e,creative:t,lang:n}){const a=V().subtitles,r=rs(),[l,o]=i.useState(!1),[c,d]=i.useState(null),m=async()=>{o(!0),d(null);try{await q.addSubtitleLanguage(e,t,n)}catch(u){if(!(u instanceof lt&&u.code==="subtitles-lang-exists")){d(a.translateIntoFailed({detail:pe(u)})),o(!1);return}}o(!1),Bs(es.subtitles(e,t,n))};return s.jsxs(s.Fragment,{children:[s.jsx($,{size:"sm",variant:"outline",disabled:l,"aria-busy":l||void 0,onClick:()=>{m()},children:a.translateInto({language:Js(n,r)})}),c?s.jsx("span",{className:"ms-convo-version-summary ms-convo-error",role:"alert",children:c}):null]})}function DC({slug:e,creative:t,entry:n}){const a=V(),r=rs(),[l,o]=i.useState(null),[c,d]=i.useState(null),m=n.subtitles,u=m?.lang;if(m?.state==="timing-changed"&&u)return s.jsx(zC,{slug:e,creative:t,lang:u});if(m?.state!=="ready"||!u)return n.level==="error"?s.jsx("p",{role:"alert",className:"ms-convo-system ms-error",children:n.text}):n.level==="warning"?s.jsxs("p",{className:"ms-convo-system ms-warning",children:[s.jsx(F,{name:"warn",size:13}),s.jsx("span",{children:n.text})]}):s.jsx("p",{className:"ms-convo-system",children:n.text});const h=async(f,x)=>{o(f),d(null);try{kv(await q.subtitleFile(e,t,x,f),`${t}.${x}.${f}`)}catch(p){d(a.subtitles.downloadFailed({detail:pe(p)}))}finally{o(null)}};return s.jsxs("div",{className:"ms-convo-version ms-convo-subtitles",role:"group","aria-label":a.subtitles.readyTitle,children:[s.jsx(F,{name:"check",size:14,className:"ms-convo-subtitles-mark"}),s.jsx("b",{children:a.subtitles.readyTitle}),s.jsx(Qs,{children:Js(u,r)}),s.jsx("span",{className:"ms-grow"}),s.jsx("a",{className:"ms-btn ms-sm ms-outline",href:es.subtitles(e,t,u),children:a.subtitles.openEditor}),LC.map(f=>s.jsxs($,{size:"sm",variant:"outline",disabled:l!==null,"aria-busy":l===f||void 0,"aria-label":a.subtitles.download({ext:`.${f}`}),onClick:()=>{h(f,u)},children:[s.jsx(F,{name:"download",size:13}),".",f]},f)),m.briefLang&&m.briefLang!==u?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-convo-version-summary",children:a.subtitles.readyOtherLang({lang:zf(u,r),brief:zf(m.briefLang,r)})}),s.jsx(OC,{slug:e,creative:t,lang:m.briefLang})]}):null,c?s.jsx("span",{className:"ms-convo-version-summary ms-convo-error",role:"alert",children:c}):null]})}function BC(e,t){if(e.length===0)return t;const n=e.map(r=>JSON.stringify(r)),a=t.map(r=>JSON.stringify(r));for(let r=Math.min(n.length,a.length);r>0;r--){let l=!0;for(let o=0;o<r&&l;o++)l=n[n.length-r+o]===a[o];if(l)return[...e,...t.slice(r)]}return[...e,...t]}const Bi=e=>!!e&&(e.state==="queued"||e.state==="running"),UC=new Set(["session","tool_use","tool_result","rate_limit","stderr","parse_error","auto_approved"]),Sv=(e,t)=>e.trim()===t.trim(),_C=(e,t)=>e.length===t.length&&e.every((n,a)=>{const r=t[a];return n.format===r.format&&n.x===r.x&&n.y===r.y&&n.timeSec===r.timeSec&&(n.note??"")===(r.note??"")});function qC(e,t,n,a,r,l,o,c=[]){const d=[],m=[...c].sort((v,y)=>v.anchor-y.anchor),u=v=>{for(;m.length>0&&m[0].anchor<=v;)d.push(m.shift().item)},h=[],f=[],x=o(t,n.map(v=>v.event),!a),p=new Map(x.rows.map(v=>[v.key,v]));let g=null,b=-1;return n.forEach(({at:v,event:y},w)=>{const j=`${t}:${w}`;if(u(w),UC.has(y.kind)){const S=p.get(`c${w}`);S?f.push({key:j,row:S}):y.kind!=="auto_approved"&&f.push({key:j,event:y});return}if(y.kind==="text"){if(!y.text.trim())return;g={key:j,kind:"agent",at:v,text:y.text,summary:!1},d.push(g)}else if(y.kind==="question_answered")d.push({key:j,kind:"question",at:v,event:y});else if(y.kind==="interrupted")d.push({key:j,kind:"system",at:v,level:"info",text:e});else if(y.kind==="progress"){const S={key:j,kind:"step",at:v,text:y.text};h.push(S),a?d.push(S):b<0&&(b=d.length)}else if(y.kind==="result"){if(f.push({key:j,event:y}),!y.ok&&!y.interrupted)d.push({key:j,kind:"error",at:v,text:y.error??""});else if(y.text?.trim()){const S=g;S&&Sv(S.text,y.text)?S.summary=!0:d.push({key:j,kind:"agent",at:v,text:y.text,summary:!0})}}}),u(1/0),!a&&h.length>0&&d.splice(b,0,{key:`${t}:fold`,kind:"fold",jobId:t,count:h.length,open:r},...r?h:[]),!a&&x.ran>0&&d.push({key:`${t}:auto`,kind:"autoline",jobId:t,log:x}),f.length>0&&d.push({key:`${t}:details`,kind:"details",jobId:t,entries:f,open:l}),d}function Ec({slug:e,creative:t,entries:n,approvals:a,job:r,live:l=[],pins:o=[],onRemovePin:c,onEditPin:d,formatName:m,canGenerate:u,onSent:h,beforeSend:f,onSelectVersion:x,versionExtra:p,versionNote:g,versionSummary:b,snapshots:v,appliesTo:y,brief:w,onBriefSaved:j,queued:S,onQueueChanged:k,variants:E,self:N,onOpenVariant:C,memberJobs:R,single:P,otherPins:z,onRemoveOtherPin:O,usageOf:T,transport:W,composerTop:Z,composerTools:A,composerBelow:L,composerLabel:_,placeholder:X,draft:ae,extraContent:K,composerDisabled:I,intro:H,queueOps:de,cards:J}){const se=V(),U=se.web.chat,te=Bi(r),[G,re]=i.useState([]),oe=i.useMemo(()=>({add:Le=>re(ne=>[...ne.filter(Ee=>Ee.clientId!==Le.clientId),Le].slice(-20)),phase:(Le,ne)=>re(Ee=>Ee.map(Ce=>Ce.clientId===Le?{...Ce,phase:ne}:Ce)),drop:Le=>re(ne=>ne.filter(Ee=>Ee.clientId!==Le))}),[]),[Ne,Q]=i.useState(new Set),[Re,Ue]=i.useState(new Set),[is,Qe]=i.useState(new Set),{list:gs,gone:As}=Eg(a),hs=i.useContext(zu),Oe=i.useMemo(()=>Mx(hs,e,t),[hs,e,t]),be=i.useRef(new Map),Fe=(Le,ne,Ee)=>{const Ce=be.current.get(Le),Xe=ne[0],ue=ne[ne.length-1];if(Ce&&Ce.n===ne.length&&Ce.first===Xe&&Ce.last===ue&&Ce.finished===Ee&&Ce.ctx===Oe)return Ce.log;const xe=$x(ne,Oe,{finished:Ee});return be.current.set(Le,{n:ne.length,first:Xe,last:ue,finished:Ee,ctx:Oe,log:xe}),xe},je=i.useRef(new Map),he=i.useRef(new Map),Ke=i.useMemo(()=>{const Le=[],ne=new Map,Ee=new Map,Ce=new Map;n.forEach((ee,as)=>{ee.type==="agent"&&(ne.has(ee.jobId)||(ne.set(ee.jobId,[]),Ee.set(ee.jobId,as)),ne.get(ee.jobId).push({at:ee.at,event:ee.event}),ee.variant&&!Ce.has(ee.jobId)&&Ce.set(ee.jobId,ee.variant))});const Xe=(ee,as)=>{if(as.length===0)return;const ds=ne.get(ee)??[],Ks=BC(ds.map(js=>js.event),as),tt=new Date().toISOString();ne.set(ee,Ks.map((js,Ds)=>{if(Ds<ds.length)return ds[Ds];const ht=`${ee}:${Ds}`;return je.current.has(ht)||je.current.set(ht,tt),{at:je.current.get(ht),event:js}}))};r&&Xe(r.id,l);const ue=(R??[]).filter(ee=>ee.job.id!==r?.id);for(const ee of ue)Xe(ee.job.id,ee.live),ee.variant&&!Ce.has(ee.job.id)&&Ce.set(ee.job.id,ee.variant);const xe=new Set([...r&&te?[r.id]:[],...ue.filter(ee=>Bi(ee.job)).map(ee=>ee.job.id)]),Be=new Set;for(const ee of n)ee.type==="agent"&&ee.event.kind==="user_message_delivered"&&Be.add(ee.event.clientId);for(const ee of l)ee.kind==="user_message_delivered"&&Be.add(ee.clientId);const _e=new Set;for(const ee of n)ee.type==="agent"&&ee.event.kind==="user_message_read"&&_e.add(ee.event.clientId);for(const ee of l)ee.kind==="user_message_read"&&_e.add(ee.clientId);const ge=new Set;for(const ee of n)ee.type==="agent"&&ee.event.kind==="user_message_not_delivered"&&ge.add(ee.event.clientId);for(const ee of l)ee.kind==="user_message_not_delivered"&&ge.add(ee.clientId);const qe=new Set((S??[]).map(ee=>ee.clientId)),Ye=new Set;for(const ee of n)ee.type==="user"&&ee.clientId&&Ye.add(ee.clientId);const Ls=ee=>{if(!(!ee.clientId||!ee.mode)){if(qe.has(ee.clientId))return"queued";if(ge.has(ee.clientId))return"notDelivered";if(_e.has(ee.clientId))return"delivered";if(Be.has(ee.clientId)||ee.deliveredAt)return"sent";if(ee.jobId&&ee.jobId===r?.id&&te)return r?.state==="queued"&&ee.mode==="redirect"?"pendingStart":"pending"}},et=(ee,as)=>{const ds=Ls(ee),Ks=ee.group?[...new Set(ee.pins.map(Ds=>Ds.variant).filter(Ds=>!!Ds))].sort(rx):[],tt=ee.context&&(ee.context.codebases.length>0||ee.context.assets.length>0)?{context:ee.context}:{},js=ee.attachments?.length?{files:ee.attachments}:{};return{key:as,kind:"user",at:ee.at,text:ee.text,pins:ee.pins,...ds?{state:ds}:{},...ee.mode==="redirect"?{redirect:!0}:{},...Ks.length?{variants:Ks}:{},...tt,...js}},bs=new Map,Us=new Set,Me=new Map;n.forEach((ee,as)=>{if(ee.type==="agent"){Me.set(ee.jobId,(Me.get(ee.jobId)??0)+1);return}ee.type!=="user"||!ee.jobId||!ee.mode||!Me.has(ee.jobId)||(Us.add(as),bs.has(ee.jobId)||bs.set(ee.jobId,[]),bs.get(ee.jobId).push({anchor:Me.get(ee.jobId),item:et(ee,`e${as}`)}))});const ss=[];for(const ee of G){if(Ye.has(ee.clientId))continue;const as={key:`out:${ee.clientId}`,kind:"user",at:ee.at,text:ee.text,pins:ee.pins,state:ge.has(ee.clientId)?"notDelivered":_e.has(ee.clientId)?"delivered":Be.has(ee.clientId)?"sent":ee.phase,...ee.mode==="redirect"?{redirect:!0}:{}},ds=r&&ne.has(r.id)?r.id:null;if(!ds){ss.push(as);continue}const Ks=`${ds}\0${ee.clientId}`;he.current.has(Ks)||he.current.set(Ks,ne.get(ds).length),bs.has(ds)||bs.set(ds,[]),bs.get(ds).push({anchor:he.current.get(Ks),item:as})}const Ie=ee=>gs.filter(as=>ee===null?!ne.has(as.approval.jobId):as.approval.jobId===ee).map(as=>({key:`ap:${as.approval.id}`,kind:"approval",shown:as})),ys=ee=>{const as=ne.get(ee),ds=Ie(ee),Ks=gs.filter(Os=>Os.approval.jobId===ee).map(Os=>Date.parse(Os.approval.createdAt)).filter(Number.isFinite),tt=Ks.length>0?Math.min(...Ks):1/0,js=bs.get(ee)??[],Ds=Os=>Os.anchor>=as.length&&"at"in Os.item&&Date.parse(Os.item.at)>=tt,ht=Ce.get(ee);return[...qC(se.web.liveUi.interruptedRow,ee,as,xe.has(ee),Ne.has(ee),Re.has(ee),Fe,js.filter(Os=>!Ds(Os))).map(Os=>ht&&(Os.kind==="agent"||Os.kind==="error"||Os.kind==="question"||Os.kind==="system")?{...Os,variant:ht}:Os),...ds,...js.filter(Ds).map(Os=>Os.item)]},ns=new Map;let Ys=null;const mt=new Map;for(const ee of n)if(ee.type==="group-turn")for(const as of ee.outcome)mt.set(`${ee.jobId}\0${as.variant}`,as);const Ns=new Map,ct=(ee,as)=>(R??[]).find(ds=>ds.job.parentJobId===ee&&(ds.job.variant??ds.variant)===as),ls=(ee,as)=>{const ds=`${ee}\0${as}`;let Ks=Ns.get(ds);if(!Ks){const tt=ct(ee,as);Ks={key:`hp:${ds}`,kind:"helper",variant:as,groupJobId:ee,open:is.has(ds),state:tt&&Bi(tt.job)?{kind:"working",step:Xr(tt.live)}:{kind:"done"},children:[],cards:[]},Ns.set(ds,Ks),Le.push(Ks)}return Ks},Is=(ee,as)=>{for(const ds of ys(as))(ds.kind==="approval"?ee.cards:ee.children).push(ds)};n.forEach((ee,as)=>{if(ee.groupJobId&&ee.variant&&ee.type!=="user"){const js=ls(ee.groupJobId,ee.variant),Ds=`e${as}`;if(ee.type==="agent"){Ee.get(ee.jobId)===as&&Is(js,ee.jobId);return}ee.type==="version"?(js.children.push({key:Ds,kind:"version",at:ee.at,n:ee.n,complete:ee.status==="complete",variant:ee.variant}),js.state.kind!=="working"&&(js.state={kind:"version",n:ee.n,complete:ee.status==="complete"})):ee.type==="system"&&(js.children.push({key:Ds,kind:"system",at:ee.at,level:ee.level,text:ee.text,...ee.origin==="agent"?{agent:!0}:{},variant:ee.variant}),js.state.kind!=="working"&&typeof ee.keptVersion=="number"?js.state={kind:"unchanged"}:js.state.kind!=="working"&&ee.level==="error"&&(js.state={kind:"failed"}));return}const ds=ee.variant??"",Ks=ns.get(ds)??null;if(ee.type==="agent"){Ks&&ee.event.kind==="result"&&!ee.event.ok&&!ee.event.interrupted&&(Ks.failed=!0),Ee.get(ee.jobId)===as&&(Ys=null,Le.push(...ys(ee.jobId)));return}const tt=`e${as}`;if(ee.type==="user"&&Us.has(as))ns.set(ds,{text:ee.text,pins:ee.pins,failed:!1});else if(ee.type==="user"){const js=Ys;if(ee.variant&&ee.fanout&&js&&js.fanout===ee.fanout&&!js.variants.includes(ee.variant))js.variants.push(ee.variant);else{const ht=Ks!==null&&Ks.failed&&Sv(Ks.text,ee.text)&&_C(Ks.pins,ee.pins)?{key:tt,kind:"retried",at:ee.at}:et(ee,tt);Le.push(ht),Ys=ht.kind==="user"&&ee.variant?{...ht,variants:[ee.variant],...ee.fanout?{fanout:ee.fanout}:{}}:null,Ys&&(Le[Le.length-1]=Ys)}ns.set(ds,{text:ee.text,pins:ee.pins,failed:!1})}else ee.type==="version"?(Ks&&(Ks.failed=!1),Le.push({key:tt,kind:"version",at:ee.at,n:ee.n,complete:ee.status==="complete",...ee.variant?{variant:ee.variant}:{}})):ee.type==="system"&&ee.origin==="brief"?Le.push({key:tt,kind:"briefStart",at:ee.at,text:ee.text}):ee.type==="system"&&ee.subtitles&&t?Le.push({key:tt,kind:"subtitles",slug:e,creative:t,entry:ee}):ee.type==="system"?(Ks&&ee.level==="error"&&(Ks.failed=!0),Le.push({key:tt,kind:"system",at:ee.at,level:ee.level,text:ee.text,...ee.origin==="agent"?{agent:!0}:{},...ee.variant?{variant:ee.variant}:{},...ee.analysisWait&&t?{wait:{slug:e,creative:t}}:{}})):ee.type==="group-turn"&&Le.push({key:tt,kind:"groupTurn",at:ee.at,outcome:ee.outcome,stopped:ee.stopped===!0,...ee.usage?{usage:ee.usage}:{}})}),r&&ne.has(r.id)&&!Ee.has(r.id)&&Le.push(...ys(r.id));for(const ee of ue){if(!ne.has(ee.job.id)&&!(ee.job.parentJobId&&Bi(ee.job))||Ee.has(ee.job.id))continue;const as=ee.job.variant??ee.variant;if(ee.job.parentJobId&&as){const ds=ls(ee.job.parentJobId,as);ne.has(ee.job.id)&&Is(ds,ee.job.id);continue}Le.push(...ys(ee.job.id))}for(const[ee,as]of Ns){if(as.state.kind==="working")continue;const ds=mt.get(ee);ds&&(as.state=ds.status==="stopped"?{kind:"stopped"}:ds.status==="failed"?{kind:"failed"}:ds.status==="unchanged"?{kind:"unchanged"}:ds.version!==null?{kind:"version",n:ds.version,complete:ds.status==="complete"}:as.state)}Le.push(...Ie(null)),Le.push(...ss);for(const ee of J??[])Le.push({key:`card-${ee.key}`,kind:"card",node:ee.node});const Hs=gs.some(ee=>!ee.leaving&&ee.approval.jobId===r?.id);return te&&!Hs&&Le.push({key:"typing",kind:"typing"}),H&&Le.unshift({key:"intro",kind:"intro",node:H}),Le},[n,r,l,te,Ne,Re,is,gs,Oe,G,S,se,R,H,J]),we=i.useRef(!1);i.useEffect(()=>{we.current=!0},[]);const ze=i.useRef(null),We=i.useRef(!0);i.useLayoutEffect(()=>{const Le=ze.current;Le&&We.current&&(Le.scrollTop=Le.scrollHeight)},[Ke.length]);const Rs=i.useRef(null),us=i.useRef(null);i.useLayoutEffect(()=>{const Le=us.current,ne=Rs.current;if(!Le||!ne)return;const Ee=()=>{const Xe=`${Le.offsetHeight}px`;if(ne.style.getPropertyValue("--ms-dock-h")===Xe)return;ne.style.setProperty("--ms-dock-h",Xe);const ue=ze.current;ue&&We.current&&(ue.scrollTop=ue.scrollHeight)};if(Ee(),typeof ResizeObserver>"u")return;const Ce=new ResizeObserver(Ee);return Ce.observe(Le),()=>Ce.disconnect()},[]);const fs=()=>{const Le=ze.current;Le&&(We.current=Le.scrollHeight-Le.scrollTop-Le.clientHeight<48)},fe=Le=>ne=>Le(Ee=>{const Ce=new Set(Ee);return Ce.has(ne)?Ce.delete(ne):Ce.add(ne),Ce}),Ge=fe(Q),De=fe(Ue),os=Le=>Qe(ne=>{const Ee=new Set(ne);return Ee.has(Le)?Ee.delete(Le):Ee.add(Le),Ee}),Ze=Le=>{Ue(ne=>ne.has(Le)?ne:new Set(ne).add(Le)),requestAnimationFrame(()=>{const ne=[...ze.current?.querySelectorAll("[data-details]")??[]].find(Ee=>Ee.dataset.details===Le);ne?.focus(),ne?.scrollIntoView?.({block:"nearest"})})},vs=Ke.length===0;return s.jsxs("div",{ref:Rs,className:"ms-convo",children:[E&&!P?s.jsx(pC,{group:E.group,current:E.current,all:E.all,missing:E.missing??[],onSelect:E.onSelect}):null,s.jsxs("ol",{ref:ze,className:"ms-convo-list",role:"log","aria-label":U.label,onScroll:fs,children:[vs&&s.jsx("li",{className:"ms-convo-empty",children:s.jsx(Rt,{icon:"comment",title:U.emptyTitle,sub:U.emptySub})}),Ke.map(Le=>{const ne=Ee=>s.jsx(HC,{item:Ee,formatName:m,onToggleFold:Ge,onToggleDetails:De,onOpenDetails:Ze,onSelectVersion:x,versionExtra:p,versionNote:g,versionSummary:b,onGone:As,self:N,onOpenVariant:C,usageOf:T},Ee.key);return s.jsxs(KC,{animate:we.current&&Le.kind!=="approval",children:[Le.kind==="helper"?s.jsx(VC,{item:Le,onToggle:()=>os(Le.key.slice(3)),children:Le.children.map(ne)}):ne(Le),Le.kind==="helper"?Le.cards.map(Ee=>s.jsx("div",{className:"ms-convo-helper-card",children:ne(Ee)},Ee.key)):null]},Le.key)})]}),s.jsxs("div",{ref:us,className:"ms-convo-dock",children:[r?.waitReason?s.jsxs("p",{className:"ms-convo-wait",role:"status",children:[s.jsx(F,{name:"clock",size:12}),se.web.variantGroup.waitReasons[r.waitReason]]}):null,s.jsx(cC,{slug:e,creative:t,queued:S??[],working:te,onChanged:()=>k?.(),...de?{ops:de}:{}}),s.jsx(eE,{transport:W,top:Z,tools:A,label:_,placeholderText:X,draft:ae,extraContent:K,sendOff:I,outbox:oe,onQueueChanged:k,slug:e,creative:t,job:te&&(P||!E?.all)?r:void 0,fanout:E?.all&&!P?E.runAll:void 0,latestJobId:r?.id,snapshots:v,pins:o,onRemovePin:c,onEditPin:d,formatName:m,canGenerate:u,onSent:h,beforeSend:f,appliesTo:P?void 0:y,brief:w,onBriefSaved:j,...P?{single:{others:z??[],...O?{onRemoveOther:O}:{}}}:{}}),L]})]})}function VC({item:e,onToggle:t,children:n}){const a=V().web.conversation.helperRow,r=e.state,l=r.kind==="working"?r.step?a.workingStep({step:r.step}):a.working:r.kind==="version"?r.complete?a.ready({n:r.n}):a.incomplete({n:r.n}):r.kind==="unchanged"?a.unchanged:r.kind==="failed"?a.failed:r.kind==="stopped"?a.stopped:a.done;return s.jsxs("div",{className:"ms-convo-helper","data-helper":e.variant,children:[s.jsxs("button",{type:"button",className:"ms-convo-fold ms-convo-helper-row","aria-expanded":e.open,onClick:t,children:[r.kind==="working"?s.jsx(Ts,{decorative:!0}):s.jsx("span",{className:"ms-step-check","aria-hidden":"true",children:s.jsx(F,{name:r.kind==="failed"?"warn":"check",size:13,strokeWidth:2})}),s.jsx(Ia,{list:[e.variant]}),s.jsx("span",{className:"ms-convo-helper-text",title:l,children:l}),s.jsx(F,{name:"chevron",size:12,className:"ms-chev"})]}),e.open?s.jsx("div",{className:"ms-convo-helper-steps",children:n}):null]})}function KC({animate:e,children:t}){const n=i.useRef(null),a=i.useRef(e);return i.useLayoutEffect(()=>{a.current&&Gs(n.current?.firstElementChild??null,{y:8})},[]),s.jsx("li",{ref:n,children:t})}function ho({at:e}){const t=rs();return Number.isNaN(new Date(e).getTime())?null:s.jsx("time",{dateTime:e,children:ca(t,e,Wr)})}const fo=()=>s.jsx("span",{className:"ms-msg-avatar ms-agent","aria-hidden":"true",children:s.jsx("svg",{width:"10",height:"10",viewBox:"0 0 12 12",children:s.jsx("path",{d:"M3 2.5v7l6-3.5-6-3.5Z",fill:"currentColor"})})});function Sl(e,t,n,a,r){const l=n?.(e.format)??e.format,o=nC(e,l,a,r);if(o)return o;const c=a.web.chat.pin({n:t,format:l});return e.timeSec===null?c:`${c} ${a.web.conversation.atSeconds({time:Vs(r,e.timeSec,{minimumFractionDigits:1,maximumFractionDigits:1})})}`}function po({pin:e,text:t}){return s.jsxs("span",{className:"ms-pin-label",children:[s.jsx("span",{className:"ms-pin-ref",children:t}),e.note?s.jsx("span",{className:"ms-pin-note",children:e.note}):null]})}function WC({at:e,event:t,variant:n}){const r=V().web.questionUi,l=t.outcome==="expired"?r.expired:t.outcome==="cancelled"?r.cancelled:r.skipped;return s.jsxs("article",{className:"ms-msg","aria-label":r.historyLabel,children:[s.jsx(fo,{}),s.jsxs("div",{className:"ms-msg-body",children:[s.jsxs("span",{className:"ms-msg-meta",children:[s.jsx("b",{children:r.historyLabel}),"·",s.jsx(ho,{at:e}),s.jsx(Ia,{list:n?[n]:void 0})]}),(Array.isArray(t.items)?t.items:[]).map((o,c)=>s.jsxs("div",{className:"ms-question-done",children:[typeof o.header=="string"&&o.header&&s.jsx(Lr,{className:"ms-question-header",text:o.header,max:Pr.header}),typeof o.question=="string"&&s.jsx(Lr,{className:"ms-question-text",text:o.question,max:Pr.question}),typeof o.answer=="string"?s.jsxs("span",{className:"ms-question-answer",children:[s.jsx("b",{children:r.yourAnswer}),s.jsx("span",{children:o.answer})]}):s.jsx("span",{className:"ms-approval-note",children:l})]},c))]})]})}function Ia({list:e}){const t=V().web.variantGroup;return e?.length?s.jsx(s.Fragment,{children:e.map(n=>s.jsx("span",{className:"ms-vchip",title:t.letterLabel({letter:n.toUpperCase()}),children:n.toUpperCase()},n))}):null}function HC({item:e,formatName:t,onToggleFold:n,onToggleDetails:a,onOpenDetails:r,onSelectVersion:l,versionExtra:o,versionNote:c,versionSummary:d,onGone:m,self:u,onOpenVariant:h,usageOf:f}){const x=V(),p=rs(),g=x.web.chat;switch(e.kind){case"user":return s.jsxs("article",{className:"ms-msg ms-you","aria-label":g.you,children:[s.jsx("span",{className:"ms-msg-avatar ms-you","aria-hidden":"true",children:s.jsx(F,{name:"user",size:13})}),s.jsxs("div",{className:"ms-msg-body",children:[s.jsxs("span",{className:"ms-msg-meta",children:[s.jsx("b",{children:g.you}),"·",s.jsx(ho,{at:e.at}),s.jsx(Ia,{list:e.variants}),e.redirect&&s.jsx("span",{className:"ms-pill ms-accent",children:x.web.liveUi.state.redirect}),e.state&&s.jsx("span",{className:le("ms-pill",e.state==="delivered"?"ms-ok":e.state==="notDelivered"?"ms-warn":"ms-neutral"),"data-state":e.state,title:e.state==="sent"?x.web.liveUi.sentHint:e.state==="delivered"?x.web.liveUi.deliveredHint:void 0,children:x.web.liveUi.state[e.state]})]}),e.text&&s.jsx("div",{className:"ms-msg-bubble",children:e.text}),e.state==="notDelivered"&&s.jsx("p",{className:"ms-composer-note",role:"status",children:x.web.liveUi.notDeliveredReason}),e.pins.length>0&&s.jsx("div",{className:"ms-msg-pins",children:e.pins.map((b,v)=>s.jsxs("span",{className:"ms-chip",title:b.note||void 0,children:[s.jsx(F,{name:"comment",size:11}),s.jsx(po,{pin:b,text:Sl(b,v+1,t,x,p)})]},v))}),e.context&&s.jsxs("div",{className:"ms-msg-pins",children:[e.context.codebases.map(b=>s.jsxs("span",{className:"ms-chip ms-msg-folder",title:b,children:[s.jsx(F,{name:"folder",size:11}),s.jsx("span",{className:"ms-pin-ref",children:b})]},`c:${b}`)),e.context.assets.map(b=>s.jsxs("span",{className:"ms-chip",title:b,children:[s.jsx(F,{name:"image",size:11}),s.jsx("span",{className:"ms-pin-ref",children:b.split("/").pop()})]},`a:${b}`))]}),e.files&&s.jsx("ul",{className:"ms-msg-pins ms-msg-files","aria-label":g.attachedFiles,children:e.files.map(b=>s.jsxs("li",{className:"ms-chip",title:b,children:[s.jsx(F,{name:wv(b),size:11}),s.jsx("span",{className:"ms-pin-ref",children:b.split("/").pop()})]},b))})]})]});case"question":return s.jsx(WC,{at:e.at,event:e.event,variant:e.variant});case"retried":return s.jsxs("div",{className:"ms-convo-retried",children:[s.jsx(F,{name:"refresh",size:11}),s.jsx("span",{children:g.retried({time:ca(p,e.at,Wr)})})]});case"agent":return s.jsxs("article",{className:le("ms-msg",e.summary&&"ms-summary"),"aria-label":e.summary?g.summary:g.agent,children:[s.jsx(fo,{}),s.jsxs("div",{className:"ms-msg-body",children:[s.jsxs("span",{className:"ms-msg-meta",children:[s.jsx("b",{children:g.agent}),"·",s.jsx(ho,{at:e.at}),s.jsx(Ia,{list:e.variant?[e.variant]:void 0}),e.summary&&s.jsx("span",{className:"ms-pill ms-ok",children:g.summary})]}),s.jsx("div",{className:"ms-msg-bubble",children:s.jsx(Ro,{text:e.text})})]})]});case"step":return s.jsxs("div",{className:"ms-step",children:[s.jsx("span",{className:"ms-step-check","aria-hidden":"true",children:s.jsx(F,{name:"check",size:13,strokeWidth:2})}),s.jsx("span",{className:"ms-step-text",children:e.text}),s.jsx(ho,{at:e.at})]});case"fold":return s.jsxs("button",{type:"button",className:"ms-convo-fold","aria-expanded":e.open,onClick:()=>n(e.jobId),children:[s.jsx("span",{className:"ms-step-check","aria-hidden":"true",children:s.jsx(F,{name:"check",size:13,strokeWidth:2})}),g.steps({count:e.count}),s.jsx(F,{name:"chevron",size:12,className:"ms-chev"})]});case"error":return s.jsxs("p",{role:"alert",className:"ms-convo-error",children:[s.jsx(Ia,{list:e.variant?[e.variant]:void 0}),g.failed({error:e.text})]});case"details":return s.jsx(XC,{jobId:e.jobId,entries:e.entries,open:e.open,onToggle:()=>a(e.jobId)});case"autoline":return s.jsx(ZC,{jobId:e.jobId,log:e.log,onOpen:r});case"version":{const b=e.variant!==void 0&&u!==void 0&&e.variant!==u?e.variant:null,v=b?null:d?.(e.n)??null;return s.jsxs("div",{className:"ms-convo-version",children:[s.jsx(Ia,{list:e.variant?[e.variant]:void 0}),s.jsxs("span",{className:le("ms-pill",e.complete?"ms-ok":"ms-warn"),children:["v",e.n," · ",e.complete?x.web.status.ready:x.web.status.incomplete]}),v?s.jsx("span",{className:"ms-convo-version-summary",children:v}):null,s.jsx("span",{className:"ms-grow"}),b?null:o?.(e.n)??null,b?h?s.jsx($,{size:"sm",variant:"outline",onClick:()=>h(b),children:x.web.conversation.openVariantVersion({letter:b.toUpperCase(),n:e.n})}):null:s.jsx($,{size:"sm",variant:"outline",onClick:()=>l?.(e.n),children:x.web.conversation.viewVersion({n:e.n})}),b?null:c?.(e.n)??null]})}case"system":{const b=s.jsx(Ia,{list:e.variant?[e.variant]:void 0});return e.level==="error"?s.jsxs("p",{role:"alert",className:"ms-convo-system ms-error",children:[b,e.text]}):e.level==="warning"?s.jsxs("p",{className:"ms-convo-system ms-warning",children:[s.jsx(F,{name:"warn",size:13}),b,s.jsx("span",{children:e.text})]}):e.agent?s.jsxs("p",{className:"ms-convo-system ms-convo-action",children:[s.jsx(F,{name:"sparkle",size:12}),b,s.jsx("span",{className:"ms-convo-action-tag",children:x.web.conversation.agentAction}),s.jsx("span",{children:e.text})]}):e.wait?s.jsx(GC,{slug:e.wait.slug,creative:e.wait.creative,chip:b,text:e.text}):s.jsxs("p",{className:"ms-convo-system",children:[b,e.text]})}case"approval":return s.jsx("div",{className:"ms-convo-approval",children:s.jsx(ri,{approval:e.shown.approval,leaving:e.shown.leaving,onGone:m})});case"groupTurn":return s.jsxs("div",{className:"ms-convo-groupturn","data-group-turn":!0,children:[s.jsx(F,{name:"check",size:12}),s.jsxs("span",{children:[kg(x,e.outcome),e.stopped?` · ${x.web.conversation.groupTurn.turnStopped}`:""]}),s.jsx("span",{className:"ms-grow"}),e.usage?f?.(e.usage)??null:null]});case"briefStart":return s.jsxs("div",{className:"ms-convo-version ms-convo-briefstart",children:[s.jsx(F,{name:"sparkle",size:14,className:"ms-convo-briefstart-mark"}),s.jsx("b",{children:x.web.briefSession.created}),s.jsx("span",{className:"ms-convo-version-summary",children:e.text})]});case"card":return s.jsx("div",{className:"ms-convo-card",children:e.node});case"subtitles":return s.jsx(DC,{slug:e.slug,creative:e.creative,entry:e.entry});case"intro":return s.jsxs("article",{className:"ms-msg","aria-label":g.agent,children:[s.jsx(fo,{}),s.jsxs("div",{className:"ms-msg-body",children:[s.jsx("span",{className:"ms-msg-meta",children:s.jsx("b",{children:g.agent})}),s.jsx("div",{className:"ms-msg-bubble",children:e.node})]})]});case"typing":return s.jsxs("div",{className:"ms-msg ms-convo-typing",children:[s.jsx(fo,{}),s.jsx("div",{className:"ms-msg-bubble",children:s.jsx(Bu,{})})]})}}function GC({slug:e,creative:t,chip:n,text:a}){const r=V(),l=i.useContext(Mn)?.live??Nm,o=pN(e,t,l).length>0,[c,d]=i.useState(!1),m=async()=>{d(!0);try{await q.skipAnalysisWait(e,t)}catch(u){Pe.show(r.videoAnalysis.skipFailed({detail:pe(u)}))}finally{d(!1)}};return s.jsxs("p",{className:"ms-convo-system ms-convo-wait",children:[n,s.jsx("span",{children:a}),o?s.jsxs(s.Fragment,{children:[" · ",s.jsx("button",{type:"button",className:"ms-convo-skip",disabled:c,onClick:()=>{m()},children:r.videoAnalysis.skip})]}):null]})}function XC({jobId:e,entries:t,open:n,onToggle:a}){const r=V(),l=r.web.chat.detailKinds,o=i.useId(),c=d=>{switch(d.kind){case"session":return[l.session,d.model?`${d.sessionId} · ${d.model}`:d.sessionId];case"text":return[l.text,d.text];case"tool_use":return[l.tool,s.jsxs(s.Fragment,{children:[s.jsx("b",{children:d.name}),s.jsx("pre",{children:JSON.stringify(d.input,null,2)})]})];case"tool_result":return[d.isError?l.error:l.result,s.jsx("pre",{children:d.content}),d.isError];case"rate_limit":return[l.limit,d.status];case"progress":return[l.step,d.text];case"stderr":return[l.log,d.text,!0];case"parse_error":return[l.unreadable,d.line,!0];case"usage":case"auto_approved":case"approval_decided":case"question_answered":return["",""];case"user_message_delivered":case"user_message_not_delivered":case"user_message_read":case"interrupted":return["",""];case"result":return d.ok?[l.done,d.text??""]:d.interrupted?[l.stopped,d.text??""]:[l.failed,d.error??"",!0]}};return s.jsxs("div",{className:"ms-convo-details",children:[s.jsxs("button",{type:"button",className:"ms-convo-fold","aria-expanded":n,"aria-controls":o,"data-details":e,onClick:a,children:[s.jsx(F,{name:"terminal",size:12}),r.web.chat.details({count:t.length}),s.jsx(F,{name:"chevron",size:12,className:"ms-chev"})]}),n&&s.jsx("ul",{id:o,className:"ms-convo-log",tabIndex:0,children:t.map(d=>{if("row"in d)return s.jsx(Cv,{row:d.row},d.key);const[m,u,h]=c(d.event);return s.jsxs("li",{children:[s.jsx("span",{className:"ms-kind",children:m}),s.jsx("span",{className:le("ms-val",h&&"ms-err"),children:u})]},d.key)})})]})}const Of=e=>{const t=e.split(`
|
|
14
|
+
`,1)[0]??"";return t.length>120?`${t.slice(0,119)}…`:t};function ZC({jobId:e,log:t,onOpen:n}){const a=V().web.chat,r=i.useId();return s.jsxs("p",{className:"ms-convo-autoline",children:[s.jsx("span",{className:"ms-step-check","aria-hidden":"true",children:s.jsx(F,{name:t.sandboxed?"shield":"terminal",size:13})}),s.jsx("span",{id:r,children:a.commandsRan({count:t.ran,approved:t.approved,sandbox:t.sandboxed,attempted:t.attempted})}),s.jsxs("span",{className:"ms-convo-autoline-more",children:[s.jsx("span",{"aria-hidden":"true",children:"·"}),s.jsx($,{size:"sm",variant:"ghost","aria-describedby":r,onClick:()=>n(e),children:a.autoDetails})]})]})}const JC={auto:"check",approved:"user",denied:"close",notRun:"minus",error:"warn",interrupted:"pause"};function Cv({row:e}){const t=V(),n=t.web.chat,[a,r]=i.useState(!1),l=i.useId(),o=am(e.explanation,t),c=e.kind==="read"?e.file:e.command,d=e.kind==="read"?"auto":e.mark,m=e.kind==="read"?n.readFile({file:Of(e.file)}):o?.title||`Bash: ${Of(e.command)}`;return s.jsxs("li",{className:le("ms-convo-auto",e.kind==="command"&&!e.counted&&"ms-convo-auto-off"),"data-mark":e.kind==="read"?"read":e.mark,children:[s.jsxs("button",{type:"button",className:"ms-convo-auto-row","aria-expanded":a,"aria-controls":l,onClick:()=>r(u=>!u),children:[s.jsx("span",{className:"ms-step-check","aria-hidden":"true",children:s.jsx(F,{name:e.kind==="read"?"eye":JC[d],size:13,strokeWidth:2})}),s.jsx("span",{className:"ms-convo-auto-text",children:m}),d!=="auto"?s.jsx("span",{className:"ms-convo-mark",children:n.commandMarks[d]}):null,o&&e.explanation?s.jsx(Ng,{explanation:e.explanation}):null,s.jsx(F,{name:"chevron",size:12,className:"ms-chev"})]}),a&&s.jsx("pre",{id:l,tabIndex:0,"aria-label":t.web.approvalUi.fullCommand,children:c})]})}const YC=new Set(["formats-not-in-brief","job-running"]),QC=1e4;function eE({transport:e,top:t,tools:n,label:a,placeholderText:r,draft:l,extraContent:o,sendOff:c,outbox:d,onQueueChanged:m,slug:u,creative:h,job:f,fanout:x,latestJobId:p,snapshots:g,pins:b,onRemovePin:v,onEditPin:y,formatName:w,canGenerate:j,onSent:S,beforeSend:k,appliesTo:E,brief:N,onBriefSaved:C,single:R}){const P=V(),z=rs(),O=P.web.chat,T=P.web.liveUi,W=i.useId(),Z=R?.others??[],A=i.useMemo(()=>Z.length?[...b,...Z]:b,[b,Z]),[L,_]=i.useState(l?.text??""),X=i.useRef(l?.nonce);i.useEffect(()=>{!l||l.nonce===X.current||(X.current=l.nonce,_(l.text))},[l]);const ae=!e&&!x,[K,I]=i.useState([]),H=i.useRef(new Set),de=(Me,ss)=>{ss!==void 0&&!H.current.has(ss)||I(Ie=>[...Ie,...Me.filter(ys=>!Ie.includes(ys))])},J=(Me,ss)=>{(ss===void 0||H.current.has(ss))&&Qe(Me)},se=Me=>I(ss=>ss.filter(Ie=>Ie!==Me)),[U,te]=i.useState([]),G=Me=>{"started"in Me?H.current.add(Me.started.id):H.current.delete(Me.settled),te(ss=>"started"in Me?[...ss,Me.started]:ss.filter(Ie=>Ie.id!==Me.settled))},re=Me=>{H.current.delete(Me),te(ss=>ss.filter(Ie=>Ie.id!==Me))};i.useEffect(()=>{I([]),te([]),H.current.clear()},[h,!!x]);const[oe,Ne]=i.useState(!1),Q=i.useRef(!1),[Re,Ue]=i.useState(null),[is,Qe]=i.useState(null),[gs,As]=i.useState(null),hs=()=>{Ue(null),Q.current=!1};i.useEffect(()=>{Re&&p===Re&&hs()},[Re,p]),i.useEffect(()=>{if(!Re)return;const Me=setTimeout(hs,QC);return()=>clearTimeout(Me)},[Re]);const Oe=i.useRef(g);i.useEffect(()=>{g!==Oe.current&&(Oe.current=g,hs())},[g]);const be=!!f,[Fe,je]=i.useState(null);i.useEffect(()=>{if(je(null),!be)return;let Me=!0;return Promise.resolve().then(()=>q.getAgentCapabilities()).then(ss=>{Me&&je({liveInput:ss?.liveInput===!0})}).catch(()=>{Me&&je({liveInput:!1})}),()=>{Me=!1}},[be]);const he=Fe??{liveInput:!1},[Ke,we]=i.useState(!1),ze=i.useRef(null);i.useEffect(()=>{be||we(!1)},[be]),i.useEffect(()=>{Ke&&ze.current?.focus()},[Ke]);const We=i.useRef(null),[Rs,us]=i.useState(void 0),fs=Array.isArray(Rs)&&Rs.length>0,fe=ae&&!be?K:[],Ge=L.trim().length>0||(x?fs:A.length>0||fe.length>0)||!!o,De=oe||Re!==null,os=be||De,Ze=!c&&(be?Ge&&!oe&&(Fe!==null||Ke):!De&&Ge&&U.length===0),vs=E?.primaries.map(Me=>Me.id)??[],Le=Me=>E?.followerOf(Me)??Me,ne=x?[]:A,Ee=E?ne.length?fC(ne.map(Me=>Me.format),Le,vs):E.fallback?.filter(Me=>vs.includes(Me))??null:null,Ce=Array.isArray(Rs)?Rs.filter(Me=>vs.includes(Me)):Rs,Xe=E?Ce===void 0||Array.isArray(Ce)&&Ce.length===0?Ee?.length?Ee:null:Ce:null,ue=vs.join(",");i.useEffect(()=>{us(Me=>{if(!Array.isArray(Me))return Me;const ss=Me.filter(Ie=>ue.split(",").includes(Ie));return ss.length===Me.length?Me:ss.length?ss:void 0})},[ue]);const xe=async(Me,ss=!1)=>{if(!(os||Q.current)){Q.current=!0,Qe(null),As(null),Ne(!0);try{if(k&&!await k()){Q.current=!1;return}if(x){const ys=!Me.text&&!Me.pins?.length&&!Me.formats?.length;if(ys&&!ss){Q.current=!1;return}const ns=await x(ys?null:Me);Q.current=!1;const Ys=[...ns.skipped.map(mt=>mt.toUpperCase()),...Object.entries(ns.failed).map(([mt,Ns])=>`${mt.toUpperCase()} (${Ns})`)];_(""),us(void 0),As(`${P.web.variantGroup.sentToAll({count:Object.keys(ns.jobs).length+ns.queued.length})}${Ys.length?` · ${P.web.variantGroup.sentToAllRefused({list:Ys.join(", ")})}`:""}`),S?.({pins:Me.pins??[]});return}if(e){We.current?.kind!=="start"&&(We.current={id:Xl(),kind:"start"});const ys=await e.start({clientId:We.current.id,text:Me.text??""});We.current=null,ys&&ys.id!==p?Ue(ys.id):Q.current=!1,_(""),S?.({pins:[]});return}const Ie=await q.sendCreativeTurn(u,h,Me);Ie&&typeof Ie.id=="string"&&Ie.id!==p?Ue(Ie.id):Q.current=!1,_(""),Me.attachments?.length&&I(ys=>ys.filter(ns=>!Me.attachments.includes(ns))),us(void 0),S?.({pins:Me.pins??[]})}catch(Ie){if(x){Qe(P.web.variantGroup.sendAllFailed({detail:pe(Ie)})),Q.current=!1;return}if(e){Qe(Ie instanceof lt&&Ie.status>=400&&Ie.status<500?Gl(Ie,P):O.sendFailed({detail:pe(Ie)})),Q.current=!1;return}const ys=Zr(Ie)==="attachment-invalid"&&Ie instanceof lt?(Ie.problems??[]).filter(ns=>Me.attachments?.includes(ns)):[];if(ys.length){I(ns=>ns.filter(Ys=>!ys.includes(Ys))),Qe(O.attachmentGone({names:ys.map(ns=>ns.split("/").pop()??ns).join(", "),count:ys.length})),Q.current=!1;return}Qe(YC.has(Zr(Ie)??"")?xv(Ie,P,{label:""}):Ie instanceof lt&&Ie.status===409?O.sendBusy:O.sendFailed({detail:pe(Ie)})),Q.current=!1}finally{Ne(!1)}}},Be=async Me=>{if(!f||!Ze||Q.current)return;Q.current=!0,Qe(null),As(null),Ne(!0),We.current?.kind!==Me&&(We.current={id:Xl(),kind:Me});const ss=We.current.id,Ie=L.trim(),ys=A;Me!=="queued"&&d.add({clientId:ss,text:Ie,pins:ys,at:new Date().toISOString(),mode:Me==="redirect"?"redirect":"live",phase:"sending"});try{let ns;Me==="redirect"?ns=(await q.redirectJob(f.id,{clientId:ss,text:Ie,...ys.length?{pins:ys}:{}})).outcome:e?ns=(await e.post({clientId:ss,text:Ie,mode:Me})).outcome:ns=(await q.postLiveMessage(u,h,{clientId:ss,text:Ie,...ys.length?{pins:ys}:{},mode:Me})).outcome,ns==="delivered-pending"||ns==="restarted"||ns==="interrupted"?d.phase(ss,"pending"):ns==="pending-start"?d.phase(ss,"pendingStart"):d.drop(ss),(ns==="queued"||ns==="queued-unsupported"||ns==="restarted"||ns==="interrupted")&&As(T.outcome[ns]),We.current=null,_(""),we(!1),S?.({pins:ys}),m?.()}catch(ns){d.drop(ss);const Ys=Gl(ns,P),mt=ns instanceof lt&&ns.status>=400&&ns.status<500;Qe(Me==="redirect"?T.redirectFailed({detail:Ys}):mt?Ys:O.sendFailed({detail:Ys}))}finally{Q.current=!1,Ne(!1)}},_e=Ke?"redirect":he.liveInput?"live":"queued",ge=()=>{Ze&&(be?Be(_e):xe({text:L.trim(),pins:ne,...fe.length?{attachments:fe}:{},...Xe?{formats:Xe}:{}}))},qe=Me=>{if(dc(Me.nativeEvent)&&!Me.repeat){Me.preventDefault(),ge();return}be&&!Ke&&Me.key==="Enter"&&!Me.shiftKey&&!Me.ctrlKey&&!Me.metaKey&&!Me.altKey&&!Me.nativeEvent.isComposing&&(Me.preventDefault(),Me.repeat||ge())},Ye=Pt()?"⌘↵":"Ctrl+↵",Ls=s.jsx("kbd",{className:"ms-composer-keys","aria-hidden":"true",children:Ye}),bs=`${be?Ke?T.redirectPlaceholder:he.liveInput?T.livePlaceholder:T.queuePlaceholder:r??O.placeholder} · ${O.sendHint({keys:Ye})}`,Us=be?Ke?T.redirectHint({keys:Ye}):he.liveInput?T.liveHint:T.queueHint:O.sendHint({keys:Ye});return s.jsx("form",{className:"ms-composer",onSubmit:Me=>{Me.preventDefault(),ge()},children:s.jsxs("div",{className:"ms-composer-box",children:[t,A.length>0&&s.jsxs("div",{className:"ms-composer-pins",children:[x&&!L.trim()?s.jsx("span",{className:"ms-composer-pins-note",children:P.web.variantGroup.pinsNotSentToAll}):null,A.map((Me,ss)=>ss>=b.length?s.jsxs("span",{className:"ms-chip ms-on ms-composer-pin",children:[s.jsx(Ia,{list:Me.variant?[Me.variant]:void 0}),s.jsx(F,{name:"comment",size:11}),s.jsx(po,{pin:Me,text:Sl(Me,ss+1,w,P,z)}),R?.onRemoveOther?s.jsx("button",{type:"button",className:"ms-x","aria-label":P.web.conversation.removeComment({n:ss+1}),onClick:()=>R.onRemoveOther?.(Me),children:s.jsx(F,{name:"close",size:10})}):null]},ss):s.jsxs("span",{className:"ms-chip ms-on ms-composer-pin",children:[R&&Me.variant?s.jsx(Ia,{list:[Me.variant]}):null,y?s.jsxs("button",{type:"button",className:"ms-pin-edit",title:Me.note||void 0,"aria-label":`${P.web.conversation.editComment({n:ss+1})} · ${Me.note||Sl(Me,ss+1,w,P,z)}`,onClick:()=>y(ss),children:[s.jsx(F,{name:"comment",size:11}),s.jsx(po,{pin:Me,text:Sl(Me,ss+1,w,P,z)})]}):s.jsxs(s.Fragment,{children:[s.jsx(F,{name:"comment",size:11}),s.jsx(po,{pin:Me,text:Sl(Me,ss+1,w,P,z)})]}),s.jsx("button",{type:"button",className:"ms-x","aria-label":P.web.conversation.removeComment({n:ss+1}),onClick:()=>v?.(ss),children:s.jsx(F,{name:"close",size:10})})]},ss))]}),ae?s.jsx(PC,{slug:u,paths:K,pending:U,onRemove:se,onCancel:re}):null,ae&&K.length>0&&be?s.jsx("p",{className:"ms-composer-note",children:O.attachWait}):null,E&&!be?s.jsx(mC,{appliesTo:E,targets:Xe,onChange:us}):null,E&&Xe&&!be?E.primaries.filter(Me=>Xe.includes(Me.id)).flatMap(Me=>Me.followers.map(ss=>s.jsxs("p",{className:"ms-composer-follows",children:[s.jsx(F,{name:"link",size:11}),O.followsBoth({follower:ss,primary:Me.label})]},`${Me.id}:${ss}`))):null,s.jsx("label",{htmlFor:W,className:le("ms-composer-label",a!==void 0&&"ms-sr"),children:a??P.web.conversation.requestChange}),s.jsx(nn,{id:W,ref:ze,rows:2,maxLength:1e4,value:L,onChange:Me=>{_(Me.target.value),We.current=null,As(null)},onKeyDown:qe,placeholder:bs,"aria-keyshortcuts":Pt()?"Meta+Enter":"Control+Enter"}),be&&Ke&&s.jsx("p",{className:"ms-composer-note",children:T.redirectNote}),be&&!Ke&&Fe&&!he.liveInput&&s.jsx("p",{className:"ms-composer-note",children:T.queueOnly}),be&&!Ke&&Fe&&he.liveInput&&s.jsx("p",{className:"ms-composer-note",children:T.liveNote}),R&&!be?s.jsx("p",{className:"ms-composer-note ms-composer-group",children:P.web.variantGroup.singleHint}):null,gs&&s.jsx("p",{role:"status",className:"ms-composer-note",children:gs}),is&&s.jsx("p",{role:"alert",className:"ms-composer-error",children:is}),s.jsxs("div",{className:"ms-composer-foot",children:[ae?s.jsx($C,{slug:u,chosen:K,onAdd:de,onRemove:se,onError:J,onPending:G,disabled:os||!!c}):null,n,N?s.jsx(kC,{slug:u,creative:h,brief:N,busy:os,onSaved:()=>C?.()}):null,s.jsx("span",{className:"ms-composer-hint",children:Us}),f&&s.jsx(rm,{job:f,onError:Qe,onRedirect:()=>{we(!0),Qe(null),ze.current?.focus()}}),j&&!f&&s.jsxs($,{size:"sm",variant:"accent","aria-label":P.web.newCreative.generate,disabled:os,onClick:()=>{xe({},!0)},children:[s.jsx(F,{name:"sparkle",size:13}),P.web.newCreative.generate]}),!be&&s.jsx(pn,{label:O.sendWithKeys({keys:Ye}),children:s.jsxs($,{type:"submit",size:"sm",variant:"accent",className:"ms-composer-send","aria-label":P.web.common.send,disabled:!Ze,children:[s.jsx(F,{name:"send",size:13,strokeWidth:1.6}),Ls]})}),be&&Ke&&s.jsxs(s.Fragment,{children:[s.jsx(pn,{label:T.cancelRedirect,whenHidden:".ms-composer-text",children:s.jsxs($,{size:"sm",variant:"ghost",className:"ms-composer-act","aria-label":T.cancelRedirect,onClick:()=>we(!1),children:[s.jsx(F,{name:"close",size:12}),s.jsx("span",{className:"ms-composer-text",children:T.cancelRedirect})]})}),s.jsx(pn,{label:T.redirect,whenHidden:".ms-composer-text",children:s.jsxs($,{type:"submit",size:"sm",variant:"accent",className:"ms-composer-act","aria-label":T.redirect,disabled:!Ze,children:[s.jsx(F,{name:"forward",size:13}),s.jsx("span",{className:"ms-composer-text",children:T.redirect})]})})]}),be&&!Ke&&Fe===null&&s.jsx(pn,{label:T.send,whenHidden:".ms-composer-text",children:s.jsxs($,{type:"submit",size:"sm",variant:"accent",className:"ms-composer-act","aria-label":T.send,loading:!0,disabled:!0,children:[s.jsx(F,{name:"send",size:13,strokeWidth:1.6}),s.jsx("span",{className:"ms-composer-text",children:T.send}),Ls]})}),be&&!Ke&&Fe&&!he.liveInput&&s.jsx(pn,{label:T.queue,whenHidden:".ms-composer-text",children:s.jsxs($,{type:"submit",size:"sm",variant:"accent",className:"ms-composer-act","aria-label":T.queue,disabled:!Ze,children:[s.jsx(F,{name:"send",size:13,strokeWidth:1.6}),s.jsx("span",{className:"ms-composer-text",children:T.queue}),Ls]})}),be&&!Ke&&Fe&&he.liveInput&&s.jsx(Cg,{variant:"accent",menuLabel:T.sendMore,groupLabel:T.send,disabled:!Ze,primary:s.jsx(pn,{label:T.send,whenHidden:".ms-composer-text",children:s.jsxs($,{type:"submit",size:"sm",variant:"accent",className:"ms-composer-act","aria-label":T.send,disabled:!Ze,children:[s.jsx(F,{name:"send",size:13,strokeWidth:1.6}),s.jsx("span",{className:"ms-composer-text",children:T.send}),Ls]})}),items:[{key:"queue",label:T.queue,onSelect:()=>{Be("queued")}}]})]})]})})}function Ev({suggestions:e,taken:t,submitLabel:n,onSubmit:a,autoFocus:r}){const l=V(),o=l.web.brand.codebase,[c,d]=i.useState(""),[m,u]=i.useState(""),[h,f]=i.useState(null),[x,p]=i.useState(!1),g=i.useRef(!1),b=i.useId(),v=xt(),y=e.filter(S=>!t.includes(S)),w=async()=>{try{const S=await v?.pickFolder(l.web.codebase.pickTitle,c.trim()||void 0);S&&(d(S),f(null))}catch(S){f(pe(S))}},j=async S=>{if(S.preventDefault(),g.current)return;const k=c.trim();if(!k){f(o.needPath);return}g.current=!0,p(!0),f(null);try{await a(k,m.trim()),d(""),u("")}catch(E){f(pe(E))}finally{g.current=!1,p(!1)}};return s.jsxs("form",{className:"ms-cbl",onSubmit:S=>{j(S)},children:[y.length?s.jsxs("div",{className:"ms-bcb-sugg",role:"group","aria-label":o.suggestions,children:[s.jsx("span",{className:"ms-bsmall-text ms-muted",children:o.suggestions}),y.map(S=>s.jsx(sn,{icon:"folder",on:c.trim()===S,title:o.suggestionTitle({path:S}),onClick:()=>{d(S),f(null)},children:wm(S)},S))]}):null,s.jsxs("div",{className:"ms-cbl-add",children:[s.jsx(ms,{className:"ms-cbl-input ms-cbl-mono","aria-label":o.pathAria,placeholder:o.pathPlaceholder,value:c,autoFocus:r,"aria-invalid":h?!0:void 0,"aria-describedby":h?b:void 0,onChange:S=>{d(S.target.value),f(null)}}),v?s.jsxs($,{size:"sm",variant:"outline",onClick:()=>{w()},children:[s.jsx(F,{name:"folder",size:12}),l.web.common.chooseFolder]}):null]}),s.jsx(ms,{className:"ms-cbl-input","aria-label":o.noteAria,placeholder:o.notePlaceholder,value:m,maxLength:500,onChange:S=>u(S.target.value)}),s.jsx("p",{className:"ms-cbl-hint",children:o.hint}),h?s.jsx("p",{id:b,role:"alert",className:"ms-cbl-error",children:h}):null,s.jsx($,{type:"submit",variant:"ink",size:"sm",className:"ms-bstart",loading:x,disabled:!c.trim(),children:n})]})}const Tv=e=>e.usage?_n(e.usage.tokens):null;function sE({job:e}){const t=V().web.brand.codebase;return!e||e.kind!=="brand-analysis"||!e.notes?.length?null:s.jsxs("section",{className:"ms-bsources","aria-label":t.notesTitle,children:[s.jsx("span",{className:"ms-cap",children:t.notesTitle}),s.jsx("ul",{className:"ms-bnotes ms-bsmall-text",children:e.notes.map((n,a)=>s.jsx("li",{children:n},a))})]})}function Rv({project:e,proposalId:t}){const n=V(),a=n.web.chat,r=n.web.brand.history,l=i.useId(),o=i.useRef(null),[c,d]=i.useState(!1),[m,u]=i.useState(null),h=i.useContext(zu);i.useEffect(()=>{let x=!0;return Promise.resolve().then(()=>q.getProposalActivity(e,t)).then(p=>{x&&u(p)},()=>{}),()=>{x=!1}},[e,t]);const f=i.useMemo(()=>m?.hasLog&&Array.isArray(m.entries)?$x(m.entries.map(x=>x.event),Mx(h,e),{finished:!m.truncated,sandboxedHint:m.sandboxed}):null,[m,h,e]);return!m?.hasLog||!f||f.ran===0?null:s.jsxs("span",{className:"ms-bauto",children:[s.jsx(F,{name:f.sandboxed?"shield":"terminal",size:12}),s.jsx("span",{id:l,children:a.commandsRan({count:f.ran,approved:f.approved,sandbox:f.sandboxed,attempted:f.attempted,atLeast:m.truncated})}),s.jsx("span",{"aria-hidden":"true",children:"·"}),s.jsx($,{ref:o,size:"sm",variant:"ghost",className:"ms-bauto-details","aria-describedby":l,"aria-haspopup":"dialog","aria-expanded":c,onClick:()=>d(x=>!x),children:a.autoDetails}),s.jsx(ot,{open:c,onClose:()=>d(!1),anchor:o,placement:"bottom-end",width:360,label:r.autoTitle,children:s.jsxs("div",{className:"ms-bauto-pop",children:[s.jsx("b",{children:r.autoTitle}),s.jsx("ul",{className:"ms-convo-log",children:f.rows.map(x=>s.jsx(Cv,{row:x},x.key))}),m.truncated?s.jsx("p",{className:"ms-muted",children:r.autoTruncated}):null]})})]})}function tE({project:e,proposal:t,onReview:n}){const r=V().web.brand.analysis,l=i.useRef(null);i.useLayoutEffect(()=>{Gs(l.current,{y:8})},[]);const o=t.changes.length+(t.guidelines?1:0);return s.jsxs("div",{className:"ms-bready",ref:l,children:[s.jsx("span",{className:"ms-bready-icon","aria-hidden":"true",children:s.jsx(F,{name:"sparkle",size:15})}),s.jsxs("span",{className:"ms-bready-text",children:[s.jsx("b",{children:r.readyTitle}),s.jsx("span",{className:"ms-muted",children:r.readySub({count:o})}),s.jsx(ar,{tokens:Tv(t),className:"ms-btokens"}),s.jsx(Rv,{project:e,proposalId:t.id})]}),s.jsx($,{variant:"ink",size:"sm",onClick:n,children:r.review})]})}function nE({job:e,live:t}){const a=V().web.brand.analysis,r=i.useRef(null);i.useLayoutEffect(()=>{Gs(r.current,{y:8})},[]);const l=XS(t.events[e.id]),o=ZS(t.events[e.id]),c=Object.values(t.approvals).filter(h=>h.jobId===e.id),[d,m]=i.useState(!1),u=()=>{m(!0),q.cancelJob(e.id).then(()=>Pe.show(a.canceled),h=>Pe.show(pe(h))).finally(()=>m(!1))};return s.jsxs("section",{className:"ms-banalysis",ref:r,"aria-labelledby":"ms-banalysis-title",children:[s.jsxs("div",{className:"ms-brow",children:[s.jsx(Ts,{decorative:!0,size:14}),s.jsx("b",{id:"ms-banalysis-title",children:a.title}),s.jsx(ar,{tokens:Do(t,e.id),live:!0,partial:$l(t,e.id),className:"ms-btokens"}),s.jsx($,{variant:"ghost",size:"sm",className:"ms-bpush",loading:d,onClick:u,children:a.cancel})]}),s.jsx("div",{className:"ms-bbar",role:"progressbar","aria-label":a.progress,"aria-busy":"true",children:s.jsx("i",{})}),o?s.jsx(aE,{phases:o}):null,s.jsxs("ol",{className:"ms-bsteps",children:[e.state==="queued"?s.jsx("li",{className:"ms-muted",children:a.queued}):null,e.state==="running"&&!l.length?s.jsx("li",{className:"ms-muted",children:a.starting}):null,l.map((h,f)=>s.jsx(rE,{text:h,done:f<l.length-1},`${f}:${h}`))]}),e.state==="running"?s.jsxs("span",{className:"ms-brow ms-muted ms-bworking",children:[s.jsx(Bu,{label:a.working}),a.working]}):null,c.map(h=>s.jsx(ri,{approval:h},h.id))]})}function aE({phases:e}){const n=V().web.brand.analysis;return s.jsx("ol",{className:"ms-bphases","aria-label":n.phasesLabel,children:e.map(({phase:a,state:r})=>s.jsxs("li",{className:"ms-bphase","data-state":r,"aria-current":r==="current"?"step":void 0,children:[s.jsx("span",{className:"ms-bphase-mark","aria-hidden":"true",children:r==="done"?s.jsx(F,{name:"check",size:10,strokeWidth:2.4}):s.jsx("i",{})}),s.jsx("span",{children:n.phases[a]}),s.jsx("span",{className:"ms-sr",children:`: ${n.phaseState[r]}`})]},a))})}function rE({text:e,done:t}){const n=i.useRef(null);return i.useLayoutEffect(()=>{Gs(n.current,{y:6})},[]),s.jsxs("li",{ref:n,className:le("ms-bstep",t&&"ms-done"),children:[s.jsx("span",{className:"ms-bstep-mark","aria-hidden":"true",children:t?s.jsx(F,{name:"check",size:12,strokeWidth:2.2}):s.jsx("i",{})}),s.jsx("span",{children:e})]})}function lE({job:e,proposals:t,onRetry:n}){const a=V(),r=a.web.brand.analysis,{slug:l}=Gt(),[o,c]=i.useState(!1);if(!e||e.state!=="failed"||t.some(u=>u.createdAt>e.createdAt))return null;const d=e.kind==="asset-description"?a.web.labels.describeFailed({error:e.error??null}):r.failed({error:e.error??"—"}),m=()=>{c(!0),xc().then(()=>q.analyzeBrand(l)).then(n,u=>Pe.show(pe(u))).finally(()=>c(!1))};return s.jsxs("div",{className:"ms-bfailed",role:"alert",children:[s.jsx(F,{name:"warn",size:15}),s.jsx("span",{children:d}),e.kind==="brand-analysis"?s.jsx($,{size:"sm",loading:o,onClick:m,children:r.retry}):null]})}function iE({overview:e,job:t,reload:n,codebases:a=[]}){const r=V(),l=r.web.brand.sources,o=rs(),{slug:c}=Gt(),[d,m]=i.useState(new Set),[u,h]=i.useState(""),[f,x]=i.useState("site"),[p,g]=i.useState(null),[b,v]=i.useState(null),y=io(t),w=y&&t?.kind==="brand-analysis",j=y&&t?.kind==="asset-description";Yu(O=>{const T=e.sources.filter(W=>O.includes(Oa("brand-source",c,W.id))).map(W=>W.id);T.length&&(m(W=>new Set([...W,...T])),n())});const S=e.sources.filter(O=>(O.kind==="website"||O.kind==="codebase")&&!d.has(O.id)&&!Ju(Oa("brand-source",c,O.id))),k=e.sources.filter(O=>O.kind==="image").length,E=S.length+k>0,N=e.sources.some(O=>O.lastAnalyzedAt),C=async(O,T)=>{await q.addBrandSource(c,{kind:"codebase",path:O,...T?{note:T}:{}}),Pe.show(r.web.brand.codebase.added,{tone:"ok"}),n()},R=async O=>{O.preventDefault();const T=ev(u);if(!T){g(l.invalidUrl);return}v("add"),g(null);try{await q.addBrandSource(c,{kind:"website",url:T}),h(""),Pe.show(l.added,{tone:"ok"}),n()}catch(W){g(pe(W))}finally{v(null)}},P=async()=>{v("analyze"),g(null);try{await xc(),await q.analyzeBrand(c),n()}catch(O){g(pe(O))}finally{v(null)}},z=O=>{const T=O.kind==="codebase"?wm(O.path??""):yc(O.url);m(W=>new Set(W).add(O.id)),Qu({text:O.kind==="codebase"?r.web.brand.codebase.removed({name:T}):l.removed({host:T}),undoLabel:r.web.brand.undo,keys:[Oa("brand-source",c,O.id)],commit:()=>q.removeBrandSource(c,O.id,Zu).then(n),restore:()=>m(W=>{const Z=new Set(W);return Z.delete(O.id),Z}),onError:W=>g(pe(W))})};return s.jsxs("section",{className:"ms-bsources","aria-labelledby":"ms-bsources-title",children:[s.jsx("span",{className:"ms-cap",id:"ms-bsources-title",children:l.title}),S.map(O=>s.jsx(oE,{src:O,onRemove:()=>z(O),meta:w?l.inProgress:O.lastAnalyzedAt?l.analyzedAt({when:ll(o,O.lastAnalyzedAt)}):l.never,live:w},O.id)),S.length?null:s.jsx("span",{className:"ms-muted ms-bsmall-text",children:l.empty}),s.jsx(it,{label:r.web.brand.codebase.kindAria,value:f,onChange:O=>{x(O),g(null)},options:[{value:"site",label:r.web.brand.codebase.kindSite,icon:"globe"},{value:"code",label:r.web.brand.codebase.kindCode,icon:"code"}]}),f==="site"?s.jsxs("form",{className:"ms-brow ms-bnowrap",onSubmit:O=>{R(O)},children:[s.jsx(ms,{className:"ms-grow ms-bsmall",value:u,"aria-label":l.addLabel,placeholder:l.addPlaceholder,onChange:O=>{h(O.target.value),g(null)}}),s.jsx($,{type:"submit",variant:"ink",size:"sm",loading:b==="add",disabled:!u.trim(),children:l.add})]}):s.jsx(Ev,{suggestions:a,taken:e.sources.flatMap(O=>O.path?[O.path]:[]),submitLabel:r.web.brand.codebase.add,onSubmit:C}),p?s.jsx("span",{className:"ms-bwarn",role:"alert",children:p}):null,s.jsx("span",{className:"ms-muted ms-bsmall-text",children:k?l.images({count:k}):l.noImages}),s.jsxs($,{className:"ms-bwide",loading:b==="analyze",disabled:y||!E,onClick:()=>{P()},children:[s.jsx(F,{name:"refresh",size:14,strokeWidth:1.6}),N?l.analyzeAgain:l.analyze]}),j?s.jsx("span",{className:"ms-muted ms-bsmall-text",children:l.busyDescribe}):E?null:s.jsx("span",{className:"ms-muted ms-bsmall-text",children:l.needSource})]})}function oE({src:e,meta:t,live:n,onRemove:a}){const r=V(),l=r.web.brand.sources,o=i.useRef(null),c=i.useRef(null),[d,m]=i.useState(!1);ii(o);const u=e.kind==="codebase",h=u?wm(e.path??""):yc(e.url);return s.jsxs("div",{className:"ms-bsource",ref:o,children:[s.jsxs("div",{className:"ms-brow ms-bnowrap",children:[s.jsx("span",{className:"ms-bsource-icon","aria-hidden":"true",children:s.jsx(F,{name:u?"code":"globe",size:12})}),s.jsx("b",{className:"ms-ell",title:(u?e.path:e.url)??void 0,children:h}),s.jsx($,{ref:c,variant:"ghost",size:"sm",icon:!0,className:"ms-bpush","aria-label":u?r.web.brand.codebase.actions({name:h}):l.actions({host:h}),"aria-expanded":d,onClick:()=>m(!d),children:s.jsx(F,{name:"more",size:14})})]}),u?s.jsx("span",{className:"ms-bsmall-text ms-muted ms-bsource-path",children:e.path}):null,u&&e.note?s.jsx("span",{className:"ms-bsmall-text ms-muted",children:e.note}):null,s.jsxs("span",{className:le("ms-bsmall-text",n?"ms-baccent":"ms-muted"),children:[n?s.jsx(Ts,{decorative:!0,size:10}):null,t]}),s.jsx(ot,{open:d,onClose:()=>m(!1),anchor:c,width:180,placement:"bottom-end",children:s.jsx("div",{className:"ms-bpop",children:s.jsxs("button",{type:"button",className:"ms-bmenu-row ms-danger","data-row":!0,onClick:()=>{m(!1),a()},children:[s.jsx(F,{name:"trash",size:13}),l.remove]})})})]})}const cE={palette:"colors",fonts:"type",rules:"voice",lightLogo:"logos"};function dE(){const t=V().web.brand.health,{kit:n,locked:a,go:r,upload:l}=Gt(),o=i.useMemo(()=>VS(n),[n]);return s.jsxs("section",{className:"ms-bhealth","aria-labelledby":"ms-bhealth-title",children:[s.jsx("span",{className:"ms-cap",id:"ms-bhealth-title",children:t.title}),s.jsx("div",{className:"ms-bhealth-list",children:o.map(c=>s.jsxs("div",{className:"ms-bhealth-row","data-state":c.ok?"ok":"todo",children:[s.jsx("span",{className:le("ms-bhealth-dot",c.ok?"ms-ok":"ms-warn"),"aria-hidden":"true",children:c.ok?s.jsx(F,{name:"check",size:9,strokeWidth:2.4}):"!"}),s.jsxs("span",{className:"ms-grow",children:[t[c.id],s.jsx("span",{className:"ms-sr",children:`: ${c.ok?t.ok:t.todo}`})]}),c.ok?null:s.jsx("button",{type:"button",className:"ms-blink-btn",disabled:a&&c.id==="lightLogo",onClick:()=>c.id==="lightLogo"?l("light"):r(cE[c.id]),children:t.fix[c.id]})]},c.id))})]})}function uE({project:e,proposals:t,undone:n}){const a=V(),r=a.web.brand.history,l=rs();if(!t.length)return null;const o=[...t].sort((c,d)=>d.createdAt.localeCompare(c.createdAt)).slice(0,4);return s.jsxs("section",{className:"ms-bhistory","aria-labelledby":"ms-bhistory-title",children:[s.jsx("b",{id:"ms-bhistory-title",children:r.title}),o.map(c=>s.jsxs("div",{className:"ms-bhistory-item",children:[s.jsxs("span",{className:"ms-muted ms-bsmall-text",children:[`${$u(l,c.createdAt)} · ${c.status==="applied"?r.applied:c.status==="discarded"?r.discarded:r.open}${n.has(c.id)?` · ${r.undone}`:""}`,c.usage?s.jsx("span",{className:"ms-btokens",children:` · ${a.web.usage.tokens({count:ia(l,Tv(c))})}`}):null]}),s.jsx(Rv,{project:e,proposalId:c.id})]},c.id))]})}function mE({slug:e,live:t}){const a=V().web.brand,r=t.projectTicks[e]??0,[l,o]=i.useState(0),[c,d]=i.useState(null),[m,u]=i.useState(null),[h,f]=i.useState([]),[x,p]=i.useState([]),[g,b]=i.useState(null),[v,y]=i.useState([]),w=i.useCallback(()=>o(N=>N+1),[]);i.useEffect(()=>{let N=!0;return Promise.resolve().then(()=>q.getBrand(e)).then(C=>{N&&(d(C),u(null))}).catch(C=>{N&&u(pe(C))}),Promise.resolve().then(()=>q.listAssets(e)).then(C=>{N&&f(C.assets)}).catch(()=>{}),Promise.resolve().then(()=>q.listReferences(e)).then(C=>{N&&p(C.references)}).catch(()=>{}),()=>{N=!1}},[e,r,l]),i.useEffect(()=>{let N=!0;return Promise.resolve().then(()=>q.getProject(e)).then(C=>{N&&(b(C.project.name),y((C.project.linkedCodebases??[]).map(R=>R.path)))}).catch(()=>{}),()=>{N=!1}},[e]);const j=v1(e,c?.kit??null,w),S=c?GS(t.jobs,c.jobKey):void 0,[k,E]=i.useState(!1);return m&&!c?s.jsx("div",{className:"ms-brand-center",children:s.jsx(Rt,{icon:"warn",title:a.loadFailed({error:m}),action:s.jsx($,{onClick:()=>{u(null),w()},children:a.retry})})}):!c||!j.kit?s.jsx("div",{className:"ms-brand-center",children:s.jsx(Ts,{size:20})}):!k&&HS(c,S)?s.jsx(pE,{slug:e,codebases:v,onManual:()=>E(!0),onStarted:w}):s.jsx(hE,{slug:e,live:t,overview:c,setOverview:d,kit:j.kit,saver:j,job:S,assets:h,setAssets:f,references:x,projectName:g,codebases:v,reload:w})}function hE({slug:e,live:t,overview:n,setOverview:a,kit:r,saver:l,job:o,assets:c,setAssets:d,references:m,projectName:u,codebases:h,reload:f}){const x=V(),p=ul(e,t),g=x.web.brand,b=Ra([]),v=i.useRef(null),y=i.useRef(!1);i.useEffect(()=>{y.current=!0},[]);const[w,j]=i.useState("overview"),S=!!n.kitError,k=i.useCallback(U=>{j(U);const te=v.current,G=te?.querySelector(`[data-sec="${U}"]`);te&&G&&typeof te.scrollTo=="function"&&te.scrollTo({top:G.offsetTop-20,behavior:"smooth"})},[]),E=U=>{const te=U.currentTarget,G=te.scrollTop+80;let re="overview";te.querySelectorAll("[data-sec]").forEach(oe=>{oe.offsetTop<=G&&(re=oe.dataset.sec)}),te.scrollTop+te.clientHeight>=te.scrollHeight-4&&(re="guidelines"),re!==w&&j(re)},N=i.useRef(null),C=i.useRef("any"),[R,P]=i.useState(!1),z=i.useCallback((U,te)=>{l.edit(G=>{const re=[...G.logos];for(const oe of U)re.some(Ne=>Ne.file===oe)||re.push({id:wc("logo",re.map(Ne=>Ne.id)),file:oe,variant:re.length?"secondary":"primary",background:te,source:rr});return{...G,logos:re}})},[l]),O=i.useCallback(U=>{C.current=U,N.current?.click()},[]),T=async U=>{const te=Array.from(U??[]);if(te.length){P(!0);try{const re=(await q.uploadFiles(e,"assets",te)).assets??[];re.length&&(d([...c.filter(oe=>!re.some(Ne=>Ne.file===oe.file)),...re]),z(re.filter(oe=>oe.kind==="image"||oe.kind==="svg").map(oe=>`assets/${oe.file}`),C.current),Pe.show(g.logos.added,{tone:"ok"}))}catch(G){Pe.show(pe(G))}finally{P(!1)}}},W={slug:e,kit:r,locked:S,saver:l,assets:c,settled:y,upload:O,go:k,reloadAssets:()=>{Promise.resolve().then(()=>q.listAssets(e)).then(U=>d(U.assets)).catch(()=>{})},addLogoFromAsset:(U,te)=>z([U],te)},Z=o?.kind==="brand-analysis"?o:void 0,A=n.proposals.find(U=>U.status==="open"),[L,_]=i.useState(!1),X=i.useRef(null);Z&&io(Z)&&(X.current=Z.id),i.useEffect(()=>{!Z||X.current!==Z.id||io(Z)||Z.state!=="succeeded"||!A||A.createdAt<Z.createdAt||(X.current=null,Pe.show(g.analysis.ready,{action:{label:g.analysis.review,run:()=>_(!0)}}),Ou(b.current)&&!Jx()&&!l.pending()&&_(!0))},[Z,A,g,b]);const[ae,K]=i.useState(()=>new Set),I=i.useCallback(U=>{if(l.rebase(U.kit,te=>YS(te,U.changes)),U.guidelines){const te=U.guidelines.after;a(G=>G&&{...G,guidelines:te})}f()},[l,a,f]),H=i.useRef(n.guidelines);H.current=n.guidelines;const de=i.useCallback(U=>{l.edit(G=>QS(G,U.changes));const te=U.guidelines;te&&H.current===te.after&&l.saveGuidelines(te.before).then(G=>{G&&a(re=>re&&{...re,guidelines:te.before})}),K(G=>new Set(G).add(U.proposalId)),Pe.show(x.web.brandReview.restored,{tone:"ok"})},[l,a,x]),J=i.useRef(null);A&&(J.current=A);const se=[["overview",g.nav.overview,void 0],["colors",g.nav.colors,r.colors.length],["type",g.nav.type,r.fonts.length],["logos",g.nav.logos,r.logos.length],["voice",g.nav.voice,void 0],["sound",g.nav.sound,void 0],["photo",g.nav.photo,void 0],["guidelines",g.nav.guidelines,void 0]];return s.jsxs(lv.Provider,{value:W,children:[s.jsxs("div",{className:"ms-bpage",ref:b,children:[s.jsxs("nav",{className:"ms-brand-nav","aria-label":g.sections,children:[se.map(([U,te,G])=>s.jsx(dn,{on:w===U,count:G,onClick:()=>k(U),children:te},U)),s.jsx("div",{className:"ms-grow"}),!l.status.saving&&!l.status.error?s.jsx("span",{className:"ms-brand-allsaved",children:g.save.allSaved}):null]}),s.jsxs("main",{className:"ms-brand-main",ref:v,onScroll:E,children:[s.jsx(fE,{saver:l}),p.state?s.jsx(vr,{slug:e,state:p.state,reload:p.reload}):null,n.kitError?s.jsxs(Df,{children:[g.kitUnreadable({error:n.kitError})," ",g.kitLocked]}):null,n.sourcesError?s.jsx(Df,{children:n.sourcesError}):null,s.jsx(j1,{overview:n,projectName:u}),s.jsx(K1,{}),s.jsx(H1,{}),s.jsx(Z1,{uploading:R}),s.jsx(y1,{}),s.jsx(sC,{}),s.jsxs("div",{className:"ms-bgrid2",children:[s.jsx(k1,{references:m}),s.jsx(N1,{text:n.guidelines,onSaved:U=>a(te=>te&&{...te,guidelines:U})})]})]}),s.jsxs("aside",{className:"ms-brand-side","aria-label":g.sources.title,children:[A?s.jsx(tE,{project:e,proposal:A,onReview:()=>_(!0)}):null,Z&&io(Z)?s.jsx(nE,{job:Z,live:t}):null,s.jsx(lE,{job:o,proposals:n.proposals,onRetry:f}),s.jsx(sE,{job:o}),s.jsx(iE,{overview:n,job:o,reload:f,codebases:h}),s.jsx(dE,{}),s.jsx(uE,{project:e,proposals:n.proposals,undone:ae})]}),s.jsx("input",{ref:N,type:"file",accept:"image/*,.svg",multiple:!0,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:U=>{T(U.target.files),U.target.value=""}})]}),J.current?s.jsx(C1,{open:L&&!!A,slug:e,proposal:J.current,kit:r,guidelines:n.guidelines,sources:n.sources,onClose:()=>_(!1),onApplied:I,onUndo:de,onChanged:f}):null]})}function Df({children:e}){return s.jsxs("div",{className:"ms-brand-alert",role:"alert",children:[s.jsx(F,{name:"warn",size:15}),s.jsx("span",{children:e})]})}function fE({saver:e}){const t=V(),n=e.status,a=i.useRef(null),r=n.saving||n.saved||!!n.error,l=i.useRef(!1);return i.useLayoutEffect(()=>{r&&!l.current&&Gs(a.current,{y:-8,ms:qs.s}),l.current=r},[r]),r?s.jsx("div",{className:"ms-brand-savepill",ref:a,"aria-live":"polite",children:n.error?s.jsxs("span",{className:"ms-brand-saveerr",role:"alert",children:[s.jsx(Qs,{tone:"warn",dot:!0,children:t.web.brand.save.failed({error:n.error.message})}),s.jsx($,{size:"sm",onClick:e.retry,children:t.web.brand.save.retry})]}):n.saving?s.jsx(Qs,{spinner:!0,children:t.web.brand.save.saving}):s.jsxs(Qs,{tone:"ok",children:[s.jsx(F,{name:"check",size:11,strokeWidth:2.4}),t.web.brand.save.saved]})}):null}function pE({slug:e,codebases:t,onManual:n,onStarted:a}){const r=V(),l=r.web.brand.empty,o=r.web.brand.codebase,c=Ra([]),[d,m]=i.useState("site"),[u,h]=i.useState(""),[f,x]=i.useState(null),[p,g]=i.useState(!1),b=i.useRef(null),v=async j=>{j.preventDefault();const S=ev(u);if(!S){x(r.web.brand.sources.invalidUrl);return}g(!0),x(null);try{b.current!==S&&(await q.addBrandSource(e,{kind:"website",url:S}),b.current=S),await q.analyzeBrand(e),a()}catch(k){x(pe(k)),g(!1)}},y=i.useRef(null),w=async(j,S)=>{const k=y.current;if(!k||k.path!==j||k.note!==S){k&&(await q.removeBrandSource(e,k.id),y.current=null);const E=await q.addBrandSource(e,{kind:"codebase",path:j,...S?{note:S}:{}});y.current={id:E.id,path:j,note:S}}await q.analyzeBrand(e),a()};return s.jsx("div",{className:"ms-brand-empty",ref:c,children:s.jsxs("div",{className:"ms-card ms-brand-empty-card","data-enter":!0,children:[s.jsx("span",{className:"ms-bready-icon","aria-hidden":"true",children:s.jsx(F,{name:"sparkle",size:16})}),s.jsx("h1",{children:l.title}),s.jsx("p",{children:d==="site"?l.sub:o.emptySub}),s.jsx(it,{label:o.kindAria,value:d,onChange:j=>{m(j),x(null)},options:[{value:"site",label:o.kindSite,icon:"globe"},{value:"code",label:o.kindCode,icon:"code"}]}),d==="site"?s.jsxs("form",{className:"ms-brand-empty-form",onSubmit:j=>{v(j)},children:[s.jsxs("div",{className:"ms-brow ms-bnowrap",children:[s.jsx(ms,{className:"ms-grow",value:u,"aria-label":l.website,placeholder:l.placeholder,autoFocus:!0,onChange:j=>{h(j.target.value),x(null)}}),s.jsx($,{type:"submit",variant:"ink",loading:p,disabled:!u.trim(),children:l.analyze})]}),f?s.jsx("span",{className:"ms-bwarn",role:"alert",children:f}):null]}):s.jsx(Ev,{suggestions:t,taken:[],submitLabel:o.addAndAnalyze,autoFocus:!0,onSubmit:w}),s.jsx("button",{type:"button",className:"ms-blink-btn ms-bstart",onClick:n,children:l.manual})]})})}const Em=3;function Tm(e,t){return{start:t?"brand":"scratch",colors:"brand",concepts:Em,...e}}function Mv(e,t){const n=Tm(e,t),a=n.name?.trim(),r=n.keywords?.trim();return{start:n.start,...n.start==="scratch"&&a?{name:a}:{},...n.start==="scratch"&&r?{keywords:r}:{},colors:n.colors??"brand",concepts:n.concepts??Em}}const $v=e=>e.find(t=>t.variant==="primary")??e[0];function xE(e,t=!0){const[n,a]=i.useState(null);i.useEffect(()=>{if(!t)return;let l=!0;return Promise.resolve().then(()=>q.getBrand(e)).then(o=>{l&&a(o.kit)}).catch(()=>{l&&a("failed")}),()=>{l=!1}},[e,t]);const r=n&&n!=="failed"?n.logos:[];return{loaded:n!==null,hasLogo:r.length>0,fromCodebase:$v(r)?.source.kind==="codebase"}}function Fv({value:e,onChange:t,hasBrandLogo:n,fromCodebase:a,withConcepts:r,disabled:l}){const o=V().web,c=o.identity,d=o.variantGroup,m=i.useId(),u=x=>t({...e,...x}),h=e.start==="scratch",f=e.concepts??Em;return s.jsxs("div",{className:"ms-idstart",role:"group","aria-labelledby":`${m}-t`,children:[s.jsx("span",{className:"ms-idstart-lbl",id:`${m}-t`,children:c.start}),s.jsx(it,{label:c.start,value:e.start,disabled:l,onChange:x=>u({start:x}),options:[{value:"brand",label:a&&n?`${c.fromBrand} · ${c.sourceCodebase}`:c.fromBrand},{value:"scratch",label:c.fromScratch}]}),h?s.jsxs("div",{className:"ms-idstart-fields",children:[s.jsx("label",{className:"ms-idstart-lbl",htmlFor:`${m}-name`,children:c.name}),s.jsx(ms,{id:`${m}-name`,value:e.name??"",maxLength:80,placeholder:c.namePlaceholder,disabled:l,onChange:x=>u({name:x.target.value})}),s.jsx("label",{className:"ms-idstart-lbl",htmlFor:`${m}-kw`,children:c.keywords}),s.jsx(ms,{id:`${m}-kw`,value:e.keywords??"",maxLength:300,placeholder:c.keywordsPlaceholder,disabled:l,onChange:x=>u({keywords:x.target.value})}),s.jsx("span",{className:"ms-idstart-lbl",children:c.colors}),s.jsx(it,{label:c.colors,value:e.colors??"brand",disabled:l,onChange:x=>u({colors:x}),options:[{value:"brand",label:c.colorsBrand},{value:"free",label:c.colorsFree}]}),r?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-idstart-lbl",children:d.variants}),s.jsx(it,{label:d.variants,value:String(f),disabled:l,onChange:x=>u({concepts:Number(x)}),options:["1","2","3","4","5"].map(x=>({value:x,label:x}))}),s.jsx("p",{className:"ms-idstart-note",children:d.identityVariantsHint})]}):null]}):s.jsxs("p",{className:"ms-idstart-note",children:[s.jsx(F,{name:n?"check":"drop",size:13}),n?c.fromBrandHint:c.noBrandLogo]})]})}function Pv({value:e,checks:t,onChange:n,disabled:a}){const r=V(),l=r.web.codebase,[o,c]=i.useState(""),[d,m]=i.useState(""),[u,h]=i.useState(null),f=()=>{const b=o.trim();if(!b||!(b.startsWith("/")||b.startsWith("~"))){h(l.needAbsolute);return}if(e.some(v=>v.path===b)){h(l.alreadyLinked);return}h(null),n([...e,{path:b,...d.trim()?{note:d.trim()}:{}}]),c(""),m("")},x=xt(),p=async()=>{try{const b=await x?.pickFolder(l.pickTitle,o.trim()||void 0);b&&(c(b),h(null))}catch(b){h(pe(b))}},g=b=>{b.key==="Enter"&&(b.preventDefault(),f())};return s.jsxs("div",{className:"ms-cbl",children:[s.jsx("p",{className:"ms-cbl-hint",children:l.hint}),e.map((b,v)=>s.jsxs("div",{className:"ms-cbl-item",children:[s.jsx("span",{className:"ms-cbl-icon","aria-hidden":"true",children:s.jsx(F,{name:"code",size:13})}),s.jsx("span",{className:"ms-cbl-path",children:b.path}),t?.find(y=>y.path===b.path)?.exists===!1?s.jsx(Qs,{tone:"warn",children:l.notFound}):null,s.jsx(ms,{className:"ms-cbl-note","aria-label":l.noteFor({path:b.path}),value:b.note??"",disabled:a,onChange:y=>n(e.map((w,j)=>j===v?{path:w.path,...y.target.value?{note:y.target.value}:{}}:w))}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,disabled:a,"aria-label":l.remove({path:b.path}),title:l.remove({path:b.path}),onClick:()=>n(e.filter((y,w)=>w!==v)),children:s.jsx(F,{name:"close",size:11})})]},b.path)),s.jsxs("div",{className:"ms-cbl-add",children:[s.jsx(ms,{className:"ms-cbl-input ms-cbl-mono","aria-label":l.pathAria,placeholder:l.pathPlaceholder,value:o,disabled:a,onChange:b=>c(b.target.value),onKeyDown:g}),s.jsx(ms,{className:"ms-cbl-input","aria-label":l.noteAria,placeholder:l.notePlaceholder,value:d,disabled:a,onChange:b=>m(b.target.value),onKeyDown:g}),x?s.jsxs($,{size:"sm",variant:"outline",disabled:a,onClick:()=>{p()},children:[s.jsx(F,{name:"folder",size:12}),r.web.common.chooseFolder]}):null,s.jsx($,{size:"sm",variant:"ink",disabled:a,onClick:f,children:l.link})]}),u?s.jsx("p",{role:"alert",className:"ms-cbl-error",children:u}):null]})}const od=e=>`assets/${e}`,gE=e=>e.kind==="image"&&/\.(png|jpe?g|webp)$/i.test(e.file),Bf=gE;function vE({open:e,onClose:t,slug:n,onPick:a}){const l=V().web.storePack,[o,c]=i.useState(null),[d,m]=i.useState(null),[u,h]=i.useState(!1),f=i.useRef(null);i.useEffect(()=>{if(!e)return;let g=!0;return m(null),c(null),Promise.resolve().then(()=>q.listAssets(n)).then(b=>{g&&c(b.assets)}).catch(b=>{g&&m(l.pickerLoadFailed({detail:pe(b)}))}),()=>{g=!1}},[e,n]);const x=async g=>{if(g.length!==0){h(!0),m(null);try{let v=(await q.uploadFiles(n,"assets",g)).assets??[];if(v.length===0){const w=await q.listAssets(n);v=w.unregistered.length>0?(await q.registerAssets(n,w.unregistered)).assets:[]}c(w=>[...(w??[]).filter(j=>!v.some(S=>S.file===j.file)),...v]);const y=v.find(Bf);y?a(od(y.file)):m(l.pickerWrongFile)}catch(b){m(l.pickerUploadFailed({detail:pe(b)}))}finally{h(!1)}}},p=o?o.filter(Bf):[];return s.jsx(rt,{open:e,onClose:t,label:l.pickerTitle,width:520,dismissible:!u,children:s.jsxs("div",{className:"ms-sp-picker",children:[s.jsxs("header",{className:"ms-sp-pick-head",children:[s.jsx("h2",{children:l.pickerTitle}),s.jsxs($,{size:"sm",variant:"outline",disabled:u,onClick:()=>f.current?.click(),children:[s.jsx(F,{name:"upload",size:13}),u?l.pickerUploading:l.pickerUpload]}),s.jsx("input",{ref:f,type:"file",accept:"image/png,image/jpeg,image/webp",hidden:!0,"aria-label":l.pickerUploadInput,onChange:g=>{x(Array.from(g.target.files??[])),g.target.value=""}})]}),d?s.jsx("p",{className:"ms-sp-error",role:"alert",children:d}):null,o===null&&!d?s.jsx("div",{className:"ms-sp-pick-state",children:s.jsx(Ts,{size:16,label:l.pickerLoading})}):null,o!==null&&p.length===0?s.jsx("p",{className:"ms-sp-pick-empty",children:l.pickerEmpty}):null,p.length>0?s.jsx("ul",{className:"ms-sp-list","aria-label":l.pickerList,children:p.map(g=>s.jsx("li",{children:s.jsxs("button",{type:"button",className:"ms-sp-item",disabled:u,onClick:()=>a(od(g.file)),children:[s.jsx("img",{className:"ms-sp-thumb",src:q.projectFileUrl(n,od(g.file)),alt:""}),s.jsx("span",{className:"ms-sp-pick-name",children:g.file}),g.description?s.jsx("span",{className:"ms-sp-pick-desc",children:g.description}):null]})},g.file))}):null,s.jsx("footer",{className:"ms-sp-pick-foot",children:s.jsx($,{size:"sm",variant:"ghost",disabled:u,onClick:t,children:l.pickerClose})})]})})}const Ui=["app","stores","screens","preview","review"],xo=["appstore","playstore"],bE={appstore:"iphone-69",playstore:"phone"},Uf={"iphone-69":"iphone69","ipad-13":"ipad13",phone:"phone",tablet:"tablet",feature:"feature"};function _f(e){return e.length===0?{min:1,max:10}:{min:Math.max(...e.map(t=>Od[t].min)),max:Math.min(...e.map(t=>Od[t].max))}}const qf=(e,{min:t,max:n})=>Math.min(n,Math.max(t,e));function Vf(e){const t={};return e.stores.includes("appstore")&&(t.appstore=ox.filter(n=>e.devices.appstore.includes(n))),e.stores.includes("playstore")&&(t.playstore=cx.filter(n=>e.devices.playstore.includes(n))),{app:{name:e.name.trim(),tagline:e.tagline.trim()},stores:xo.filter(n=>e.stores.includes(n)),devices:t,screenshots:e.shots.slice(0,e.count).map(n=>({caption:n.caption.trim(),screen:n.screen})),preview:e.preview}}const Av=()=>Array.from({length:Od.appstore.max},()=>({caption:"",screen:null,noScreen:!1})),cd=e=>e.screen!==null||e.noScreen===!0,Kf=e=>e.split("/").pop()??e;function jE(e){const t=Av().map((n,a)=>{const r=e.screenshots[a];return r?{caption:r.caption,screen:r.screen,noScreen:r.screen===null}:n});return{name:e.app.name,tagline:e.app.tagline,stores:[...e.stores],devices:{appstore:[...e.devices.appstore??["iphone-69"]],playstore:[...e.devices.playstore??["phone"]]},count:e.screenshots.length,shots:t,preview:e.preview}}function Lv(e){const n=V().web.storePack,a=i.useRef(!1),[r,l]=i.useState(!1);i.useEffect(()=>{e.open||l(!1)},[e.open]);const o=()=>{a.current?l(!0):e.onClose()};return s.jsxs(s.Fragment,{children:[s.jsx(rt,{open:e.open,onClose:o,label:n.title,width:760,children:e.open?s.jsx(yE,{slug:e.slug,onClose:o,onDone:e.onClose,dirty:a,...e.initial?{initial:e.initial}:{},...e.onConfirm?{onConfirm:e.onConfirm}:{}}):null}),s.jsx(rt,{open:e.open&&r,onClose:()=>l(!1),label:n.closeTitle,width:420,children:s.jsxs("div",{className:"ms-spw-close",children:[s.jsx("h2",{children:n.closeTitle}),s.jsx("p",{children:n.closeBody}),s.jsxs("div",{className:"ms-spw-close-actions",children:[s.jsx($,{variant:"outline",onClick:()=>l(!1),children:n.keepEditing}),s.jsx($,{variant:"ink",onClick:()=>{l(!1),e.onClose()},children:n.discard})]})]})})]})}function yE({onClose:e,onDone:t,slug:n,dirty:a,initial:r,onConfirm:l}){const o=V(),c=o.web.storePack,[d,m]=i.useState(0),[u,h]=i.useState(()=>r?jE(r):{name:"",tagline:"",stores:["appstore"],devices:{appstore:["iphone-69"],playstore:["phone"]},count:3,shots:Av(),preview:!1}),[f,x]=i.useState(null),[p,g]=i.useState(null),[b,v]=i.useState(null),y=i.useRef(null),w=i.useRef(!0),j=i.useRef(!1),S=i.useId(),k=i.useId(),E=i.useId();a.current=r?JSON.stringify(Vf({...u,count:qf(u.count,_f(u.stores))}))!==JSON.stringify(r):u.name.trim()!==""||u.tagline.trim()!==""||u.shots.some(J=>J.caption.trim()!==""||cd(J));const N=J=>h(se=>({...se,...J})),C=_f(u.stores),R=qf(u.count,C),P=u.shots.slice(0,R),z=J=>J==="appstore"?o.variants.storePack.appStore:o.variants.storePack.googlePlay,O={app:u.name.trim()!=="",stores:u.stores.length>0,screens:P.every(J=>cd(J)),preview:!0,review:!0},T=P.flatMap((J,se)=>cd(J)?[]:[se+1]),W=J=>Ui.slice(0,J).every(se=>O[se]),Z=J=>{W(J)&&m(J)},A=Ui[d];i.useEffect(()=>{if(w.current){w.current=!1;return}y.current?.focus()},[d]);const L=(J,se)=>N({stores:se?xo.filter(U=>U===J||u.stores.includes(U)):u.stores.filter(U=>U!==J)}),_=(J,se,U)=>{if(J==="appstore"){const te=se;N({devices:{...u.devices,appstore:U?[...u.devices.appstore,te]:u.devices.appstore.filter(G=>G!==te)}})}else{const te=se;N({devices:{...u.devices,playstore:U?[...u.devices.playstore,te]:u.devices.playstore.filter(G=>G!==te)}})}},X=(J,se)=>N({shots:u.shots.map((U,te)=>te===J?{...U,...se}:U)}),ae=Vf({...u,count:R}),K=c.creativeTitle({name:ae.app.name}),I=async J=>{if(j.current)return;const se=Tj.safeParse(ae);if(!se.success){v(c.createFailed({detail:se.error.issues.map(U=>U.message).join("; ")}));return}j.current=!0,g(J?"generate":"draft"),v(null);try{if(l){await l(se.data),t();return}const U=await q.createStorePack(n,{title:K,storePack:se.data,generate:J});J?Bs(es.creative(n,U.slug)):(Pe.show(c.draftSaved({title:K}),{tone:"ok",action:{label:o.web.newCreative.open,run:()=>Bs(es.creative(n,U.slug))}}),Bs(es.project(n))),t()}catch(U){j.current=!1,g(null),v(l?c.saveFailed({detail:pe(U)}):c.createFailed({detail:pe(U)}))}},H=J=>J==="appstore"?ox:cx,de=J=>J==="appstore"?u.devices.appstore:u.devices.playstore;return s.jsxs("div",{className:"ms-spw",children:[s.jsxs("header",{className:"ms-spw-head",children:[s.jsxs("div",{className:"ms-spw-titles",children:[s.jsx("h2",{children:c.title}),s.jsx("span",{className:"ms-spw-sub",children:c.stepOf({n:d+1,total:Ui.length,name:c.steps[A]})})]}),s.jsx($,{variant:"ghost",icon:!0,"aria-label":o.common.close,disabled:p!==null,onClick:e,children:s.jsx(F,{name:"close",size:13,strokeWidth:1.6})})]}),s.jsx("ol",{className:"ms-spw-steps","aria-label":c.stepsLabel,children:Ui.map((J,se)=>s.jsx("li",{children:s.jsxs("button",{type:"button",className:le("ms-spw-step",se===d&&"ms-on",se<d&&"ms-done"),"aria-current":se===d?"step":void 0,disabled:p!==null||!W(se),onClick:()=>Z(se),children:[s.jsx("span",{className:"ms-spw-num","aria-hidden":"true",children:se<d&&O[J]?s.jsx(F,{name:"check",size:10,strokeWidth:2.4}):se+1}),s.jsx("span",{children:c.steps[J]})]})},J))}),s.jsxs("div",{className:"ms-spw-body",children:[s.jsx("h3",{className:"ms-spw-h",ref:y,tabIndex:-1,children:c.steps[A]}),A==="app"?s.jsxs("div",{className:"ms-spw-fields",children:[s.jsx("label",{className:"ms-spw-lbl",htmlFor:S,children:c.appName}),s.jsx(ms,{id:S,value:u.name,maxLength:60,onChange:J=>N({name:J.target.value}),onKeyDown:J=>{J.key==="Enter"&&O.app&&(J.preventDefault(),m(1))}}),s.jsxs("label",{className:"ms-spw-lbl",htmlFor:k,children:[c.tagline," ",s.jsx("span",{className:"ms-spw-faint",children:c.taglineHint})]}),s.jsx(ms,{id:k,value:u.tagline,maxLength:120,onChange:J=>N({tagline:J.target.value})})]}):null,A==="stores"?s.jsxs("div",{className:"ms-spw-stores",children:[s.jsx("div",{role:"group","aria-label":c.stores,className:"ms-spw-storelist",children:xo.map(J=>s.jsxs("label",{className:"ms-spw-store",children:[s.jsx(Rn,{on:u.stores.includes(J),label:z(J),onChange:se=>L(J,se)}),s.jsx(en,{channel:J==="appstore"?"appstore":"googleplay",size:20}),s.jsx("span",{children:z(J)})]},J))}),u.stores.length===0?s.jsxs("p",{className:"ms-spw-err",id:E,children:[s.jsx(F,{name:"warn",size:13}),c.oneStore]}):null,xo.filter(J=>u.stores.includes(J)).map(J=>s.jsxs("div",{role:"group","aria-label":c.devicesFor({store:z(J)}),className:"ms-spw-devices",children:[s.jsx("span",{className:"ms-spw-cap",children:c.devicesFor({store:z(J)})}),H(J).map(se=>{const U=se===bE[J],te=c.devices[Uf[se]];return s.jsxs("label",{className:"ms-spw-device",children:[s.jsx(Rn,{on:U||de(J).includes(se),label:te,disabled:U,onChange:G=>_(J,se,G)}),s.jsx("span",{children:te}),s.jsx("span",{className:"ms-spw-faint",children:U?c.required:c.optional})]},se)})]},J))]}):null,A==="screens"?s.jsxs("div",{className:"ms-spw-screens",children:[s.jsxs("div",{className:"ms-spw-count",children:[s.jsx(Tt,{label:c.count,value:R,min:C.min,max:C.max,decimals:0,onChange:J=>N({count:J})}),s.jsx("span",{className:"ms-spw-faint",children:c.countRange(C)})]}),s.jsx("p",{className:"ms-spw-faint",children:c.captionHint}),T.length>0?s.jsxs("p",{className:"ms-spw-err",role:"status",children:[s.jsx(F,{name:"warn",size:13}),c.screenMissing({list:T.join(", ")})]}):null,s.jsx("ol",{className:"ms-spw-shots",children:P.map((J,se)=>s.jsxs("li",{className:le("ms-spw-shot",J.noScreen&&"ms-nos"),children:[s.jsx("span",{className:"ms-spw-n","aria-hidden":"true",children:se+1}),s.jsx(ms,{"aria-label":c.captionOf({n:se+1}),placeholder:c.caption,value:J.caption,maxLength:Ej,title:J.caption||void 0,onChange:U=>X(se,{caption:U.target.value})}),s.jsxs("div",{className:"ms-spw-screen",children:[J.screen?s.jsxs(s.Fragment,{children:[s.jsx("img",{className:"ms-spw-thumb",src:q.projectFileUrl(n,J.screen),alt:""}),s.jsx("span",{className:"ms-spw-file",title:J.screen,children:Kf(J.screen)}),s.jsx($,{size:"sm",variant:"outline","aria-label":c.chooseScreen({n:se+1}),onClick:()=>x(se),children:c.changeScreen}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":c.removeScreen({n:se+1}),onClick:()=>X(se,{screen:null}),children:s.jsx(F,{name:"close",size:12})})]}):s.jsxs($,{size:"sm",variant:"outline","aria-label":c.chooseScreen({n:se+1}),onClick:()=>x(se),children:[s.jsx(F,{name:"image",size:13}),c.screen]}),s.jsx($,{size:"sm",variant:J.noScreen?"ink":"ghost","aria-pressed":J.noScreen===!0,"aria-label":c.noScreenOf({n:se+1}),onClick:()=>X(se,J.noScreen?{noScreen:!1}:{noScreen:!0,screen:null}),children:c.noScreenChoice})]})]},se))})]}):null,A==="preview"?s.jsxs("div",{className:"ms-spw-fields",children:[s.jsx("span",{className:"ms-spw-lbl",id:E,children:c.previewQuestion}),s.jsx(it,{label:c.previewQuestion,value:u.preview?"yes":"no",onChange:J=>N({preview:J==="yes"}),options:[{value:"yes",label:c.previewYes},{value:"no",label:c.previewNo}]}),s.jsx("p",{className:"ms-spw-faint",children:c.previewHint})]}):null,A==="review"?s.jsxs("dl",{className:"ms-spw-review",children:[s.jsx("dt",{children:c.reviewApp}),s.jsxs("dd",{children:[s.jsx("b",{children:ae.app.name}),ae.app.tagline?s.jsxs("span",{className:"ms-spw-faint",children:[" · ",ae.app.tagline]}):null]}),s.jsx("dt",{children:c.reviewStores}),s.jsx("dd",{className:"ms-spw-marks",children:ae.stores.map(J=>s.jsxs("span",{children:[s.jsx(en,{channel:J==="appstore"?"appstore":"googleplay"}),z(J)]},J))}),s.jsx("dt",{children:c.reviewDevices}),s.jsx("dd",{children:ae.stores.map(J=>s.jsxs("div",{children:[z(J),": ",(ae.devices[J]??[]).map(se=>c.devices[Uf[se]]).join(", ")]},J))}),s.jsx("dt",{children:c.reviewShots}),s.jsx("dd",{children:s.jsx("ol",{className:"ms-spw-rshots",children:ae.screenshots.map((J,se)=>s.jsxs("li",{children:[s.jsxs("span",{children:[se+1," · ",J.caption||c.reviewFromBrief]})," ",s.jsx("span",{className:"ms-spw-faint",children:J.screen?Kf(J.screen):c.reviewNoScreen})]},se))})}),ae.screenshots.some(J=>J.screen===null)?s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:c.noScreenChoice}),s.jsx("dd",{children:c.reviewNoScreenRows({list:ae.screenshots.flatMap((J,se)=>J.screen===null?[se+1]:[]).join(", ")})})]}):null,s.jsx("dt",{children:c.reviewPreview}),s.jsx("dd",{children:ae.preview?c.yes:c.no})]}):null]}),s.jsxs("footer",{className:"ms-spw-foot",children:[A==="review"?s.jsx("b",{className:"ms-spw-count-line",children:c.reviewFormats({count:Rl(ae).formats.length})}):s.jsx("span",{}),s.jsxs("div",{className:"ms-spw-actions",children:[s.jsx($,{variant:"ghost",disabled:p!==null,onClick:e,children:o.common.cancel}),d>0?s.jsx($,{variant:"outline",disabled:p!==null,onClick:()=>m(d-1),children:c.back}):null,A==="review"&&l?s.jsx($,{variant:"accent",loading:p!==null,disabled:p!==null,onClick:()=>{I(!0)},children:r?c.confirmUpdate:c.confirmAdd}):A==="review"?s.jsxs(s.Fragment,{children:[s.jsx($,{variant:"outline",loading:p==="draft",disabled:p!==null,onClick:()=>{I(!1)},children:c.saveDraft}),s.jsxs($,{variant:"accent",loading:p==="generate",disabled:p!==null,onClick:()=>{I(!0)},children:[s.jsx(F,{name:"sparkle",size:14}),c.generate]})]}):s.jsx($,{variant:"ink",disabled:!O[A],onClick:()=>m(d+1),children:c.next})]}),b?s.jsxs("p",{className:"ms-spw-ferr",role:"alert",children:[s.jsx(F,{name:"warn",size:14}),s.jsx("span",{children:b})]}):null]}),s.jsx(vE,{open:f!==null,onClose:()=>x(null),slug:n,onPick:J=>{f!==null&&X(f,{screen:J,noScreen:!1}),x(null)}})]})}function wE(e){return e.find(t=>t.id==="appstore-iphone-69")?.channel??e.find(t=>t.id.startsWith("appstore-"))?.channel??null}function kE(e,t,n=[]){if(!e)return{formats:[],formatLabels:{},links:{},assets:[],videos:0,images:0,durationSec:null,pack:null,full:null};const a=Rj(e,new Map,n,t),r="full"in a?{instances:Rl(e,t).formats,formatLabels:Rl(e,t).formatLabels,links:Rl(e,t).links}:a,l=r.instances.filter(c=>t.find(d=>d.id===kt(c))?.kind==="video").length,o=[...new Set(e.screenshots.flatMap(c=>c.screen?[c.screen]:[]))];return{formats:r.instances,formatLabels:r.formatLabels,links:r.links,assets:o,videos:l,images:r.instances.length-l,durationSec:e.preview?Mj:null,pack:{...e,instances:r.instances},full:"full"in a?a.full:null}}const dd=10;function NE({value:e,onChange:t,disabled:n}){const r=V().web.languages,l=rs(),o=i.useId(),c=[...ei].sort((h,f)=>Js(h.tag,l).localeCompare(Js(f.tag,l),l)),d=h=>{if(h===""){t(void 0);return}const f=h;t({primary:f,extra:(e?.extra??[]).filter(x=>x!==f)})},m=h=>{if(!e)return;const f=e.extra.includes(h);t({primary:e.primary,extra:f?e.extra.filter(x=>x!==h):[...e.extra,h]})},u=(e?.extra.length??0)>=dd;return s.jsxs("div",{className:"ms-brief-langs",children:[s.jsx("span",{className:"ms-brief-lbl",children:r.briefTitle}),s.jsx("p",{className:"ms-brief-hint",id:o,children:r.briefHint}),s.jsx(At,{label:r.briefPrimary,value:e?.primary??"",disabled:n,onChange:d,options:[{value:"",label:r.briefNone},...c.map(h=>({value:h.tag,label:Js(h.tag,l)})),...tf.map(h=>({value:h,label:Js(h,l),disabled:!0,hint:r.briefRtl}))]}),e?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-brief-lbl",children:r.briefExtra({count:e.extra.length,max:dd})}),s.jsxs("div",{className:"ms-brief-chips",role:"group","aria-label":r.briefExtraLabel,children:[c.filter(h=>h.tag!==e.primary).map(h=>{const f=e.extra.includes(h.tag);return s.jsx(sn,{on:f,disabled:n||!f&&u,title:!f&&u?r.briefFull({max:dd}):void 0,onClick:()=>m(h.tag),children:Js(h.tag,l)},h.tag)}),tf.map(h=>s.jsx(sn,{disabled:!0,title:r.briefRtl,onClick:()=>{},children:Js(h,l)},h))]}),s.jsx("p",{className:"ms-brief-hint ms-brief-rtl",children:r.briefRtl})]}):null]})}const Iv=["none","6","15","30","60","custom"],Wf=e=>e===null?"none":Iv.includes(String(e))?String(e):"custom";function Hf(e,t){const n=[...t];return e.forEach((a,r)=>{if(t.includes(a))return;let l=0;for(let o=r-1;o>=0;o--){const c=n.indexOf(e[o]);if(c>=0){l=c+1;break}}n.splice(l,0,a)}),n}function SE({slug:e,detail:t,presets:n,disabled:a,onChanged:r,onRefresh:l}){const o=V(),c=o.web.conversation,d=o.web.newCreative,m=rs(),u=i.useId(),h=t.creative,[f,x]=i.useState(h.title),[p,g]=i.useState(h.brief),[b,v]=i.useState(h.brief),y=i.useRef(h.brief),w=fe=>{y.current=fe,v(fe)},[j,S]=i.useState(()=>Wf(h.brief.durationSec)),[k,E]=i.useState(()=>Wf(h.brief.durationSec)==="custom"?String(h.brief.durationSec):""),[N,C]=i.useState(h.brief.assets.join(", ")),[R,P]=i.useState(h.linkedCodebases),[z,O]=i.useState(null),T=Sc(),W=Cc(),[Z,A]=i.useState(null),[L,_]=i.useState(null),X=(fe,Ge)=>g(De=>({...De,[fe]:Ge})),ae=(fe,Ge)=>{const De=Object.fromEntries(Object.entries(Ge??{}).filter(([os])=>fe.includes(os)));return Object.keys(De).length>0?De:void 0},K=fe=>g(Ge=>{const{formatLabels:De,...os}=Ge,Ze=ae(fe,Ge.formatLabels);return{...os,formats:fe,...Ze?{formatLabels:Ze}:{}}}),I=fe=>{const Ge=p.formats.filter(De=>kt(De)===fe);if(Ge.length===0){K([...p.formats,fe]);return}if(Ge.some(De=>b.formats.includes(De))){de(Ge);return}be(Ge)},[H,de]=i.useState(null),[J,se]=i.useState(!1),[U,te]=i.useState(!1),[G,re]=i.useState(!1),oe=b.storePack,Ne=async fe=>{A(null);const Ge=y.current,De=await q.updateCreative(e,t.slug,{storePack:fe}),os=new Set([...Ge.storePack?jo(Ge.storePack):[],...De.brief.storePack?jo(De.brief.storePack):[]]);w(De.brief),g(Ze=>{const vs=Ze.formats.filter(xe=>!Ge.formats.includes(xe)||De.brief.formats.includes(xe)),Le=Hf(vs,De.brief.formats),ne={...Ze.formatLabels??{}};for(const xe of os)delete ne[xe],De.brief.formatLabels?.[xe]&&(ne[xe]=De.brief.formatLabels[xe]);const{formatLabels:Ee,storePack:Ce,...Xe}=Ze,ue=ae(Le,ne);return{...Xe,formats:Le,...ue?{formatLabels:ue}:{},...De.brief.storePack?{storePack:De.brief.storePack}:{}}}),l?.()},Q=async()=>{re(!0);try{await Ne(null),te(!1)}catch(fe){te(!1),A(o.web.storePack.saveFailed({detail:pe(fe)}))}re(!1)},[Re,Ue]=i.useState(null),is=fe=>xn(pt(n,fe),fe,m,p.formatLabels),Qe=async fe=>{A(null);try{const Ge=await q.updateCreative(e,t.slug,fe);w(Ge.brief),l?.()}catch(Ge){const De=y.current;g(os=>{const{formatLabels:Ze,...vs}=os,Le=fe.formats?Hf(os.formats,De.formats):os.formats,ne={...Ze??{}};for(const Ce of Object.keys(fe.formatLabels??{})){const Xe=De.formatLabels?.[Ce];Xe?ne[Ce]=Xe:delete ne[Ce]}const Ee=ae(Le,ne);return{...vs,formats:Le,...Ee?{formatLabels:Ee}:{}}}),A(o.web.instances.saveFailed({detail:pe(Ge)}))}},gs=(fe,Ge=[])=>fe.filter(De=>b.formats.includes(De)&&!Ge.includes(De)),As=(fe,Ge=[])=>{const De=gs(fe,Ge),os=b.formats;De.length>0&&(De.length!==os.length||De.some((Ze,vs)=>Ze!==os[vs]))&&Qe({formats:De})},hs=(fe,Ge)=>{const De=p.formats.indexOf(fe);if(De<0||Ge<0||Ge>=p.formats.length||Ge===De)return;const os=p.formats.filter(Ze=>Ze!==fe);os.splice(Ge,0,fe),K(os),As(os)},Oe=fe=>{const Ge=hh(kt(fe),p.formats);if(!Ge)return;const De=p.formats.reduce((os,Ze,vs)=>kt(Ze)===kt(fe)?vs:os,-1);K([...p.formats.slice(0,De+1),Ge,...p.formats.slice(De+1)])},be=fe=>{de(null);const Ge=p.formats.filter(De=>!fe.includes(De));K(Ge),As(Ge,fe)},Fe=fe=>{const Ge=(p.formatLabels?.[fe]??"").trim();!b.formats.includes(fe)||(b.formatLabels?.[fe]??"")===Ge||Qe({formatLabels:{[fe]:Ge}})},je=(fe,Ge)=>g(De=>{const{formatLabels:os,...Ze}=De,vs={...os??{},[fe]:Ge};return{...Ze,formatLabels:vs}}),he=fe=>Ge=>{Ge.preventDefault(),Re&&Re!==fe&&hs(Re,p.formats.indexOf(fe)),Ue(null)},Ke=p.formats.some(fe=>pt(n,fe)?.identity),we=xE(e,Ke),ze=i.useMemo(()=>wE(n),[n]),We=i.useMemo(()=>{const fe=new Map;for(const Ge of n)(!Ge.hidden||p.formats.some(De=>kt(De)===Ge.id))&&fe.set(Ar(Ge.channel),[...fe.get(Ar(Ge.channel))??[],Ge]);return[...fe.entries()]},[n,p.formats]),Rs=i.useMemo(()=>{const fe=h.resumeFrom?t.versions.find(Ge=>Ge.n===h.resumeFrom.version):t.versions.at(-1);return $j(fe,{formats:p.formats,links:Fj(b,p.formats,n)})==="convert"},[h.resumeFrom,b,t.versions,p.formats,n]),us=()=>{if(j==="none")return null;if(j!=="custom")return Number(j);const fe=Number(k);return Number.isInteger(fe)&&fe>=1&&fe<=600?fe:"invalid"},fs=async fe=>{A(null);const Ge=us();if(Ge==="invalid"){A(d.customInvalid);return}const De=p.formats.find(Ze=>!Pj.test(Ze));if(De!==void 0){A(o.web.instances.invalidId({id:De}));return}_(fe?"regenerate":"save");let os=!1;try{const Ze=z??h.brief.services,{services:vs,formatLabels:Le,identity:ne,storePack:Ee,...Ce}=p,Xe=NN(p.formats,p.formatLabels,y.current.formatLabels,{...h.brief.formatLabels,...y.current.formatLabels}),ue=Ke&&p.identity?{identity:Mv(p.identity,we.hasLogo)}:{};await q.updateCreative(e,t.slug,{title:f,brief:{...Ce,...ue,...Xe?{formatLabels:Xe}:{},durationSec:Ge,assets:N.split(",").map(xe=>xe.trim()).filter(Boolean),...Ze?{services:Ze}:{}},linkedCodebases:R}),os=!0,fe&&await q.sendCreativeTurn(e,t.slug,{})}catch(Ze){A(pe(Ze))}_(null),os&&r()};return s.jsxs("form",{className:"ms-brief-form",onSubmit:fe=>{fe.preventDefault(),fs(!1)},children:[s.jsx("label",{className:"ms-brief-lbl",htmlFor:`${u}-title`,children:d.title}),s.jsx(ms,{id:`${u}-title`,value:f,onChange:fe=>x(fe.target.value)}),s.jsx("label",{className:"ms-brief-lbl",htmlFor:`${u}-goal`,children:c.goal}),s.jsx(nn,{id:`${u}-goal`,rows:4,value:p.goal,onChange:fe=>X("goal",fe.target.value)}),s.jsx("label",{className:"ms-brief-lbl",htmlFor:`${u}-msg`,children:d.keyMessage}),s.jsx(ms,{id:`${u}-msg`,value:p.message,onChange:fe=>X("message",fe.target.value)}),s.jsx("span",{className:"ms-brief-lbl",children:c.length}),s.jsx(it,{className:"ms-brief-len",label:c.lengthFor,value:j,onChange:S,options:Iv.map(fe=>({value:fe,label:fe==="none"?c.lengthNone:fe==="custom"?d.custom:d.secondsShort({n:Number(fe)})}))}),j==="custom"?s.jsx(ms,{inputMode:"numeric","aria-label":d.customSeconds,placeholder:d.customSeconds,value:k,onChange:fe=>E(fe.target.value.replace(/\D/g,"").slice(0,3))}):null,s.jsx("label",{className:"ms-brief-lbl",htmlFor:`${u}-assets`,children:c.assets}),s.jsx(ms,{id:`${u}-assets`,value:N,onChange:fe=>C(fe.target.value)}),s.jsx("label",{className:"ms-brief-lbl",htmlFor:`${u}-notes`,children:c.notes}),s.jsx(ms,{id:`${u}-notes`,value:p.notes,onChange:fe=>X("notes",fe.target.value)}),s.jsx("span",{className:"ms-brief-lbl",children:c.formats}),s.jsx("div",{className:"ms-brief-formats",children:We.map(([fe,Ge])=>s.jsxs("div",{className:"ms-brief-group",role:"group","aria-label":Dn(fe,m),children:[s.jsxs("span",{className:"ms-brief-ghead",children:[s.jsx(en,{channel:da(fe)}),Dn(fe,m)]}),s.jsxs("div",{className:"ms-brief-chips",children:[Ge.map(De=>s.jsxs(sn,{on:p.formats.some(os=>kt(os)===De.id),onClick:()=>I(De.id),icon:De.kind==="video"?"video":"image",title:De.hidden?`${De.width}×${De.height} · ${o.web.newCreative.formatGone}`:`${De.width}×${De.height}`,children:[sm(De,m),De.hidden?s.jsxs("span",{className:"ms-brief-gone",children:[" · ",o.web.newCreative.formatGone]}):null]},De.id)),fe===ze?s.jsxs("span",{className:"ms-brief-pack",children:[s.jsx(sn,{on:oe!==void 0,onClick:()=>se(!0),icon:"image",disabled:a,title:oe?o.web.storePack.entryAria({count:oe.screenshots.length}):o.web.storePack.entryAdd,children:oe?o.web.storePack.entryOn({count:oe.screenshots.length}):o.web.storePack.entryTitle}),oe?s.jsxs(s.Fragment,{children:[s.jsx($,{size:"sm",variant:"ghost",disabled:a,onClick:()=>se(!0),children:o.web.storePack.entryEdit}),s.jsx($,{size:"sm",variant:"ghost","aria-label":o.web.storePack.entryRemoveAria,disabled:a,onClick:()=>te(!0),children:o.web.storePack.entryRemove})]}):null]}):null]})]},fe))}),s.jsx(Lv,{open:J,onClose:()=>se(!1),slug:e,...oe?{initial:oe}:{},onConfirm:Ne}),s.jsx(rt,{open:U,onClose:()=>{G||te(!1)},label:o.web.storePack.removeTitle,width:420,children:s.jsxs("div",{className:"ms-brief-confirm",children:[s.jsx("h3",{children:o.web.storePack.removeTitle}),s.jsx("p",{children:o.web.storePack.removeBody}),s.jsxs("div",{className:"ms-brief-actions",children:[s.jsx($,{variant:"danger",loading:G,disabled:G,onClick:()=>{Q()},children:o.web.storePack.removeConfirm}),s.jsx($,{variant:"outline",disabled:G,onClick:()=>te(!1),children:o.common.cancel})]})]})}),p.formats.length>0?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-brief-lbl",id:`${u}-inst`,children:o.web.instances.title}),s.jsx("p",{className:"ms-brief-hint",children:o.web.instances.hint}),s.jsx("ol",{className:"ms-brief-inst","aria-labelledby":`${u}-inst`,children:p.formats.map((fe,Ge)=>{const De=pt(n,fe),os=is(fe),Ze=hh(kt(fe),p.formats)===null;return s.jsxs("li",{className:le("ms-brief-inst-row",Re===fe&&"ms-drag"),onDragOver:vs=>{Re&&vs.preventDefault()},onDrop:he(fe),children:[s.jsxs("span",{className:"ms-brief-inst-head",children:[s.jsx("span",{className:"ms-brief-inst-grip",draggable:!a,title:o.web.instances.dragHandle({name:os}),"aria-hidden":"true",onDragStart:vs=>{Ue(fe),vs.dataTransfer?.setData("text/plain",fe)},onDragEnd:()=>Ue(null),children:s.jsx(F,{name:"menu",size:13})}),De?s.jsx(en,{channel:da(De.channel)}):null,s.jsx("b",{className:"ms-brief-inst-name",children:os})]}),s.jsx(ms,{className:"ms-brief-inst-label","aria-label":o.web.instances.labelOf({name:os}),placeholder:o.web.instances.labelPlaceholder,maxLength:60,value:p.formatLabels?.[fe]??"",disabled:a,onChange:vs=>je(fe,vs.target.value),onBlur:()=>Fe(fe),onKeyDown:vs=>{vs.key==="Enter"&&(vs.preventDefault(),Fe(fe))}}),s.jsxs("span",{className:"ms-brief-inst-actions",children:[s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":o.web.instances.moveUp({name:os}),disabled:a||Ge===0,onClick:()=>hs(fe,Ge-1),children:s.jsx("span",{className:"ms-brief-up",children:s.jsx(F,{name:"chevron",size:13})})}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":o.web.instances.moveDown({name:os}),disabled:a||Ge===p.formats.length-1,onClick:()=>hs(fe,Ge+1),children:s.jsx(F,{name:"chevron",size:13})}),s.jsxs($,{size:"sm",variant:"ghost","aria-label":o.web.instances.addAnother({name:os}),title:Ze?o.web.instances.full:void 0,disabled:a||Ze||!De,onClick:()=>Oe(fe),children:[s.jsx(F,{name:"plus",size:13}),o.web.instances.addAnotherShort]}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":o.web.instances.remove({name:os}),disabled:a,onClick:()=>de([fe]),children:s.jsx(F,{name:"trash",size:13})})]})]},fe)})})]}):null,s.jsx(rt,{open:H!==null,onClose:()=>de(null),label:H?o.web.instances.removeTitle({name:H.map(is).join(", ")}):"",width:420,children:s.jsxs("div",{className:"ms-brief-confirm",children:[s.jsx("h3",{children:H?o.web.instances.removeTitle({name:H.map(is).join(", ")}):""}),s.jsx("p",{children:o.web.instances.removeBody}),s.jsxs("div",{className:"ms-brief-actions",children:[s.jsx($,{variant:"danger",onClick:()=>{H&&be(H)},children:o.web.instances.removeConfirm}),s.jsx($,{variant:"outline",onClick:()=>de(null),children:o.common.cancel})]})]})}),Ke?s.jsx(Fv,{value:Tm(p.identity,we.hasLogo),onChange:fe=>X("identity",fe),hasBrandLogo:we.hasLogo,fromCodebase:we.fromCodebase,withConcepts:!1,disabled:a}):null,s.jsx(NE,{value:p.locales,disabled:a,onChange:fe=>g(Ge=>{const{locales:De,...os}=Ge;return fe?{...os,locales:fe}:os})}),s.jsx("span",{className:"ms-brief-lbl",children:o.web.services.title}),s.jsx("p",{className:"ms-brief-hint",children:o.web.services.hint}),s.jsx(Sm,{value:z??h.brief.services,configured:T,checks:W,disabled:a,onChange:O}),s.jsx("span",{className:"ms-brief-lbl",children:d.codebases}),s.jsx(Pv,{value:R,onChange:P,disabled:a}),Rs?s.jsxs("p",{className:"ms-brief-notice",role:"note",children:[s.jsx(F,{name:"warn",size:13}),s.jsx("span",{children:c.legacyConvertNotice})]}):null,Z?s.jsx("p",{role:"alert",className:"ms-brief-error",children:Z}):null,s.jsxs("div",{className:"ms-brief-actions",children:[s.jsx($,{type:"submit",variant:"outline",disabled:a||L!==null,loading:L==="save",children:o.common.save}),s.jsx($,{variant:"ink",disabled:a||L!==null||p.formats.length===0,loading:L==="regenerate",onClick:()=>{fs(!0)},children:c.saveAndRegenerate})]})]})}let Jr={title:null,end:null,owner:null,crumb:null};const du=new Set,Cl=e=>{Jr={...Jr,...e};for(const t of du)t()},CE=e=>(du.add(e),()=>{du.delete(e)}),Gf=()=>Jr;function zv(e,t){Jr[e]!==t&&Cl({[e]:t})}function Ov(){return i.useSyncExternalStore(CE,Gf,Gf)}function Tc(e,t,n){const a=Ov();i.useLayoutEffect(()=>{if(t)return Cl({owner:e}),()=>{Jr.owner===e&&Cl({owner:null})}},[e,t]);const r=i.useRef(n?.open);r.current=n?.open;const l=n?.title||null,o=n?.variant??null,c=!!n?.open;return i.useLayoutEffect(()=>{if(!(!t||!l&&!o&&!c))return Cl({crumb:{key:e,title:l,variant:o,open:c?()=>r.current?.():null}}),()=>{Jr.crumb?.key===e&&Cl({crumb:null})}},[e,t,l,o,c]),t&&a.owner===e?a:null}function Rm(e,t,n){const r=V().web.removal,[l,o]=i.useState(null),[c,d]=i.useState(null),[m,u]=i.useState(!1),[h,f]=i.useState(null),[x,p]=i.useState(null),g=i.useRef(n);g.current=n;const b=i.useRef(!0);i.useEffect(()=>(b.current=!0,()=>{b.current=!1}),[]);const v=i.useCallback(()=>{o(null),d(null),Promise.resolve().then(()=>q.creativeRemoval(e,t)).then(z=>{b.current&&o(z)}).catch(z=>{b.current&&d(pe(z))})},[e,t]),y=l?.role==="host",w=l?.title??t,j=async()=>{u(!0),p(null);try{await q.archiveCreative(e,t,y),f(null),Pe.show(r.archived({title:w}),{tone:"ok",...l?.role==="sister"?{}:{action:{label:r.undo,run:()=>{S()}}}}),g.current?.("archived")}catch(z){h?p(pe(z)):Pe.show(r.archiveFailed({detail:pe(z)}),{tone:"neutral"})}finally{b.current&&u(!1)}},S=async()=>{try{await q.unarchiveCreative(e,t),Pe.show(r.restored({title:w}),{tone:"ok"}),g.current?.("restored")}catch(z){Pe.show(r.restoreFailed({detail:pe(z)}),{tone:"neutral"})}},k=async()=>{u(!0),p(null);try{await q.deleteCreative(e,t,y),f(null),Pe.show(r.deleted({title:w}),{tone:"ok"}),g.current?.("deleted")}catch(z){p(pe(z))}finally{b.current&&u(!1)}},E=()=>{m||(f(null),p(null))},N=l?.members??1,C=l?.letter?.toUpperCase()??"",R=h==="archive"?r.archiveGroupBody({count:N}):y?r.deleteGroupBody({count:N}):l?.role==="sister"?r.deleteVariantBody({letter:C}):r.deleteBody,P=s.jsx(rt,{open:h!==null,onClose:E,label:h==="archive"?r.archiveGroupTitle({title:w}):r.deleteTitle({title:w}),width:460,dismissible:!m,children:s.jsxs("div",{className:"ms-vdlg","data-testid":"removal-dialog",children:[s.jsx("h2",{children:h==="archive"?r.archiveGroupTitle({title:w}):r.deleteTitle({title:w})}),s.jsx("p",{className:"ms-vdlg-hint",children:R}),x?s.jsx("p",{role:"alert",className:"ms-vdlg-err",children:x}):null,s.jsxs("div",{className:"ms-vdlg-actions",children:[s.jsx($,{type:"button",variant:"ghost",onClick:E,disabled:m,children:r.cancel}),h==="archive"?s.jsx($,{type:"button",variant:"ink",loading:m,onClick:()=>{j()},children:r.archiveConfirm}):s.jsx($,{type:"button",variant:"danger",loading:m,onClick:()=>{k()},children:r.deleteConfirm})]})]})});return{info:l,failed:c,load:v,busy:m,dialogs:P,archive:()=>{y?(p(null),f("archive")):j()},askDelete:()=>{p(null),f("delete")},restore:()=>{S()}}}function Dv({removal:e,close:t}){const n=V().web.removal,a=i.useId(),{info:r,failed:l}=e,o=l??(r?r.blocked?.message??null:n.checking),c=r?.members??1,d=r?.letter?.toUpperCase()??"",m=r?.role==="host"?[n.archiveGroup({count:c}),n.deleteGroup({count:c})]:r?.role==="sister"?[n.archiveVariant({letter:d}),n.deleteVariant({letter:d})]:[n.archive,n.delete],u=o!==null,h=f=>u?void 0:()=>{t(),f()};return s.jsxs(s.Fragment,{children:[s.jsx(dn,{"data-row":"",role:"menuitem",icon:"folder","aria-disabled":u||void 0,"aria-describedby":u?a:void 0,onClick:h(e.archive),children:m[0]}),s.jsx(dn,{"data-row":"",role:"menuitem",icon:"trash","aria-disabled":u||void 0,"aria-describedby":u?a:void 0,onClick:h(e.askDelete),children:m[1]}),u?s.jsx("p",{id:a,className:"ms-vmenu-why",role:"note",children:o}):null]})}function Bv({slug:e,creative:t,label:n,onDone:a,extra:r,className:l,variant:o="outline",size:c,buttonRef:d}){const[m,u]=i.useState(!1),h=i.useRef(null),f=d??h,x=Rm(e,t,a),{load:p}=x;i.useEffect(()=>{m&&p()},[m,p]);const g=()=>u(!1);return s.jsxs(s.Fragment,{children:[s.jsx($,{ref:f,variant:o,icon:!0,...c?{size:c}:{},className:l,"aria-label":n,"aria-haspopup":"menu","aria-expanded":m,onClick:()=>u(b=>!b),children:s.jsx(F,{name:"more",size:14})}),s.jsx(ot,{open:m,onClose:g,anchor:f,placement:"bottom-end",width:260,children:s.jsxs("div",{role:"menu","aria-label":n,children:[r?.(g),s.jsx(Dv,{removal:x,close:g})]})}),x.dialogs]})}function Mm(e,t,n){const[a,r]=i.useState(null),[l,o]=i.useState([]),[c,d]=i.useState(null),[m,u]=i.useState(0);i.useEffect(()=>{let f=!0;return Promise.all([q.getCreative(e,t),q.getConversation(e,t)]).then(([x,p])=>{f&&(r(x),o(p),d(null))}).catch(x=>{f&&d(pe(x))}),()=>{f=!1}},[e,t,n,m]);const h=i.useCallback(()=>u(f=>f+1),[]);return{detail:a,conversation:l,error:c,reload:h}}const Uv={cues:2e3,words:60,text:200,wordText:100,lang:35,ms:36e6},ud=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),md=(e,t)=>Object.keys(e).every(n=>t.includes(n)),_i=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=Uv.ms,EE=/^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{1,8})*$/;function TE(e){const t=Uv;if(!ud(e)||!md(e,["lang","cues"]))return{ok:!1,reason:"not a subtitles block"};if(typeof e.lang!="string"||e.lang.length>t.lang||!EE.test(e.lang))return{ok:!1,reason:"bad language"};if(!Array.isArray(e.cues)||e.cues.length>t.cues)return{ok:!1,reason:`cues must be an array of at most ${t.cues}`};const n=[];let a=0;for(let r=0;r<e.cues.length;r++){const l=e.cues[r];if(!ud(l)||!md(l,["start","end","text","words"]))return{ok:!1,reason:`cue ${r} is malformed`};if(!_i(l.start)||!_i(l.end)||!(l.end>l.start))return{ok:!1,reason:`cue ${r} has bad times`};if(l.start<a)return{ok:!1,reason:`cue ${r} is out of order`};if(a=l.start,typeof l.text!="string"||l.text.length>t.text)return{ok:!1,reason:`cue ${r} has a bad text`};let o;if(l.words!==void 0){if(!Array.isArray(l.words)||l.words.length>t.words)return{ok:!1,reason:`cue ${r} has too many words`};o=[];for(const c of l.words){if(!ud(c)||!md(c,["start","end","text"])||!_i(c.start)||!_i(c.end)||c.end<c.start||typeof c.text!="string"||c.text.length===0||c.text.length>t.wordText)return{ok:!1,reason:`cue ${r} has a bad word`};o.push({start:c.start,end:c.end,text:c.text})}}n.push({start:l.start,end:l.end,text:l.text,...o?{words:o}:{}})}return{ok:!0,subtitles:{lang:e.lang,cues:Object.freeze(n)}}}const Xf=1,RE=["compositionMissing","compositionInvalid","baseNotAllowed","assetPathRejected","assetLoadFailed","fontMissing","fontLoadFailed","videoSeekTimeout","layerTimeout","layerError","badAnimation","audioBlocked","unknownClipType","frameTimeout","videoFrameMismatch","clipAudioFailed","textOverflow","layerStalled","subtitlesInvalid"],_v=.1,qv=4,ME=.01,$E=8,FE=36e3,PE=64,Vv=2**31-1,oi=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Aa=(e,t)=>Object.keys(e).every(n=>t.includes(n)),kn=e=>typeof e=="number"&&Number.isFinite(e),AE=e=>typeof e=="string"&&e.length>0&&e.length<=PE,Kv=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0&&e<=Vv,hd=36e3,qi=(e,t,n,a=!1)=>kn(e)&&(a?e>t:e>=t)&&e<=n;function LE(e){if(typeof e!="string"||e.length>512||!e.startsWith("assets/")||e.split("/").some(t=>t.trim()===""||t==="."||t===".."))return!1;for(let t=0;t<e.length;t++){const n=e.charCodeAt(t);if(n<32||n>=127&&n<=159||n===92||n===58||n===37||n===63||n===35)return!1}return!0}function Zf(e,t){if(!oi(e))return null;switch(e.type){case"seek":return Aa(e,["type","t"])&&kn(e.t)&&e.t>=0&&e.t<=FE?{type:"seek",t:e.t}:null;case"play":return!Aa(e,["type","loop","rate"])||e.loop!==void 0&&typeof e.loop!="boolean"||e.rate!==void 0&&!(kn(e.rate)&&e.rate>=_v&&e.rate<=qv)?null:{type:"play",...e.loop!==void 0?{loop:e.loop}:{},...e.rate!==void 0?{rate:e.rate}:{}};case"pause":return Aa(e,["type"])?{type:"pause"}:null;case"select":return Aa(e,["type","clipId"])&&(e.clipId===null||AE(e.clipId))?{type:"select",clipId:e.clipId}:null;case"mute":return Aa(e,["type","muted"])&&typeof e.muted=="boolean"?{type:"mute",muted:e.muted}:null;case"setScale":return Aa(e,["type","scale"])&&(e.scale==="fit"||kn(e.scale)&&e.scale>=ME&&e.scale<=$E)?{type:"setScale",scale:e.scale}:null;case"setComposition":{if(!Aa(e,["type","composition","keepTime","seq"])||!Kv(e.seq)||e.keepTime!==void 0&&typeof e.keepTime!="boolean")return null;const n=t?t(e.composition):null;return n?{type:"setComposition",composition:n,...e.keepTime!==void 0?{keepTime:e.keepTime}:{},seq:e.seq}:null}case"sessionMedia":return!Aa(e,["type","src","index","sourceFps","sourceStart","sourceVideoEnd","audioStart"])||!LE(e.src)||!(typeof e.index=="number"&&Number.isInteger(e.index)&&e.index>=0&&e.index<1e4)||!qi(e.sourceFps,0,240,!0)||!qi(e.sourceStart,0,hd)||!qi(e.sourceVideoEnd,0,hd,!0)||e.audioStart!==void 0&&!qi(e.audioStart,0,hd)?null:{type:"sessionMedia",src:e.src,index:e.index,sourceFps:e.sourceFps,sourceStart:e.sourceStart,sourceVideoEnd:e.sourceVideoEnd,...e.audioStart!==void 0?{audioStart:e.audioStart}:{}};case"setSubtitles":{if(!Aa(e,["type","subtitles"])||!("subtitles"in e))return null;if(e.subtitles===null)return{type:"setSubtitles",subtitles:null};const n=TE(e.subtitles);return n.ok?{type:"setSubtitles",subtitles:n.subtitles}:null}default:return null}}const Xa={message:2e3,id:64,name:200,scenes:200,errors:200},Ko=(e,t)=>typeof e=="string"&&e.length<=t,IE=e=>oi(e)&&kn(e.x)&&kn(e.y)&&kn(e.width)&&kn(e.height)?{x:e.x,y:e.y,width:e.width,height:e.height}:null,fd=e=>!oi(e)||!RE.includes(e.code)||typeof e.message!="string"||e.clipId!==void 0&&!Ko(e.clipId,Xa.id)?null:{code:e.code,message:e.message.slice(0,Xa.message),...e.clipId!==void 0?{clipId:e.clipId}:{}},zE=e=>!oi(e)||!Ko(e.id,Xa.id)||!kn(e.start)||!kn(e.duration)||e.name!==void 0&&!Ko(e.name,Xa.name)?null:{id:e.id,...e.name!==void 0?{name:e.name}:{},start:e.start,duration:e.duration};function pd(e,t,n){if(!Array.isArray(e)||e.length>t)return null;const a=[];for(const r of e){const l=n(r);if(l===null)return null;a.push(l)}return a}function OE(e){if(!oi(e))return null;switch(e.type){case"ready":{if(e.version!==Xf||!kn(e.duration)||!kn(e.fps)||!kn(e.width)||!kn(e.height))return null;const t=pd(e.scenes,Xa.scenes,zE),n=pd(e.errors,Xa.errors,fd);return!t||!n?null:{type:"ready",version:Xf,duration:e.duration,fps:e.fps,width:e.width,height:e.height,scenes:t,errors:n}}case"time":return kn(e.t)&&typeof e.playing=="boolean"?{type:"time",t:e.t,playing:e.playing}:null;case"error":{const t=fd(e.error);return t?{type:"error",error:t}:null}case"clipBounds":{if(!(e.clipId===null||Ko(e.clipId,Xa.id))||!kn(e.scale))return null;const t=e.bounds===null?null:IE(e.bounds);return e.bounds!==null&&!t?null:{type:"clipBounds",clipId:e.clipId,bounds:t,scale:e.scale}}case"compositionApplied":{if(!Kv(e.seq))return null;const t=pd(e.errors,Xa.errors,fd);return t?{type:"compositionApplied",seq:e.seq,errors:t}:null}default:return null}}function DE(e,t){if(e.length>t)return!0;let n=0;for(let a=0;a<e.length;a++){const r=e.charCodeAt(a);if(r<128?n+=1:r<2048?n+=2:r>=55296&&r<=56319&&a+1<e.length&&(e.charCodeAt(a+1)&64512)===56320?(n+=4,a++):n+=3,n>t)return!0}return!1}function BE(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;let t;try{t=JSON.stringify(e)}catch{return null}if(typeof t!="string"||DE(t,ic.jsonBytes))return null;const n=Aj.safeParse(JSON.parse(t));return n.success?n.data:null}const $m=6e4,Yr=e=>Math.min(1e4,1e3*2**Math.max(0,e)),UE=5e3,Wv=5,_E=5e3,Fm=(e,t=Date.now())=>Math.min(dv,Math.max(_E,e-t-$m)),Hv=e=>{const t=Date.parse(e);return Number.isFinite(t)?Fm(t):null},Gv=e=>e instanceof lt?e.status:e?.status,Qr=new Map,Xv=e=>e!==null&&Date.parse(e.expiresAt)-Date.now()>$m+1e3,Pm=(e,t)=>{t?.token&&Promise.resolve().then(()=>q.revokePreview(e.slug,e.creative,e.n,t.token)).catch(()=>{})};function Zv(e){window.clearTimeout(e.idle),Qr.get(e.key)===e&&Qr.delete(e.key);const t=e.session;e.session=null,Am(e,t)}function Am(e,t){!t||e.session?.token===t.token||((e.shown.get(t.token)??0)>0?e.retired.set(t.token,t):Pm(e,t))}function qE(e,t){e.shown.set(t,(e.shown.get(t)??0)+1)}function Jf(e,t){const n=(e.shown.get(t)??0)-1;if(n>0){e.shown.set(t,n);return}e.shown.delete(t);const a=e.retired.get(t);a&&(e.retired.delete(t),Pm(e,a))}function VE(e){for(const t of[...Qr.values()])t.users===0&&t.key!==e&&Zv(t)}function KE(e){let t=Qr.get(e.key);return t||(t={...e,session:null,last:null,pending:null,users:0,idle:0,shown:new Map,retired:new Map},Qr.set(e.key,t)),window.clearTimeout(t.idle),t.users+=1,t}function WE(e){e.users=Math.max(0,e.users-1),!(e.users>0)&&(window.clearTimeout(e.idle),e.idle=window.setTimeout(()=>{e.users===0&&Zv(e)},UE))}function HE(e){if(Xv(e.session))return Promise.resolve(e.session);if(e.pending)return e.pending;VE(e.key);const t=e.session?.token??e.last??void 0,n=Promise.resolve().then(()=>t?q.previewSession(e.slug,e.creative,e.n,e.format,window.location.origin,t):q.previewSession(e.slug,e.creative,e.n,e.format,window.location.origin)).then(a=>{const r=e.session;if(e.pending=null,Qr.get(e.key)!==e)throw Pm(e,a),new Error("released");return e.session=a,e.last=a.token,r&&r.token!==a.token&&Am(e,r),a},a=>{throw e.pending=null,a});return e.pending=n,n}function GE(e,t){e.session?.token===t.token&&(e.session=null),Am(e,t)}function el(e){const[t,n]=i.useState({kind:"idle"}),a=e.enabled&&e.n!==null?`${e.slug}/${e.creative}/${e.n}/${e.format}`:null,[r,l]=i.useState({key:null,n:0,wait:!1}),o=i.useRef({key:null,n:0}),c=i.useRef(null),d=i.useRef(null),m=i.useRef(null),u={get current(){return m.current?.token??null}};i.useEffect(()=>{if(a===null||e.n===null){d.current=null;return}const p=KE({key:a,slug:e.slug,creative:e.creative,n:e.n,format:e.format});return d.current=p,()=>{d.current===p&&(d.current=null),WE(p)}},[a]),i.useEffect(()=>()=>{m.current&&(Jf(m.current.e,m.current.token),m.current=null)},[]),i.useEffect(()=>{o.current.key!==a&&(o.current={key:a,n:0});const p=d.current;if(a===null||!p){n({kind:"idle"}),c.current=null;return}let g=!0,b=0;const v=(w,j)=>{window.clearTimeout(b),b=window.setTimeout(()=>{g&&j()},w)},y=w=>{w||n(j=>j.kind==="busy"||j.kind==="ready"&&Xv(j.session)?j:{kind:"loading"}),HE(p).then(j=>{if(!g)return;o.current.n=0,c.current=j,n(k=>k.kind==="ready"&&k.session.token===j.token?k:{kind:"ready",session:j});const S=Hv(j.expiresAt);S!==null&&v(S,()=>y(!0))},j=>{if(!g)return;const S=Gv(j);if(S===404){n({kind:"legacy"});return}if(S===429||w){w||n({kind:"busy"}),v(Yr(o.current.n++),()=>y(w));return}n({kind:"failed",message:pe(j)})})};return r.wait&&r.key===a?(u.current===null&&n({kind:"busy"}),v(Yr(o.current.n++),()=>y(u.current!==null))):y(!1),()=>{g=!1,window.clearTimeout(b)}},[a,r]);const h=i.useCallback(()=>{const p=d.current;p&&c.current&&GE(p,c.current),l(g=>({key:a,n:g.n+1,wait:!0}))},[a]),f=i.useCallback(()=>{o.current.n=0,l(p=>({key:a,n:p.n+1,wait:!1}))},[a]),x=i.useCallback(p=>{const g=d.current,b=m.current;b&&b.token===p&&b.e===g||(b&&Jf(b.e,b.token),m.current=p!==null&&g?{e:g,token:p}:null,p!==null&&g&&qE(g,p))},[]);return{state:t,stalled:h,retry:f,showing:x}}function ci(e){const[t,n]=i.useState(null),[a,r]=i.useState("idle"),l=e.enabled&&e.n!==null&&e.hash!==null?`${e.slug}/${e.creative}/${e.n}/${e.format}/${e.hash}`:null;return i.useEffect(()=>{if(l===null||e.n===null){n(null),r("idle");return}let o=!0,c=0,d=0;const m=e.n,u=(f,x)=>{window.clearTimeout(c),c=window.setTimeout(()=>{o&&x()},f)},h=f=>{Promise.resolve().then(()=>q.getStoryboard(e.slug,e.creative,m,e.format)).then(x=>{if(!o)return;d=0,n(x),r("ready");const p=Hv(x.expiresAt);p!==null&&u(p,()=>h("refresh"))},x=>{if(o){if(f==="refresh"){if(d>=Wv){n(null),r("none");return}u(Yr(d++),()=>h("refresh"));return}if(Gv(x)===429){r("busy"),u(Yr(d++),()=>h("retry"));return}n(null),r("none")}})};return n(null),r("loading"),h("first"),()=>{o=!1,window.clearTimeout(c)}},[l]),{storyboard:t,state:a}}const Rc=e=>e?.frames.find(t=>t.kind==="poster")??e?.frames[0]??null;function uu(e){try{const t=new URL(e.url);return(t.protocol==="http:"||t.protocol==="https:")&&t.origin===e.origin?t.href:null}catch{return null}}const XE=2e4,ZE=new Set(["compositionMissing","compositionInvalid","baseNotAllowed"]),JE=1/60,xd=20,YE=e=>Math.min(qv,Math.max(_v,Number.isFinite(e)?e:1)),QE=e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>e()):setTimeout(e,16)};class eT{events=new EventTarget;active=null;incoming=null;awaitingPlay=!1;time=0;dur=Number.NaN;isPaused=!0;rate=1;defaultPlaybackRate=1;loop=!1;isMuted=!1;error=null;draft=null;sessionMedia=new Map;seq=0;subtitles=void 0;sentSeq=-1;flushQueued=!1;applied=null;selectedId=null;clipBounds=null;get currentTime(){return this.time}set currentTime(t){if(!Number.isFinite(t))return;const n=Number.isFinite(this.dur)?this.dur:Number.POSITIVE_INFINITY;this.time=Math.min(n,Math.max(0,t)),this.post({type:"seek",t:this.time}),this.isPaused||this.post(this.playCommand())}get duration(){return this.dur}get muted(){return this.isMuted}set muted(t){t!==this.isMuted&&(this.isMuted=t,this.post({type:"mute",muted:t}))}get paused(){return this.isPaused}get playbackRate(){return this.rate}set playbackRate(t){this.rate=YE(t),this.isPaused||this.post(this.playCommand())}play(){return this.error?Promise.reject(this.error):(this.isPaused&&(this.isPaused=!1,this.post(this.playCommand()),this.emit("play")),Promise.resolve())}pause(){this.isPaused||(this.isPaused=!0,this.post({type:"pause"}),this.emit("pause"))}setComposition(t){return this.seq=this.seq>=Vv?1:this.seq+1,this.draft={composition:t,seq:this.seq},this.flushQueued||(this.flushQueued=!0,QE(()=>{this.flushQueued=!1,this.flushDraft()})),this.seq}setSubtitles(t){this.subtitles=t,this.post({type:"setSubtitles",subtitles:t})}clearSubtitles(){this.subtitles=void 0}select(t){this.selectedId=t,t===null&&this.clipBounds?.clipId&&(this.clipBounds={...this.clipBounds,clipId:null,bounds:null},this.emit("clipbounds")),this.post({type:"select",clipId:t})}clearDraft(){this.draft=null,this.sessionMedia.clear()}addSessionMedia(t,n){const a={type:"sessionMedia",src:t,...n};return!this.active||!Zf(a)?!1:(this.sessionMedia.set(t,{token:Yf(this.active.id),cmd:a}),this.post(a),!0)}addEventListener(t,n){this.events.addEventListener(t,n)}removeEventListener(t,n){this.events.removeEventListener(t,n)}expect(t,n){this.incoming={id:t,send:n}}release(t){this.active?.id===t&&(this.active=null),this.incoming?.id===t&&(this.incoming=null)}counts(t){return this.active?this.active.id===t:this.incoming?.id===t}detach(){this.active=null,this.incoming=null}receive(t,n){if(t.type==="ready"){if(this.incoming?.id!==n)return!1;const r=this.active;this.active=this.incoming,this.incoming=null,r&&r.id!==n&&r.send({type:"pause"}),this.dur=t.duration,this.error=null,this.isMuted&&this.post({type:"mute",muted:!0}),this.time>0&&this.post({type:"seek",t:Math.min(this.time,t.duration)}),this.sentSeq=-1;const l=Yf(n);for(const[o,c]of this.sessionMedia)c.token!==l?this.sessionMedia.delete(o):this.post(c.cmd);return this.selectedId!==null&&this.post({type:"select",clipId:this.selectedId}),this.subtitles!==void 0&&this.post({type:"setSubtitles",subtitles:this.subtitles}),this.flushDraft(),this.isPaused||this.post(this.playCommand()),this.emit("loadedmetadata"),this.emit("durationchange"),!0}if(t.type==="error")return this.active===null&&this.incoming?.id===n&&ZE.has(t.error.code)&&(this.error=t.error,this.isPaused=!0,this.emit("error")),!1;if(t.type==="compositionApplied"){if(this.active?.id!==n)return!1;if(this.applied={seq:t.seq,errors:t.errors},!t.errors.some(l=>l.code==="compositionInvalid")&&this.draft&&t.seq===this.draft.seq){const l=this.draft.composition.duration>0?this.draft.composition.duration:0;l!==this.dur&&(this.dur=l,this.emit("durationchange"))}return this.emit("compositionapplied"),!1}if(t.type==="clipBounds")return this.active?.id!==n||(this.clipBounds={clipId:t.clipId,bounds:t.bounds,scale:t.scale},this.emit("clipbounds")),!1;if(t.type!=="time"||this.active?.id!==n||(t.playing&&(this.awaitingPlay=!1),t.playing&&this.isPaused))return!1;const a=!t.playing&&!this.isPaused&&!this.awaitingPlay&&Number.isFinite(this.dur)&&t.t>=this.dur-JE;return this.time=t.t,this.emit("timeupdate"),a&&(this.isPaused=!0,this.emit("pause"),this.emit("ended")),!1}flushDraft(){if(!this.draft||!this.active||this.draft.seq===this.sentSeq)return;const{composition:t,seq:n}=this.draft;this.sentSeq=n,this.post({type:"setComposition",composition:t,keepTime:!0,seq:n})||(this.applied={seq:n,errors:[{code:"compositionInvalid",message:"the draft was refused by the preview protocol (structure or size)"}]},this.emit("compositionapplied"))}playCommand(){return{type:"play",loop:this.loop,rate:this.rate}}post(t){return!this.active||!Zf(t,BE)?!1:(t.type==="play"&&(this.awaitingPlay=!0),this.active.send(t),!0)}emit(t){this.events.dispatchEvent(new Event(t))}}function Yf(e){try{return new URL(e).pathname.split("/")[1]||e}catch{return e}}function di({session:e,title:t,onMedia:n,onStall:a,onShowing:r,autoPlay:l,muted:o=!1,subtitles:c,className:d}){const u=V().web.render,[h]=i.useState(()=>new eT),[f,x]=i.useState([]),[p,g]=i.useState(null),b=uu(e),v=i.useRef({onMedia:n,onStall:a,onShowing:r});if(v.current={onMedia:n,onStall:a,onShowing:r},i.useEffect(()=>(v.current.onMedia?.(h),()=>{h.pause(),h.detach(),v.current.onMedia?.(null),v.current.onShowing?.(null)}),[h]),i.useEffect(()=>{h.muted=o},[o,h]),i.useEffect(()=>{c!==void 0?h.setSubtitles(c):h.clearSubtitles()},[c,h]),i.useEffect(()=>{l&&(h.loop=!0,h.play().catch(()=>{}))},[l,h]),!b)return s.jsx("div",{className:le("ms-cplayer",d),children:s.jsx("p",{className:"ms-cplayer-note",role:"alert",children:u.failed({detail:e.url})})});const y=p?uu(p):null,w=[];p&&y&&y!==b&&w.push({s:p,u:y,next:!1}),w.push({s:e,u:b,next:w.length>0});const j=S=>{const k=u.runtimeError[S.code]??S.code;return S.clipId?u.errorClip({text:k,clip:S.clipId}):k};return s.jsxs("div",{className:le("ms-cplayer",d),children:[w.map(S=>s.jsx(sT,{url:S.u,session:S.s,title:t,media:h,next:S.next,onReady:k=>{g(S.s),x(k.slice(0,xd)),v.current.onShowing?.(S.s.token)},onError:k=>x(E=>E.length>=xd?E:[...E,k]),onApplied:k=>x(k.slice(0,xd)),onStall:()=>v.current.onStall?.()},S.u)),f.length?s.jsx("ul",{className:"ms-cplayer-errors",role:"status","aria-label":u.runtimeIssues,children:[...new Set(f.map(j))].map(S=>s.jsx("li",{children:S},S))}):null]})}function sT({url:e,session:t,title:n,media:a,next:r,onReady:l,onError:o,onApplied:c,onStall:d}){const m=i.useRef(null),u=i.useRef({onReady:l,onError:o,onApplied:c,onStall:d});return u.current={onReady:l,onError:o,onApplied:c,onStall:d},i.useEffect(()=>{const h=m.current;if(!h)return;let f=!1;a.expect(e,g=>{h.contentWindow?.postMessage(g,"*")});const x=g=>{if(!h.contentWindow||g.source!==h.contentWindow||g.origin!=="null"&&g.origin!==t.origin)return;const b=OE(g.data);b&&(b.type==="error"&&a.counts(e)&&u.current.onError(b.error),b.type==="compositionApplied"&&a.counts(e)&&u.current.onApplied(b.errors),a.receive(b,e)&&b.type==="ready"&&(f=!0,u.current.onReady(b.errors)))};window.addEventListener("message",x);const p=window.setTimeout(()=>{f||u.current.onStall()},XE);return()=>{window.removeEventListener("message",x),window.clearTimeout(p),a.release(e)}},[e,t.origin,a]),s.jsx("iframe",{ref:m,className:le("ms-cplayer-frame",r&&"ms-next"),src:e,title:n,sandbox:"allow-scripts",referrerPolicy:"no-referrer",allow:"autoplay",...r?{"aria-hidden":!0,tabIndex:-1}:{}})}const tT=170,nT=96,aT=450;function hr(e,t){return xn(e.preset,e.id,t,e.labels)}function rT(e,t){const n=/^(\d+) · /.exec(e.labels?.[e.id]??"");return n?n[1]:hr(e,t)}function nr(e,t){return e.preset?`${Dn(e.preset.channel,t)} · ${hr(e,t)}`:e.id}function Qf(e){const t=V(),n=t.web.canvas,a=rs(),{n:r}=e,l=e.inProgress?{...e.board,out:null}:e.board,o=i.useRef(null),c=nr(l,a),d=gc(l),m=e.zoom,u=d.width*m<tT,h=e.draft!==null&&e.draft.format===l.id,f=(I,H)=>{const de=F0({x:I*d.width,y:H*d.height},m);return{left:`${de.x}px`,top:`${de.y}px`}},x=e.composition??null,{storyboard:p}=ci({slug:e.slug,creative:e.creative,n:x?.n??null,format:x?.format??l.id,hash:x?.hash??null,enabled:x!==null}),g=Rc(p),b=g?{src:g.url,video:!1}:l.out&&r!==null?Nr(e.slug,e.creative,r,l.out):null,v=l.out!==null||x!==null,[y,w]=i.useState(!1),[j,S]=i.useState(!1),k=i.useRef(0);i.useEffect(()=>()=>window.clearTimeout(k.current),[]),i.useEffect(()=>{e.tool!=="select"&&(S(!1),w(!1))},[e.tool]);const E=l.preset?.kind==="image",N=e.card&&!E&&l.out&&r!==null&&tr(l.out.file)?Da(e.slug,e.creative,r,l.out.file):null,C=N!==null&&e.tool==="select"&&y,R=x!==null&&N===null&&!E&&e.tool==="select"&&(y||j),P=el({slug:e.slug,creative:e.creative,n:x?.n??null,format:x?.format??l.id,enabled:R}),z=()=>{(x||N)&&e.tool==="select"&&(window.clearTimeout(k.current),k.current=window.setTimeout(()=>w(!0),aT))},O=()=>{window.clearTimeout(k.current),w(!1)},T=l.preset?.kind==="video",W=l.out?.durationSec??null,Z=l.out?.warnings?.filter(I=>I.key==="outputs.largeFile")??[],A=I=>{qn(I.currentTarget,[{opacity:0,filter:"blur(8px)"},{opacity:1,filter:"blur(0)"}],qs.l,Vt.out)},L=I=>{const H=xm(I.currentTarget.getBoundingClientRect(),I);e.onPlace(H.x,H.y)},_=e.card?Math.max(Math.round(d.width*m),nT):Math.max(Math.round(d.width*m),um(m,e.boardKey!==void 0||e.tag!==void 0||e.grouped)),X=!e.card&&_<dm,ae=x&&(x.render.kind=="queued"||x.render.kind==="rendering"||x.render.kind==="failed"||x.render.kind==="problem"),K=!e.card||e.rendering||e.inProgress||e.note||ae||l.out&&!l.out.verified||Z.length>0;return s.jsxs("div",{className:le("ms-cv-board",e.card&&"ms-cv-card-board",e.selected&&"ms-on",h&&"ms-drafting"),"data-board":e.boardKey??l.id,children:[s.jsxs("div",{className:le("ms-cv-board-head",X&&"ms-narrow-head"),style:e.card?{width:_}:{maxWidth:_},children:[e.from?s.jsx("div",{className:"ms-cv-board-line ms-cv-board-from",children:e.from}):null,s.jsxs("div",{className:"ms-cv-board-line",children:[l.preset?s.jsx(en,{channel:da(l.preset.channel)}):null,e.tag?s.jsx("span",{className:"ms-cv-board-tag","aria-hidden":"true",children:e.tag}):null,s.jsx("b",{className:"ms-cv-board-name",title:c,children:l.preset?X?rT(l,a):hr(l,a):c}),s.jsx("span",{className:"ms-cv-board-slot",children:e.badge})]}),K?s.jsxs("div",{className:"ms-cv-board-line ms-cv-board-sub",children:[l.preset&&!e.card?s.jsxs("span",{className:"ms-cv-board-meta",children:[pm(l.preset),W!==null?` · ${n.seconds({n:Vs(a,W,{maximumFractionDigits:1})})}`:""]}):null,e.inProgress?s.jsx("span",{className:"ms-cv-board-state ms-cv-wip",children:n.inProgress}):e.rendering?s.jsx("span",{className:"ms-cv-board-state",children:n.renderingState}):e.note?s.jsx("span",{className:"ms-cv-board-state",children:e.note}):x&&(!e.card||ae)?s.jsx(lT,{render:x.render,label:c,onRender:x.onRender}):!e.card&&l.out&&l.out.verified&&!Z.length?s.jsx("span",{className:"ms-cv-board-state",children:n.boardReady}):null,!e.rendering&&l.out&&!l.out.verified?s.jsx(Qs,{tone:"warn",children:t.web.formatUi.unverified}):null,Z.map((I,H)=>s.jsx(oT,{warning:I},H))]}):null]}),s.jsxs("div",{className:le("ms-cv-frame-wrap",u&&"ms-narrow"),style:{width:d.width*m,height:d.height*m},onPointerEnter:z,onPointerLeave:O,children:[s.jsxs("div",{ref:o,className:le("ms-cv-frame",!v&&"ms-empty-frame"),style:{width:d.width,height:d.height,zoom:m},"data-frame":l.id,onClick:()=>{e.card&&v&&o.current?e.onOpen(o.current):e.onSelect()},onDoubleClick:()=>{!e.card&&v&&o.current&&e.onOpen(o.current)},children:[b&&r!==null?b.video?s.jsx("video",{src:b.src,muted:!0,playsInline:!0,preload:"metadata","aria-label":`${c} v${r}`,onLoadedData:A},b.src):s.jsx("img",{src:b.src,alt:`${c} v${r}`,onLoad:A,draggable:!1},b.src):x?null:s.jsx("span",{className:"ms-cv-frame-note",children:l.preset?r!==null?t.web.formatUi.missingIn({n:r}):e.missing?t.web.formatUi.missingIn({n:e.missing}):n.notGenerated:t.web.formatUi.unknownPreset({id:l.id})}),R&&P.state.kind==="ready"?s.jsx(di,{session:P.state.session,title:t.web.render.playerFrame({label:`${c} v${x.n}`}),autoPlay:!0,className:"ms-cv-live-player",onStall:P.stalled,onShowing:P.showing,...e.card?{muted:!0}:{}}):null,C?s.jsx("video",{className:"ms-cv-live-file",src:N,muted:!0,autoPlay:!0,loop:!0,playsInline:!0,"aria-hidden":"true"},N):null,e.rendering?s.jsx("span",{className:"ms-shimmer","aria-hidden":"true"}):null,e.tool==="comment"&&v&&e.commentable!==!1?s.jsx("button",{type:"button",className:"ms-cv-hit","aria-label":n.commentOn({label:c}),onClick:I=>{I.stopPropagation(),L(I)}}):null]}),R&&(P.state.kind==="loading"||P.state.kind==="busy")?s.jsx("span",{className:"ms-cplayer-state",role:"status",children:P.state.kind==="busy"?t.web.render.busy:t.web.render.loading}):null,x&&!E&&e.tool==="select"?s.jsx("button",{type:"button",className:le("ms-cv-live",j&&"ms-on"),"aria-pressed":j,"aria-label":j?t.web.render.stopPreview({label:c}):t.web.render.playPreview({label:c}),title:j?t.web.render.stopPreview({label:c}):t.web.render.playPreview({label:c}),onClick:I=>{I.stopPropagation(),S(H=>!H)},onDoubleClick:I=>I.stopPropagation(),children:s.jsx(F,{name:j?"pause":"play",size:12,fill:!j})}):null,e.onComment&&e.tool==="select"&&v?s.jsx("button",{type:"button",className:"ms-cv-comment-btn","aria-label":n.commentStart({label:c}),title:n.commentStart({label:c}),onClick:I=>{I.stopPropagation(),e.onComment()},onDoubleClick:I=>I.stopPropagation(),children:s.jsx(F,{name:"comment",size:13,strokeWidth:1.6})}):null,e.tool==="select"&&v?s.jsxs("button",{type:"button",className:"ms-cv-open","aria-label":n.openEditorOf({label:c}),onClick:I=>{I.stopPropagation(),o.current&&e.onOpen(o.current)},onDoubleClick:I=>I.stopPropagation(),children:[s.jsx(F,{name:l.preset?.kind==="image"?"image":"video",size:14,strokeWidth:1.6}),s.jsx("span",{className:"ms-cv-open-text",children:n.openEditor})]}):null,e.pins.map(({pin:I,number:H})=>s.jsx("button",{type:"button",className:le("ms-cv-pin",e.draft?.index===H-1&&"ms-on"),style:f(I.x,I.y),"aria-label":n.pin.edit({n:H}),title:I.note,onClick:de=>{de.stopPropagation(),e.onEditPin(H)},children:H},H)),e.draft&&e.draft.format===l.id?s.jsx(Yv,{draft:e.draft,number:e.draft.index===null?e.nextNumber:e.draft.index+1,video:T,at:f(e.draft.x,e.draft.y),onText:e.onDraftText,onCommit:e.onDraftCommit,onCancel:e.onDraftCancel,onDelete:e.onDraftDelete}):null]})]})}function lT({render:e,label:t,onRender:n}){const a=V().web.render;switch(e.kind){case"queued":return s.jsx("span",{className:"ms-cv-board-state",children:e.ahead?a.queuedAhead({count:e.ahead}):a.queued});case"rendering":return s.jsx("span",{className:"ms-cv-board-state",children:a.rendering({pct:e.pct})});case"rendered":return s.jsx("span",{className:"ms-cv-board-state",children:a.rendered});case"problem":return s.jsx(iT,{problems:e.problems,label:t,onRender:n});case"failed":return s.jsxs("span",{className:"ms-cv-board-state ms-cv-render-failed",title:e.error??void 0,children:[a.failedState," · ",s.jsx("button",{type:"button",className:"ms-cv-retry","aria-label":a.retryRenderOf({label:t}),onClick:r=>{r.stopPropagation(),n()},children:a.retryRender})]});default:return null}}function iT({problems:e,label:t,onRender:n}){const a=V(),r=a.web.render,l=i.useRef(null),[o,c]=i.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsxs("button",{ref:l,type:"button",className:"ms-pill ms-warn ms-cv-large ms-cv-render-problem","aria-haspopup":"dialog","aria-expanded":o,"aria-label":r.problemOpen({label:t}),title:Tg(e,a).join(`
|
|
15
|
+
`),onClick:d=>{d.stopPropagation(),c(m=>!m)},children:[s.jsx(F,{name:"warn",size:11}),r.problemState({count:e.length})]}),s.jsx(ot,{open:o,onClose:()=>c(!1),anchor:l,placement:"bottom-start",width:320,label:r.problemTitle,children:s.jsxs("div",{className:"ms-cv-large-pop",children:[s.jsx("b",{children:r.problemTitle}),s.jsx(im,{className:"ms-cv-problem-list",problems:e}),s.jsx("p",{children:r.problemHint}),s.jsx($,{variant:"outline","aria-label":r.renderAgainOf({label:t}),onClick:d=>{d.stopPropagation(),c(!1),n()},children:r.renderAgain})]})})]})}function oT({warning:e}){const n=V().web.canvas,a=rs(),r=i.useRef(null),[l,o]=i.useState(!1),c=Number(e.params.sizeMB),d=Number.isFinite(c)?Vs(a,c,{maximumFractionDigits:0}):null,m=dx(e,a),u=(b,v)=>{const y=Number(e.params[b]);return Number.isFinite(y)?Vs(a,y,{maximumFractionDigits:v}):null},[h,f,x]=[u("sizeMB",1),u("mbps",1),u("targetMbps",1)],p=typeof e.params.channel=="string"?e.params.channel:null,g=h!==null&&f!==null&&x!==null&&p!==null?n.largeDetail({size:h,mbps:f,target:x,channel:p}):m;return s.jsxs(s.Fragment,{children:[s.jsxs("button",{ref:r,type:"button",className:"ms-pill ms-warn ms-cv-large","aria-haspopup":"dialog","aria-expanded":l,"aria-label":d!==null?n.largeOpen({size:d}):n.largeTitle,title:m,onClick:b=>{b.stopPropagation(),o(v=>!v)},children:[s.jsx(F,{name:"warn",size:11}),d!==null?n.largeChip({size:d}):n.largeTitle]}),s.jsx(ot,{open:l,onClose:()=>o(!1),anchor:r,placement:"bottom-start",width:300,label:n.largeTitle,children:s.jsxs("div",{className:"ms-cv-large-pop",children:[s.jsx("b",{children:n.largeTitle}),s.jsx("p",{children:g})]})})]})}function Jv({preset:e}){const t=V().web.canvas,n=e.safeZone;if(!n)return null;const a=o=>({...o,position:"absolute"}),r=`${n.top/e.height*100}%`,l=`${n.bottom/e.height*100}%`;return s.jsxs("span",{className:"ms-cv-safe","aria-hidden":"true",children:[n.top>0?s.jsx("i",{className:"ms-cv-safe-top",style:a({height:r}),children:s.jsx("em",{children:t.safeTop})}):null,n.bottom>0?s.jsx("i",{className:"ms-cv-safe-bottom",style:a({height:l}),children:s.jsx("em",{children:t.safeBottom})}):null,n.left>0?s.jsx("i",{className:"ms-cv-safe-left",style:a({width:`${n.left/e.width*100}%`,top:r,bottom:l})}):null,n.right>0?s.jsx("i",{className:"ms-cv-safe-right",style:a({width:`${n.right/e.width*100}%`,top:r,bottom:l})}):null]})}function Yv({draft:e,number:t,video:n,time:a,at:r,onText:l,onCommit:o,onCancel:c,onDelete:d}){const m=V(),u=m.web.canvas.pin,h=i.useRef(null),f=i.useRef(null),[x]=i.useState(()=>`${e.format}:${e.index}`);i.useLayoutEffect(()=>{qn(h.current,[{opacity:0,transform:"scale(.92) translateY(4px)"},{opacity:1,transform:"none"}],qs.s,Vt.spring);const w=f.current;w&&(w.focus({preventScroll:!0}),w.setSelectionRange(w.value.length,w.value.length))},[x]);const[p,g]=i.useState(e.x>.55);i.useLayoutEffect(()=>{const w=h.current,j=()=>{const E=w?.closest(".ms-cv-viewport, .ms-fv-stage")?.getBoundingClientRect(),N=w?.parentElement?.getBoundingClientRect();if(!w||!E||!N||!E.width)return;const C=N.left+e.x*N.width,R=E.right-C;g(R<w.offsetWidth+40&&C-E.left>R)};j();const S=w?.parentElement;if(!S||typeof ResizeObserver>"u")return;const k=new ResizeObserver(j);return k.observe(S),()=>k.disconnect()},[e.x,e.format,r?.left,r?.top]);const b=!e.text.trim(),v=r??{left:`${e.x*100}%`,top:`${e.y*100}%`},y=w=>{if(w.key==="Escape"){w.preventDefault(),w.stopPropagation(),c();return}dc(w.nativeEvent)&&!w.repeat&&(w.preventDefault(),b||o())};return s.jsxs(s.Fragment,{children:[e.index===null?s.jsx("span",{className:"ms-cv-pin ms-draft",style:v,"aria-hidden":"true",children:t}):null,s.jsxs("div",{ref:h,className:le("ms-cv-bubble",p&&"ms-left"),style:v,role:"group","aria-label":u.marker({n:t}),onClick:w=>w.stopPropagation(),onDoubleClick:w=>w.stopPropagation(),children:[s.jsx(nn,{ref:f,rows:3,maxLength:2e3,"aria-label":u.field,placeholder:u.placeholder,value:e.text,onChange:w=>l(w.target.value),onKeyDown:y}),s.jsxs("div",{className:"ms-cv-bubble-foot",children:[a!==void 0?s.jsx("span",{className:"ms-cv-bubble-time",children:a}):n?s.jsx("span",{className:"ms-cv-bubble-time",title:u.atStartHint,children:u.atStart}):null,s.jsx("span",{className:"ms-grow"}),e.index!==null?s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":u.remove,title:u.remove,onClick:d,children:s.jsx(F,{name:"trash",size:13})}):null,s.jsx($,{size:"sm",variant:"ghost",onClick:c,children:m.common.cancel}),s.jsx($,{size:"sm",variant:"ink",disabled:b,onClick:o,children:e.index===null?u.add:u.save})]})]})]})}function Lm(){let e={time:0,settled:0};const t=new Set;return{get:()=>e,set(n,a){if(!(e.time===n&&(!a||e.settled===n))){e={time:n,settled:a?n:e.settled};for(const r of t)r()}},subscribe(n){return t.add(n),()=>{t.delete(n)}}}}const Jn=e=>i.useSyncExternalStore(e.subscribe,e.get,e.get),mu=1/30,cT=250,gd=mu/2,ep=.001,Ta=[0,1],hu=e=>Number.isFinite(e)&&e>0;function Qv(e,t,n){return Math.max(0,...Ta.filter(a=>e[a]&&!t[a]).map(n))}function dT(e,t){const n=[Number.NaN,Number.NaN],a=[!1,!1];let r=!1,l=0,o=Number.NEGATIVE_INFINITY,c=0,d=!0;const m=T=>hu(n[T])?n[T]:t.hint(T),u=T=>e[T]!==null&&!a[T],h=()=>Qv([e[0]!==null,e[1]!==null],a,m),f=(T,W)=>{const Z=m(T);return Z>0&&W>=Z-gd},x=()=>Ta.filter(u).reduce((T,W)=>T===null||m(W)>m(T)?W:T,null),p=()=>Ta.find(T=>u(T)&&!f(T,l))??x(),g=()=>{const T=p();return T!==null&&(l=e[T].currentTime),T},b=(T,W)=>{const Z=e[T],A=m(T),L=A>0&&W>=A-gd;if(L){const _=Math.max(0,A-ep);Math.abs(Z.currentTime-_)>ep&&(Z.currentTime=_),Z.paused||Z.pause()}else Z.currentTime!==W&&(Z.currentTime=W);return!L},v=T=>{const W=e[T];if(!W.paused)return;const Z=W.play();Z&&typeof Z.catch=="function"&&Z.catch(()=>{d&&r&&k()})},y=()=>{c=0,!(!d||!r)&&(g(),t.clock.set(l,!1),c=requestAnimationFrame(y))},w=T=>{r!==T&&(r=T,t.onPlaying(T),T&&!c&&(c=requestAnimationFrame(y)),!T&&c&&(cancelAnimationFrame(c),c=0))};function j(T){const W=h(),Z=Math.max(0,W?Math.min(W,T):T);l=Z,o=t.now();for(const A of Ta)u(A)&&b(A,Z)&&r&&v(A);t.clock.set(Z,!0)}function S(){if(r||!Ta.some(u))return;const T=h();if(T&&l>=T-gd)j(0);else for(const W of Ta)u(W)&&b(W,l);w(!0);for(const W of Ta)u(W)&&!f(W,l)&&v(W)}function k(){for(const T of e)T&&!T.paused&&T.pause();g(),w(!1),t.clock.set(l,!0)}const E=()=>{if(t.loop()){j(0);return}for(const T of e)T&&!T.paused&&T.pause();l=h(),w(!1),t.clock.set(l,!0)},N=T=>()=>{if(!r)return;const W=g();for(const Z of Ta)Z!==W&&u(Z)&&f(Z,l)&&b(Z,l);if(T===0&&W===0&&u(1)&&!f(1,l)){const Z=e[1],A=t.now();Math.abs(Z.currentTime-l)>mu&&A-o>=cT&&(Z.currentTime=l,o=A)}t.clock.set(l,!0)},C=T=>()=>{if(!r)return;g();const W=T===0?1:0;u(W)&&!f(W,l)||E()},R=T=>()=>{const W=e[T];n[T]=W.duration,W.defaultPlaybackRate=t.rate(),W.playbackRate=t.rate(),t.onMeta([...n])},P=T=>()=>{a[T]||(a[T]=!0,t.onFailed([...a]),r&&!Ta.some(W=>u(W)&&!f(W,l))&&k())},z=[];for(const T of Ta){const W=e[T];if(!W)continue;const Z=(A,L)=>{W.addEventListener(A,L),z.push([W,A,L])};Z("timeupdate",N(T)),Z("ended",C(T)),Z("loadedmetadata",R(T)),Z("durationchange",R(T)),Z("error",P(T)),hu(W.duration)&&(n[T]=W.duration),W.error&&(a[T]=!0),W.paused||W.pause(),W.currentTime!==0&&(W.currentTime=0)}t.onMeta([...n]),t.onFailed([...a]);const O={play:S,pause:k,seek:j,step(T){r&&k(),j(Math.round((l+T*mu)*30)/30)},isPlaying:()=>r,applyRate(){for(const T of e)T&&(T.defaultPlaybackRate=t.rate(),T.playbackRate=t.rate())},dispose(){d=!1;for(const[T,W,Z]of z)T.removeEventListener(W,Z);c&&cancelAnimationFrame(c),c=0}};return O.applyRate(),O}function uT(e,t,n={}){const[a]=i.useState(Lm),[r,l]=i.useState(!1),[o,c]=i.useState([Number.NaN,Number.NaN]),[d,m]=i.useState([!1,!1]),u=i.useRef(n);u.current=n;const h=i.useRef(null);i.useEffect(()=>{const j=dT([e,t],{clock:a,now:()=>(u.current.now??(()=>performance.now()))(),hint:S=>u.current.durations?.[S]??0,rate:()=>u.current.rate??1,loop:()=>!!u.current.loop,onPlaying:l,onMeta:S=>c(k=>Object.is(k[0],S[0])&&Object.is(k[1],S[1])?k:S),onFailed:S=>m(k=>k[0]===S[0]&&k[1]===S[1]?k:S)});return h.current=j,l(!1),a.set(0,!0),()=>{j.dispose(),h.current===j&&(h.current=null)}},[e,t,a]);const f=n.rate??1;i.useEffect(()=>{h.current?.applyRate()},[f,e,t]);const x=n.durations,p=Qv([e!==null,t!==null],d,j=>hu(o[j])?o[j]:x?.[j]??0),g=i.useCallback(()=>h.current?.play(),[]),b=i.useCallback(()=>h.current?.pause(),[]),v=i.useCallback(()=>{const j=h.current;j&&(j.isPlaying()?j.pause():j.play())},[]),y=i.useCallback(j=>h.current?.seek(j),[]),w=i.useCallback(j=>h.current?.step(j),[]);return i.useMemo(()=>({clock:a,playing:r,duration:p,failed:d,play:g,pause:b,toggle:v,seek:y,step:w}),[a,r,p,d,g,b,v,y,w])}const jr=e=>!!(e.target instanceof Element?e.target:null)?.closest('input, textarea, select, [contenteditable=""], [contenteditable="true"]'),pr=e=>!!(e.target instanceof Element?e.target:null)?.closest(".ms-modal, .ms-pop"),ui=e=>!e.metaKey&&!e.ctrlKey&&!e.altKey&&!e.isComposing,za=(e,t)=>{if(e.key!==" "&&e.code!=="Space"&&e.key!=="Enter")return!1;const a=(e.target instanceof Element?e.target:null)?.closest('button, a[href], [role="button"], [role="tab"], [role="menuitem"], [role="option"], [role="switch"], [role="checkbox"], [role="radio"]');return!!(a&&!(t&&a.closest(t)))},mT=e=>e.scrollHeight>e.clientHeight+1;function hT({text:e,className:t}){const a=V().web.canvas.versions,r=i.useRef(null),[l,o]=i.useState(!1),[c,d]=i.useState(!1);return i.useLayoutEffect(()=>{o(!1);const m=r.current;if(!m)return;const u=()=>d(mT(m));if(u(),typeof ResizeObserver>"u")return;const h=new ResizeObserver(u);return h.observe(m),()=>h.disconnect()},[e]),s.jsxs("span",{className:le("ms-reqnote",t),children:[s.jsx("span",{ref:r,className:le("ms-reqnote-text",!l&&"ms-clamp2"),title:c&&!l?e:void 0,children:e}),c||l?s.jsx($,{size:"sm",variant:"ghost",className:"ms-reqnote-more","aria-expanded":l,onClick:()=>o(m=>!m),children:l?a.noteLess:a.noteMore}):null]})}const El=30,Wo=".ms-fv-play, .ms-fv-scrub",Za=e=>Math.round(e*1e3)/1e3;function wt(e){const t=Math.max(0,e),n=Math.floor(Za(t)*100+1e-6),a=Math.floor(n/6e3),r=Math.floor(n%6e3/100);return`${String(a).padStart(2,"0")}:${String(r).padStart(2,"0")}.${String(n%100).padStart(2,"0")}`}function fT(e,t,n){return Math.min(e-8-t/2,Math.max(8+t/2,16+(e-32)*n))}const eb=["0.5","1","1.5","2"];function sb({clock:e,duration:t,playing:n,disabled:a,marks:r=[],onRange:l,onBand:o,blocked:c,extra:d,hint:m,onToggle:u,onStep:h,onSeek:f,onPause:x,onResume:p,loop:g,onLoop:b,speed:v,onSpeed:y}){const w=V(),j=w.web.formatView,S=rs(),{time:k,settled:E}=Jn(e),N=i.useRef(null),C=i.useRef(null),[R,P]=i.useState(null),[z,O]=i.useState(null),T=i.useRef(null),W=i.useRef(null),Z=i.useRef(null),A=w.web.conversation,L=()=>{C.current=null,P(null),O(null)};i.useEffect(()=>{(a||!l||c)&&(P(null),O(null))},[a,l,c]),i.useEffect(()=>{if(!R&&!z)return;const re=oe=>{if(oe.key!=="Escape"||oe.defaultPrevented||(oe.target instanceof Element?oe.target:null)?.closest('[role="dialog"], [aria-modal="true"], dialog, .ms-pop, .ms-modal, input, textarea, select, [contenteditable]:not([contenteditable="false"])'))return;const Q=z!==null&&document.activeElement===T.current;L(),Q&&N.current?.focus()};return window.addEventListener("keydown",re),()=>window.removeEventListener("keydown",re)},[R,z]),i.useEffect(()=>{z&&T.current?.focus()},[z]);const _=re=>t?Math.min(100,Math.max(0,re/t*100)):0,X=re=>{const oe=N.current?.getBoundingClientRect();return!oe||!oe.width||!t?null:Math.min(t,Math.max(0,(re-oe.left)/oe.width*t))},ae=re=>{if(a||c||re.button!==0)return;re.currentTarget.setPointerCapture?.(re.pointerId),O(null);const oe=!!re.target.closest?.(".ms-fv-ruler");if(l&&(re.shiftKey||oe)){const Q=X(re.clientX);if(Q===null)return;C.current={resume:n,from:Q,px:re.clientX,ruler:oe&&!re.shiftKey},n&&x(),P({a:Q,b:Q});return}C.current={resume:n},n&&x();const Ne=X(re.clientX);Ne!==null&&f(Ne)},K=re=>{if(!C.current)return;const oe=X(re.clientX);if(C.current.from!==void 0){oe!==null&&P({a:C.current.from,b:oe});return}oe!==null&&f(oe)},I=re=>{const oe=C.current;if(C.current=null,oe?.from!==void 0){const Ne=re.type==="pointerup"?X(re.clientX)??oe.from:oe.from;if(P(null),re.type!=="pointerup"){oe.resume&&p();return}if(oe.ruler&&(Math.abs(re.clientX-(oe.px??re.clientX))<3||Math.abs(Ne-oe.from)<Zl)){f(Ne),oe.resume&&p();return}Math.abs(Ne-oe.from)>=Zl?O({start:Math.min(Ne,oe.from),end:Math.max(Ne,oe.from)}):oe.resume&&p();return}oe?.resume&&p()},H=re=>{a||(re.key==="Home"&&(re.preventDefault(),f(0)),re.key==="End"&&(re.preventDefault(),f(t)),(re.key==="PageUp"||re.key==="PageDown")&&(re.preventDefault(),f(e.get().time+(re.key==="PageUp"?1:-1))))},de=R?`${R.a}:${R.b}`:z?`${z.start}:${z.end}`:"",J=R?{start:Math.min(R.a,R.b),end:Math.max(R.a,R.b)}:z,se=J!==null,U=i.useRef(o);U.current=o,i.useEffect(()=>{if(se)return U.current?.(!0),()=>U.current?.(!1)},[se]),i.useLayoutEffect(()=>{const re=W.current,oe=Z.current;if(!re||!oe||!J)return;const Ne=re.offsetWidth,Q=oe.clientWidth;!Ne||!Q||(re.style.left=`${fT(Q,Ne,_((J.start+J.end)/2)/100)}px`)},[de,z!==null]);const te=[1,2,5,10,15,30,60,120,300].find(re=>t/re<=10)??600,G=t?Array.from({length:Math.floor(t/te+1e-6)+1},(re,oe)=>oe*te).filter(re=>re/t<=.94):[];return s.jsxs("section",{ref:Z,className:le("ms-fv-transport",se&&"ms-banded"),"aria-label":j.transport,"data-part":"b",children:[s.jsxs("div",{className:"ms-fv-controls",children:[s.jsx("button",{type:"button",className:"ms-fv-play","aria-label":n?j.pause:j.play,"aria-keyshortcuts":"Space",disabled:a,onClick:u,children:s.jsx(F,{name:n?"pause":"play",size:13,fill:!n,strokeWidth:n?2:1.4})}),s.jsxs("span",{className:"ms-fv-tc",children:[wt(k),s.jsxs("span",{className:"ms-faint",children:[" / ",wt(t)]})]}),s.jsx($,{size:"sm",variant:"outline",icon:!0,"aria-label":j.prevFrame,title:j.prevFrame,"aria-keyshortcuts":"ArrowLeft",disabled:a,onClick:()=>h(-1),children:s.jsx(F,{name:"back",size:13})}),s.jsx($,{size:"sm",variant:"outline",icon:!0,"aria-label":j.nextFrame,title:j.nextFrame,"aria-keyshortcuts":"ArrowRight",disabled:a,onClick:()=>h(1),children:s.jsx(F,{name:"forward",size:13})}),s.jsx("span",{className:"ms-fv-sep","aria-hidden":"true"}),s.jsx($,{size:"sm",variant:"outline",icon:!0,className:le("ms-fv-loop",g&&"ms-on"),"aria-label":j.loop,title:j.loop,"aria-pressed":g,onClick:()=>b(!g),children:s.jsx(F,{name:"refresh",size:13})}),s.jsx(At,{className:"ms-fv-speed",variant:"pill",label:j.speed,value:v,onChange:y,options:eb.map(re=>({value:re,label:j.speedValue({n:Vs(S,Number(re))})}))}),d,s.jsx("span",{className:"ms-grow"}),s.jsx("span",{className:"ms-fv-keys",title:m,children:m})]}),s.jsxs("div",{className:"ms-fv-scrubwrap",children:[s.jsxs("div",{ref:N,className:le("ms-fv-scrub",a&&"ms-off"),role:"slider",tabIndex:a?-1:0,"aria-label":j.position,"aria-disabled":a||void 0,"aria-valuemin":0,"aria-valuemax":Za(t),"aria-valuenow":Za(E),"aria-valuetext":j.positionText({time:wt(E),total:wt(t)}),onPointerDown:ae,onPointerMove:K,onPointerUp:I,onPointerCancel:I,onKeyDown:H,children:[s.jsx("div",{className:"ms-fv-ruler","aria-hidden":"true",children:G.map(re=>s.jsx("span",{style:{left:`${_(re)}%`},children:w.web.canvas.seconds({n:Vs(S,re)})},re))}),s.jsx("div",{className:"ms-fv-track","aria-hidden":"true",children:s.jsx("i",{style:{width:`${_(k)}%`}})}),s.jsx("span",{className:"ms-fv-head",style:{left:`${_(k)}%`},"aria-hidden":"true"})]}),s.jsxs("div",{className:"ms-fv-spans",children:[J?s.jsx("span",{className:"ms-fv-span ms-picking","aria-hidden":"true",style:{left:`${_(J.start)}%`,width:`${_(J.end-J.start)}%`}}):null,r.filter(re=>re.pin.range).map(({pin:re,number:oe})=>{const{a:Ne,b:Q}=br(S,re.range);return s.jsx("span",{className:"ms-fv-span",role:"img","aria-label":A.rangeSpan({a:Ne,b:Q,note:re.note??""}),style:{left:`${_(re.range.start)}%`,width:`${_(re.range.end-re.range.start)}%`}},oe)})]}),s.jsx("div",{className:"ms-fv-marks",children:r.filter(re=>re.pin.timeSec!==null).map(({pin:re,number:oe})=>s.jsx("button",{type:"button",className:"ms-fv-mark",style:{left:`${_(re.timeSec)}%`},title:re.note,"aria-label":j.marker({n:oe,time:wt(re.timeSec)}),disabled:a,onClick:()=>{n&&x(),f(re.timeSec)},children:oe},oe))})]}),J?z?s.jsxs("div",{ref:W,className:"ms-fv-rangebubble",role:"group","aria-label":A.rangeBubble,style:{left:`calc(16px + (100% - 32px) * ${_((J.start+J.end)/2)/100})`},children:[s.jsxs("span",{className:"ms-fv-rangetc",children:[wt(J.start)," – ",wt(J.end)]}),s.jsxs($,{ref:T,size:"sm",variant:"ink",onClick:()=>{const re=z;O(null),l?.(re)},children:[s.jsx(F,{name:"comment",size:12}),A.rangeBubbleAction]}),s.jsx("span",{className:"ms-fv-rangeesc",children:A.rangeBubbleEsc})]}):s.jsx("div",{ref:W,className:"ms-fv-rangebubble ms-live","aria-hidden":"true",style:{left:`calc(16px + (100% - 32px) * ${_((J.start+J.end)/2)/100})`},children:s.jsxs("span",{className:"ms-fv-rangetc",children:[wt(J.start)," – ",wt(J.end)]})}):null]})}const sp=5,tp=e=>Math.max(0,Math.min(100,e));function Im(e){const t=V().web.canvas.compare;return s.jsx(rt,{open:e.open,onClose:e.onClose,label:t.label,width:1e3,children:e.open?s.jsx(pT,{...e}):null})}function pT({onClose:e,slug:t,creative:n,versions:a,presets:r,labels:l,states:o,format:c,initial:d,actions:m}){const u=V(),h=u.web.canvas.compare,f=u.web.formatVersions,x=rs(),p=o[c]?.follows??c,g=o[p],b=g?.history??a.filter(we=>we.outputs.some(ze=>ze.format===p)).map(we=>we.n),v=g?.star.version??null,[y,w]=i.useState(d[0]),[j,S]=i.useState(d[1]),[k,E]=i.useState(50),N=i.useRef(null),C=i.useRef(null),R=i.useRef(!1),P=pt(r,p),z=nr({id:p,preset:P,labels:l},x),O=we=>Bn(a.find(ze=>ze.n===we),p),T=[el({slug:t,creative:n,n:y,format:p,enabled:O(y)!==null}),el({slug:t,creative:n,n:j,format:p,enabled:O(j)!==null})],W=(we,ze)=>{const We=T[ze];if(O(we)&&We.state.kind!=="legacy"){const fs=We.state.kind==="ready"?We.state.session.duration:null;return{live:!0,video:P?.kind!=="image",preview:We.state,stalled:We.stalled,retry:We.retry,showing:We.showing,duration:fs}}const Rs=a.find(fs=>fs.n===we)?.outputs.find(fs=>fs.format===p);if(!Rs)return null;const us=fs=>Da(t,n,we,fs);return{live:!1,video:tr(Rs.file),src:us(Rs.file),poster:Rs.preview?us(Rs.preview):void 0,duration:Rs.durationSec}},Z=[W(y,0),W(j,1)],A=Z.some(we=>we?.video),[L,_]=i.useState(()=>A?"side":"overlay"),X=L==="overlay",[ae,K]=i.useState(null),[I,H]=i.useState(null),[de,J]=i.useState("1"),[se,U]=i.useState(!1),te=uT(ae,I,{durations:[Z[0]?.duration,Z[1]?.duration],rate:Number(de),loop:se}),G=!!(ae&&!te.failed[0]||I&&!te.failed[1]),re=we=>{we==="overlay"&&te.pause(),_(we)},oe=i.useRef({on:!1,toggle:te.toggle,step:te.step});oe.current={on:A&&G,toggle:te.toggle,step:te.step},i.useEffect(()=>{const we=ze=>{const We=C.current,Rs=ze.target instanceof Node?ze.target:null;!We||!Rs||ze.defaultPrevented||!oe.current.on||!We.contains(Rs)&&Rs!==We.closest(".ms-dialog")||!ui(ze)||ze.shiftKey||jr(ze)||za(ze,Wo)||(ze.key===" "||ze.code==="Space"?(ze.preventDefault(),ze.repeat||oe.current.toggle()):(ze.key==="ArrowLeft"||ze.key==="ArrowRight")&&(ze.preventDefault(),oe.current.step(ze.key==="ArrowRight"?1:-1)))};return document.addEventListener("keydown",we),()=>document.removeEventListener("keydown",we)},[]);const Ne=P?zg(P.width,P.height):{width:400,height:400},Q=(we,ze)=>{const We=Math.min(we/Ne.width,ze/Ne.height,Ne.height<360?1.4:1);return{width:Math.round(Ne.width*We),height:Math.round(Ne.height*We)}},Re=Q(X?580:310,A?440:520),Ue=we=>{const ze=N.current?.getBoundingClientRect();ze&&ze.width&&E(tp(Math.round((we-ze.left)/ze.width*100)))},is=we=>{R.current=!0,we.currentTarget.setPointerCapture?.(we.pointerId),Ue(we.clientX)},Qe=we=>{const ze=we.key==="ArrowLeft"||we.key==="ArrowDown"?k-sp:we.key==="ArrowRight"||we.key==="ArrowUp"?k+sp:we.key==="Home"?0:we.key==="End"?100:null;ze!==null&&(we.preventDefault(),E(tp(ze)))},gs=(we,ze)=>s.jsxs("span",{className:le("ms-cmp-tag",X&&we===1?"ms-cmp-tag-r":"ms-cmp-tag-l"),"aria-hidden":"true",children:["v",ze,ze===v?" ★":""]}),As=(we,ze)=>Z[we]?.video&&te.failed[we]?s.jsx("span",{className:"ms-cmp-failed",role:"alert",children:h.videoFailed({n:ze})}):null,hs=(we,ze)=>{const We=Z[we],Rs=X?we===0?{clipPath:`inset(0 ${100-k}% 0 0)`}:void 0:Re;return s.jsxs("div",{className:le("ms-cmp-pane",we===0&&"ms-cmp-left"),style:Rs,children:[We?We.live?We.preview.kind==="ready"?s.jsx(di,{session:We.preview.session,title:u.web.render.playerFrame({label:`${z} v${ze}`}),onMedia:we===0?K:H,onStall:We.stalled,onShowing:We.showing,muted:we===1},`v${ze}`):We.preview.kind==="failed"?s.jsxs("span",{className:"ms-cmp-failed ms-cmp-failed-retry",role:"alert",children:[s.jsx("span",{children:u.web.render.failed({detail:We.preview.message})}),s.jsxs($,{size:"sm",variant:"outline",onClick:We.retry,children:[s.jsx(F,{name:"refresh",size:12}),u.web.render.retry]})]}):s.jsx("span",{className:"ms-cplayer-state",role:"status",children:We.preview.kind==="busy"?u.web.render.busy:u.web.render.loading}):We.video?s.jsx("video",{ref:we===0?K:H,src:We.src,poster:We.poster,muted:we===1,playsInline:!0,preload:"auto","aria-label":`${z} v${ze}`},We.src):s.jsx("img",{src:We.src,alt:`${z} v${ze}`,draggable:!1},We.src):s.jsx("span",{className:"ms-cmp-none",children:h.noOutput}),X?null:As(we,ze),X?null:gs(we,ze)]})},Oe=(we,ze,We)=>{const Rs=a.find(fs=>fs.n===ze),us=ze===v&&g?s.jsx(Qs,{tone:"accent",children:g.star.manual?h.starManual:h.starAuto}):ze===g?.defaultVersion?s.jsx("span",{title:f.autoTip,children:s.jsx(Qs,{children:f.auto})}):null;return s.jsxs("div",{className:"ms-cmp-side",children:[s.jsx("span",{className:"ms-cap",children:we}),s.jsx("div",{className:"ms-cmp-chips",role:"group","aria-label":we,children:b.map(fs=>s.jsxs(sn,{on:fs===ze,onClick:()=>We(fs),children:["v",fs,fs===v?" ★":""]},fs))}),us?s.jsx("span",{className:"ms-cmp-marks",children:us}):null,Rs?s.jsx(hT,{className:"ms-cmp-note",text:Rs.request.trim()||u.web.canvas.versions.fromBrief}):null]})},be=g&&!g.follows?[...new Set([j,y])].filter(we=>O(we)!==null||a.some(ze=>ze.n===we&&ze.outputs.some(We=>We.format===p))):[],Fe=m.pending(p),[je,he]=i.useState(null);i.useEffect(()=>{he(null)},[y,j]);const Ke=we=>{he(null),m.star(p,we,{done:e,fail:he})};return s.jsxs("div",{ref:C,className:"ms-cmp",children:[s.jsxs("div",{className:"ms-cmp-main",children:[s.jsx("div",{className:"ms-cmp-stage",children:s.jsxs("div",{ref:N,className:le("ms-cmp-pair",X?"ms-overlay":"ms-side"),style:X?Re:void 0,onPointerDown:X?is:void 0,onPointerMove:X?we=>{R.current&&Ue(we.clientX)}:void 0,onPointerUp:()=>{R.current=!1},onPointerCancel:()=>{R.current=!1},children:[hs(0,y),hs(1,j),X?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"ms-cmp-divider",style:{left:`${k}%`},role:"slider",tabIndex:0,"aria-label":h.slider,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":k,"aria-valuetext":`v${y} ${k}% · v${j} ${100-k}%`,onKeyDown:Qe,children:s.jsxs("span",{className:"ms-cmp-knob","aria-hidden":"true",children:[s.jsx(F,{name:"chevron",size:12}),s.jsx(F,{name:"chevron",size:12})]})}),gs(0,y),gs(1,j),te.failed[0]||te.failed[1]?s.jsxs("div",{className:"ms-cmp-failures",children:[As(0,y),As(1,j)]}):null]}):null]})}),A?s.jsx(sb,{clock:te.clock,duration:te.duration,playing:te.playing,disabled:!G,hint:u.web.formatView.keysLocked,onToggle:te.toggle,onStep:te.step,onSeek:te.seek,onPause:te.pause,onResume:te.play,loop:se,onLoop:U,speed:de,onSpeed:J}):null]}),s.jsxs("div",{className:"ms-cmp-side-col",children:[s.jsxs("div",{className:"ms-cmp-side-scroll",children:[s.jsxs("div",{className:"ms-cmp-head",children:[s.jsx("b",{children:h.title({label:z})}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":u.common.close,onClick:e,children:s.jsx(F,{name:"close",size:12})})]}),s.jsxs("div",{className:"ms-cmp-side",children:[s.jsx("span",{className:"ms-cap","aria-hidden":"true",children:h.view}),s.jsx(it,{label:h.view,value:L,onChange:re,options:A?[{value:"side",label:h.sideBySide},{value:"overlay",label:h.overlay}]:[{value:"overlay",label:h.overlay},{value:"side",label:h.sideBySide}]})]}),Oe(h.left,y,w),Oe(h.right,j,S)]}),be.length?s.jsxs("div",{className:"ms-cmp-actions",children:[je?s.jsx("p",{role:"alert",className:"ms-cmp-error",children:je}):null,be.map((we,ze)=>we===v?s.jsx($,{disabled:!0,children:h.usedForExport({n:we})},we):s.jsx($,{variant:ze===0?"ink":"default",disabled:Fe,onClick:()=>Ke(we),children:h.useForExport({n:we})},we))]}):null]})]})}const xT=2,gT=4,tb=6e4,np=new Map,Mr=new Map,Vi=[];let vd=0;const nb=e=>`${e.slug}/${e.creative}/${e.n}/${e.format}/${e.hash}`,vT=e=>e instanceof lt?e.status:e?.status,Il=Symbol("cancelled");function bT(e,t){return new Promise((n,a)=>{const r={start:()=>{t(null),vd+=1,Promise.resolve().then(e).then(n,a).finally(()=>{vd-=1,Vi.shift()?.start()})},drop:()=>{const l=Vi.indexOf(r);l<0||(Vi.splice(l,1),t(null),a(Il))}};vd<xT?r.start():(Vi.push(r),t(r))})}function jT(e){let t=!1,n=null,a=0,r=null;return{promise:(async()=>{for(let o=0;;o++){if(t)throw Il;try{return await bT(()=>q.getStoryboard(e.slug,e.creative,e.n,e.format),c=>{n=c})}catch(c){if(c===Il||t)throw Il;const d=vT(c);if(d===404||d===422)return"none";if(d!==429||o>=gT)return"failed";await new Promise(m=>{r=m,a=window.setTimeout(m,Yr(o))}),r=null}}})(),waiters:0,cancel:()=>{t=!0,n?.drop(),window.clearTimeout(a),r?.()}}}function yT(e,t){const n=nb(e),a=np.get(n);if(a&&a.until>Date.now())return Promise.resolve(a.answer);let r=Mr.get(n);if(!r){const o=jT(e);o.promise=o.promise.then(c=>{const d=typeof c=="object"?Date.parse(c.expiresAt):NaN;return np.set(n,{answer:c,until:typeof c=="object"?Number.isFinite(d)?d-$m-1e3:0:Date.now()+tb}),c},c=>{if(c===Il)return"failed";throw c}).finally(()=>{Mr.get(n)===o&&Mr.delete(n)}),Mr.set(n,o),r=o}const l=r;return l.waiters+=1,t?.addEventListener("abort",()=>{l.waiters-=1,l.waiters===0&&(Mr.get(n)===l&&Mr.delete(n),l.cancel())},{once:!0}),l.promise}function zm(){const[e,t]=i.useState(null),[n,a]=i.useState(()=>typeof IntersectionObserver>"u");return i.useEffect(()=>{if(n||!e)return;const l=new IntersectionObserver(o=>{o.some(c=>c.isIntersecting)&&(a(!0),l.disconnect())},{rootMargin:"200px"});return l.observe(e),()=>l.disconnect()},[e,n]),{ref:i.useCallback(l=>t(l),[]),seen:n}}function Om(e,t){const[n,a]=i.useState({key:"",url:null,state:"idle"}),r=e?nb(e):null;return i.useEffect(()=>{if(!e||!r||!t)return;const l=new AbortController;let o=0;const c=()=>{yT(e,l.signal).then(d=>{if(l.signal.aborted)return;const m=typeof d=="object"?d:null,u=Rc(m)?.url??null;a({key:r,url:u,state:u?"ready":d==="failed"?"failed":"none"});const h=m?Date.parse(m.expiresAt):NaN;u&&Number.isFinite(h)?o=window.setTimeout(c,Fm(h)):d==="failed"&&(o=window.setTimeout(c,tb))})};return a(d=>d.key===r?d:{key:r,url:null,state:"loading"}),c(),()=>{l.abort(),window.clearTimeout(o)}},[r,t]),e?n.key===r?{url:n.url,state:n.state}:{url:null,state:t?"loading":"idle"}:{url:null,state:"none"}}function wT({still:e,onNone:t,onLoad:n}){const{ref:a,seen:r}=zm(),{url:l,state:o}=Om(e,r);return i.useEffect(()=>{o==="none"&&t?.()},[o]),s.jsx("span",{ref:a,className:"ms-cover",children:l?s.jsx(li,{src:l,alt:"",onLoad:n,small:!0,fallbackClassName:"ms-cover-none"}):null})}function Mc({still:e}){const{ref:t,seen:n}=zm(),{url:a}=Om(e,n);return a?s.jsx("img",{src:a,alt:""}):s.jsx("span",{ref:t,style:{display:"block",width:"100%",height:"100%"}})}const $c="ms.exportFolder",ap=()=>{try{return localStorage.getItem($c)??""}catch{return""}},kT=e=>{try{localStorage.setItem($c,e)}catch{}},ab="ms.exportProfile";function NT(){try{const e=JSON.parse(localStorage.getItem(ab)??"null"),t=mx.includes(e?.quality)?e.quality:No,n=ux.includes(e?.resolution)?e.resolution:null;return{quality:t,resolution:n,fps:null}}catch{return{quality:No,resolution:null,fps:null}}}const ST=({quality:e,resolution:t})=>{try{localStorage.setItem(ab,JSON.stringify({quality:e,resolution:t}))}catch{}},CT=200,ET=new Set([".mp4",".mov",".webm",".m4v"]);function rp(e){const n=e?.kind==="image"?["png","jpg","jpeg","webp"]:["mp4","mov","m4v"];return`.${n.find(a=>e?.extensions.includes(a))??n[0]}`}function Ho(e){const t=V();return s.jsx(rt,{open:e.open,onClose:e.onClose,label:e.group?`${t.web.exportUi.groupHeading}: ${e.title}`:t.web.exportUi.title({title:e.title}),width:760,children:e.group?s.jsx(RT,{...e}):e.snapshot?s.jsx(rb,{...e,snapshot:e.snapshot}):null})}const TT={versions:[],states:{}};function RT(e){const t=V(),[n,a]=i.useState(null);return i.useEffect(()=>{let r=!0;return q.groupExportPlan(e.slug,e.creative).then(l=>{r&&a(l.items)},l=>{r&&a({error:pe(l)})}),()=>{r=!1}},[e.slug,e.creative]),n===null?s.jsx("p",{className:"ms-exp-empty",role:"status",children:t.web.exportUi.groupLoading}):Array.isArray(n)?s.jsx(rb,{...e,snapshot:TT,groupPlan:n}):s.jsx("p",{className:"ms-exp-error",role:"alert",children:t.web.exportUi.groupLoadFailed({detail:n.error})})}function rb({onClose:e,slug:t,creative:n,title:a,snapshot:r,presets:l,labels:o,pattern:c,onSettings:d,jobs:m={},locales:u,subtitles:h,groupPlan:f}){const x=V(),p=x.web.exportUi,g=rs(),b=xt(),{versions:v,states:y}=r,w=i.useMemo(()=>Ul(h),[h]),j=i.useMemo(()=>f?f.map(D=>{const Ae=pt(l,D.format),ts=D.state==="needs-render",ps=D.state==="needs-render"||D.file===""?null:{format:D.format,file:D.file,width:D.width,height:D.height,durationSec:null,verified:!0,preview:null},Cs=D.source==="pick"?p.groupPick({variant:D.letter.toUpperCase(),n:D.version}):p.groupDefault({variant:D.letter.toUpperCase(),n:D.version}),ks=ts&&D.hash?{n:D.version,format:D.format,hash:D.hash}:null;return{id:D.format,preset:Ae,n:D.v??D.version,fileN:D.version,output:ps,needsRender:ts,still:ks,composed:D.composed===!0,file:ps?.file??(ts?`${D.format}${rp(Ae)}`:null),follows:null,newer:null,blocked:D.state==="missing"?p.fileMissing({n:D.version}):null,problems:[],member:D.slug,sourceLabel:Cs}}):Object.values(y).flatMap(D=>{const Ae=D.follows?y[D.follows]?.star.version??null:D.star.version;if(Ae===null)return[];const ts=D.follows?D.exportVersion??(Bn(v.find(jt=>jt.n===Ae),D.id)?Ae:null):Ae,ps=ts===null?void 0:v.find(jt=>jt.n===ts),Cs=ps?.outputs.find(jt=>jt.format===D.id)??null,ks=Bn(ps,D.id),Ms=ps!==void 0&&ks!==null&&rc(ps,D.id,w)!=="rendered",Bt=Ms&&ks&&ts!==null?{n:ts,format:D.id,hash:ks.hash}:null,bt=pt(l,D.id),nt=D.follows?xn(pt(l,D.follows),D.follows,g,o):null,fn=Ms?null:Cs?D.starFileMissing?p.fileMissing({n:ts??Ae}):null:nt!==null?p.noFollowerFile({n:Ae,primary:nt}):p.fileMissing({n:Ae}),Nn=Cs?.file??(Ms?`${D.id}${rp(bt)}`:null),Vn=ps&&!Ms&&ax(ps,D.id).length?pf(Cs,x,g):[];return[{id:D.id,preset:bt,n:Ae,fileN:ts,output:Cs,needsRender:Ms,still:Bt,composed:ps!==void 0&&Bn(ps,D.id)!==null,file:Nn,follows:nt,newer:nt===null?D.star.newer:null,blocked:fn,problems:Vn,...D.subtitlesTrack===!1?{noTrack:!0}:{}}]}),[f,y,v,l,o,p,g,x,w]),[S,k]=i.useState(()=>Object.fromEntries(j.map(D=>[D.id,D.blocked===null&&D.problems.length===0]))),[E,N]=i.useState(c),[C,R]=i.useState(c),[P,z]=i.useState({kind:"idle"}),[O]=i.useState(()=>Lj(new Date)),[T,W]=i.useState(ap),Z=T!==""&&T===ap(),[A,L]=i.useState({kind:"idle"}),[_,X]=i.useState(null),ae=!!(u&&u.extra.length>0),K=f?[]:(h??[]).map(D=>D.lang),[I,H]=i.useState({}),[de,J]=i.useState({}),[se,U]=i.useState({}),[te,G]=i.useState({}),[re,oe]=i.useState(()=>u?{[u.primary]:!0}:{}),[Ne,Q]=i.useState(null),Re=i.useRef(null),Ue=A.kind==="run"||A.kind==="job",is=i.useId(),Qe=i.useId(),gs=i.useId(),As=i.useId(),hs=i.useId(),Oe=i.useId(),be=i.useId(),[Fe,je]=i.useState(NT),he=A.kind==="job"?m[A.id]:void 0,Ke=A.kind==="job"?A.id:null;i.useEffect(()=>Ke?Ml.watch(Ke):void 0,[Ke]),i.useEffect(()=>{if(A.kind!=="job"||!he||he.state==="queued"||he.state==="running")return;const D=he.export;if(he.state==="succeeded"&&D){const Ae=(D.excluded??[]).map(ts=>{const ps=j.find(ks=>ks.id===ts.format),Cs=nr({id:ts.format,preset:ps?.preset??null,out:ps?.output??null,labels:o},g);return p.excludedItem({label:ts.locale?`${Cs} (${ts.locale})`:Cs,n:ts.version,list:pf({problems:ts.problems,issues:ts.issues??[]},x,g).join("; ")})});L({kind:"done",destination:D.destination,files:D.files??[],skipped:D.skipped??[],excluded:Ae});return}if(L({kind:"idle"}),D?.refusal?.code==="localization-needs-force"){Q(D.refusal.problems?.length?D.refusal.problems:[he.error??""]);return}X(he.state==="cancelled"?p.cancelled:p.failed({detail:he.error??x.web.jobState.failed}))},[A,he,p,x,j,o,g]);const we=i.useRef(new AbortController);i.useEffect(()=>{const D=new AbortController;return we.current=D,()=>D.abort()},[]);const ze=Pt()?p.showInFinder:p.showInFolder,We=u&&ae?u.primary:void 0,Rs=(D,Ae=We)=>Uj({title:a,slug:n,format:D.id,preset:D.preset??void 0,size:D.output??void 0,version:D.n,date:O,...Ae?{locale:Ae}:{}}),us=j.map(D=>D.file?ji(E,Rs(D)):null),fs=fh(j.flatMap((D,Ae)=>us[Ae]?.ok&&D.file?[{format:D.id,stem:us[Ae].name,ext:yi(D.file)}]:[]));let fe=0;const Ge=j.map((D,Ae)=>{const ts=us[Ae]?.ok&&D.file;return{row:D,name:ts?`${fs[fe++]}${yi(D.file)}`:null}}),De=Ge.filter(D=>D.row.blocked===null&&S[D.row.id]),os=u&&ae?u.extra.filter(D=>re[D]):[],Ze=!u||!ae||!!re[u.primary],vs=D=>K.filter(Ae=>D[Ae]),Le=D=>D.file!==null&&ET.has(yi(D.file)),ne=D=>Le(D)&&D.noTrack!==!0,Ee=De.some(D=>ne(D.row)),Ce=D=>(h??[]).find(Ae=>Ae.lang===D)?.timing.locale,Xe=(D,Ae)=>{const ts=Ce(D);return ts===void 0||ts===Ae},ue=D=>D===void 0||D===u?.primary?void 0:D,xe=D=>{const Ae=De.filter(ts=>ne(ts.row));return Ae.length>0&&Ae.every(ts=>v.find(ps=>ps.n===ts.row.n)?.localizations?.some(ps=>ps.locale===D&&ps.instanceId===ts.row.id)===!0)},Be=D=>{const Ae=(h??[]).find(ps=>ps.lang===D);if(!u||!ae||!Ae)return;const ts=te[D];return ue(ts!==void 0&&Xe(D,ue(ts))?ts:_j(Ae,u,xe))},_e=D=>{const Ae=Ce(D);return Ae===void 0||ae&&!!re[Ae]},ge=D=>Ce(D)===void 0||ae,qe=(Ee?vs(I).filter(ge):[]).map(D=>({video:Be(D),lang:D})),Ye=vs(de).filter(_e),Ls=vs(se).filter(_e),et=qe.length+Ye.length+Ls.length>0,bs=Ye.length>0||Ls.length>0,Us=(D,Ae,ts)=>{const ps=ts&&Le(D)?Ye.filter(Ms=>Xe(Ms,Ae)):[],Cs=ps.length>0||ts&&Le(D)&&Ls.some(Ms=>Xe(Ms,Ae)),ks=qe.filter(Ms=>Ms.video===Ae).map(Ms=>Ms.lang);return{plain:ts&&(!Le(D)||Cs||ks.length===0),files:ps,drawn:ne(D)?ks:[]}},Me=[...Ze?[void 0]:[],...os],ss=[...Me.map(D=>[D,!0]),...[...new Set(qe.map(D=>D.video))].filter(D=>!Me.includes(D)).map(D=>[D,!1])],Ie=ss.flatMap(([D,Ae])=>De.flatMap(ts=>{const ps=ts.row.file?ji(E,Rs(ts.row,D??We)):null;if(!ps?.ok)return[];const Cs=Us(ts.row,D,Ae),ks={row:ts.row,tag:D,format:ts.row.id,stem:Ij(E,ps.name,D,D!==void 0),ext:yi(ts.row.file),sub:void 0,files:Cs.files};return[...Cs.plain?[ks]:[],...Cs.drawn.map(Ms=>({...ks,stem:zj(ks.stem,Ms),sub:Ms,files:[]}))]})),ys=fh(Ie),ns=Ie.map((D,Ae)=>({tag:D.tag,sub:D.sub,format:D.format,files:D.files,stem:ys[Ae],name:`${ys[Ae]}${D.ext}`})),Ys=ns.filter(D=>D.tag===void 0),mt=qe.map(D=>({...D,names:ns.filter(Ae=>Ae.sub===D.lang&&Ae.tag===D.video).map(Ae=>Ae.name)})).filter(D=>D.names.length>0),Ns=ns.filter(D=>D.sub===void 0).flatMap(D=>D.files.flatMap(Ae=>[`${D.stem}.${Ae}.srt`,`${D.stem}.${Ae}.vtt`])),ct=(D,Ae)=>{if(!et||!Ze||Us(D,void 0,!0).plain)return Ae;if(Le(D)&&!ne(D))return p.subtitles.noTrackRow;const ps=Ys.filter(Cs=>Cs.format===D.id&&Cs.sub!==void 0).map(Cs=>Cs.name);return ps.length>0?ps.join(", "):Ae},ls=ss.reduce((D,[Ae,ts])=>D+De.reduce((ps,Cs)=>{const ks=Us(Cs.row,Ae,ts);return ps+(ks.plain?1+2*ks.files.length:0)+ks.drawn.length},0),0),Is=os.map(D=>({tag:D,names:ns.filter(Ae=>Ae.tag===D).map(Ae=>Ae.name)})).filter(D=>D.names.length>0),Hs=De[0]?.row??j[0],ee=Hs?ji(E,Rs(Hs)).unknown:[],as=E.length>CT,ds=!E.trim()||De.some(D=>D.name===null),Ks=j.some(D=>!ji(E,Rs(D)).ok),tt=Oj(ns.map(D=>D.name)),js=as?p.errors.invalidPattern:ds?p.emptyName:tt.length?p.collision({list:tt.join(", ")}):null,Ds=Ze?et?Ys.find(D=>D.sub===void 0)?.name??null:(De[0]??Ge.find(D=>D.name!==null))?.name??null:null,ht=D=>{const Ae=Re.current,ts=`{${D}}`,ps=Ae?.selectionStart??E.length,Cs=Ae?.selectionEnd??E.length;N(E.slice(0,ps)+ts+E.slice(Cs)),z({kind:"idle"}),requestAnimationFrame(()=>{Ae&&(Ae.focus(),Ae.setSelectionRange(ps+ts.length,ps+ts.length))})},un=async()=>{z({kind:"saving"});try{const D=await q.updateSettings({exportNamePattern:E});R(D.exportNamePattern),z({kind:"saved"}),d?.(D)}catch(D){z({kind:"failed",detail:pe(D)})}},Os=async()=>{X(null);try{const D=await b?.pickFolder(p.pickTitle,T.trim()||void 0);D&&W(D)}catch(D){X(pe(D))}},gt=De.length>0&&T.trim()!==""&&js===null&&!Ue,mn=u&&ae?[u.primary,...u.extra].filter(D=>re[D]):[],Wt=u?mn.some(D=>D!==u.primary):!1,$n=Wt?{locales:mn}:{},gn=qe.map(D=>u&&ae?{video:D.video??u.primary,lang:D.lang}:D.lang),zt=et?{subtitles:{...gn.length>0?{drawn:gn}:{},...Ye.length>0?{files:Ye}:{},...Ls.length>0?{soft:Ls}:{}}}:{},Mt=Wt||qe.some(D=>D.video!==void 0),Yn=D=>D.composed&&D.preset!==null&&qj(D.preset,D.id),vt=j.some(Yn),St=D=>{if(Mt||!Yn(D)||Fe.resolution===null&&Fe.fps===null)return null;const Ae=Fe.resolution!==null?Vj(D.preset,Fe.resolution):null;return[Ae?`${Ae.width}×${Ae.height}`:null,Fe.fps!==null?x.render.fpsName({fps:Fe.fps}):null].filter(Boolean).join(" · ")},an=j.filter(Yn).map(D=>D.output?.render?.fps??null),Zt=an.length>0&&an.every(D=>D!==null&&D===an[0])?String(an[0]):null,$t=Mt?{quality:No}:{quality:Fe.quality,...Fe.resolution!==null?{resolution:Fe.resolution}:{},...Fe.fps!==null?{fps:Fe.fps}:{}},rn=async(D=!1)=>{const Ae=T.trim();if(!gt)return;X(null),Q(null),L({kind:"run"});const ts={},ps={};for(const Ms of De)Ms.row.follows!==null?ps[Ms.row.id]=Ms.row.fileN??Ms.row.n:ts[Ms.row.id]=Ms.row.n;const Cs=we.current.signal,ks=Object.keys(ps).length?{follow:ps}:{};try{const Ms=(bt,nt)=>f?q.exportGroupJob(t,n,{destination:Ae,formats:De.map(fn=>fn.row.id),pattern:E,date:O,...$n,...$t,...bt?{force:!0}:{}}):pv(()=>q.exportPicksJob(t,n,{destination:Ae,picks:ts,...ks,pattern:E,date:O,...$n,...zt,...$t,...bt?{force:!0}:{}}),nt),Bt=await Ms(D,iu(Cs));if(D||Ml.setRetry(Bt.job.id,()=>Ms(!0,iu(new AbortController().signal))),kT(Ae),Mt||ST(Fe),Cs.aborted)return;L({kind:"job",id:Bt.job.id})}catch(Ms){if(Cs.aborted)return;if(Ms instanceof lt&&Ms.code==="localization-needs-force"){Q(Ms.problems?.length?Ms.problems:[Ms.message]),L({kind:"idle"});return}X(gv(Ms,x)),L({kind:"idle"})}},Jt=()=>{A.kind==="job"&&Promise.resolve().then(()=>q.cancelJob(A.id)).catch(D=>X(pe(D)))},hn=s.jsxs("div",{className:"ms-exp-head",children:[s.jsxs("div",{className:"ms-exp-titles",children:[s.jsx("h2",{children:f?p.groupHeading:p.heading}),s.jsx("span",{className:"ms-exp-sub",children:f?p.groupSub({title:a}):p.sub({title:a})})]}),s.jsx($,{variant:"ghost",icon:!0,"aria-label":x.common.close,onClick:e,children:s.jsx(F,{name:"close",size:13,strokeWidth:1.6})})]});return A.kind==="done"?s.jsxs("div",{className:"ms-exp",children:[hn,s.jsxs("div",{className:"ms-exp-done",role:"status",children:[s.jsx("span",{className:"ms-exp-done-mark",ref:D=>{D&&ti(D)},children:s.jsx(F,{name:"check",size:24,strokeWidth:2.2})}),s.jsx("b",{children:p.done({count:A.files.length})}),s.jsx("span",{className:"ms-exp-path",children:A.destination}),A.skipped.length?s.jsx("span",{className:"ms-exp-skipped",children:p.skipped({list:A.skipped.join(", ")})}):null,A.excluded.length?s.jsx("span",{className:"ms-exp-problem",role:"alert",children:p.excluded({list:A.excluded.join(", ")})}):null,_?s.jsx("p",{role:"alert",className:"ms-exp-error",children:_}):null,s.jsxs("div",{className:"ms-exp-done-actions",children:[b?s.jsxs($,{variant:"outline",onClick:()=>{Du(b,A.destination,A.files).catch(D=>X(pe(D)))},children:[s.jsx(F,{name:"folder",size:14}),ze]}):null,s.jsx($,{variant:"ink",onClick:e,children:p.finish})]})]})]}):s.jsxs("div",{className:"ms-exp",children:[hn,j.length?s.jsxs("div",{className:"ms-exp-rows",children:[s.jsxs("div",{className:"ms-exp-row ms-exp-cols ms-cap","aria-hidden":"true",children:[s.jsx("span",{}),s.jsx("span",{}),s.jsx("span",{children:p.format}),s.jsx("span",{children:p.version})]}),Ge.map(({row:D,name:Ae})=>{const ts=nr({id:D.id,preset:D.preset,out:D.output,labels:o},g),ps=!D.still&&D.output&&D.fileN!==null?Nr(t,D.member??n,D.fileN,D.output):null,Cs=D.preset?D.preset.width/D.preset.height:D.output?D.output.width/D.output.height:1,ks=D.blocked!==null;return s.jsxs("div",{className:le("ms-exp-row",ks?"ms-blocked":!S[D.id]&&"ms-off"),children:[s.jsx(Rn,{on:!ks&&!!S[D.id],label:p.include({label:ts}),disabled:Ue||ks,onChange:Ms=>k(Bt=>({...Bt,[D.id]:Ms}))}),s.jsx("span",{className:le("ms-exp-thumb",Cs>1.05?"ms-wide":Cs<.95?"ms-tall":"ms-square"),"aria-hidden":"true",children:D.still?s.jsx(Mc,{still:{...D.still,slug:t,creative:D.member??n}}):ps?ps.video?s.jsx("video",{src:ps.src,muted:!0,preload:"metadata"}):s.jsx("img",{src:ps.src,alt:""}):null}),s.jsxs("span",{className:"ms-exp-name",children:[s.jsxs("span",{className:"ms-exp-label",children:[D.preset?s.jsx(en,{channel:da(D.preset.channel)}):null,s.jsx("b",{children:ts})]}),ks?s.jsx("span",{className:"ms-exp-blocked",children:D.blocked}):s.jsxs("span",{className:"ms-exp-file",children:[ct(D,Ae)??"—",St(D)?s.jsxs("span",{className:"ms-exp-size",children:[" ",p.outputSize({size:St(D)})]}):null]}),D.needsRender&&!ks?s.jsx("span",{className:"ms-exp-render",children:x.web.render.rendersFirst}):null,D.problems.length&&!ks?s.jsx("span",{className:"ms-exp-problem",children:p.renderProblems({list:D.problems.join("; ")})}):null]}),D.sourceLabel!==void 0?s.jsx("span",{className:"ms-exp-ver",children:D.sourceLabel}):D.follows!==null?s.jsxs("span",{className:"ms-exp-follows",children:[p.follows({primary:D.follows}),s.jsx("span",{className:"ms-exp-ver",children:p.star({n:D.n})})]}):s.jsxs("span",{className:"ms-exp-ver",children:[p.star({n:D.n}),D.newer!==null?s.jsx("span",{className:"ms-exp-newer",children:p.newer({n:D.newer})}):null]})]},D.id)})]}):s.jsx("p",{className:"ms-exp-empty",children:p.empty}),u&&ae?s.jsxs("div",{className:"ms-exp-langs",role:"group","aria-label":x.web.languages.exportLanguages,children:[s.jsx("span",{className:"ms-exp-dest-label",children:x.web.languages.exportLanguages}),s.jsx("div",{className:"ms-exp-langs-list",children:[u.primary,...u.extra].map(D=>s.jsxs("label",{className:"ms-exp-lang",children:[s.jsx(Rn,{on:!!re[D],label:D===u.primary?x.web.languages.renderOriginal({language:Js(D,g)}):Js(D,g),disabled:Ue,onChange:Ae=>{Q(null),oe(ts=>({...ts,[D]:Ae}))}}),s.jsx("span",{children:D===u.primary?x.web.languages.renderOriginal({language:Js(D,g)}):Js(D,g)})]},D))})]}):null,K.length>0?s.jsxs("div",{className:"ms-exp-langs ms-exp-subs",role:"group","aria-label":p.subtitles.title,children:[s.jsx("span",{className:"ms-exp-dest-label",children:p.subtitles.title}),[...Ee?[[p.subtitles.drawn,p.subtitles.drawnHint,I,H,!0]]:[],[p.subtitles.files,p.subtitles.filesHint,de,J,!1],[p.subtitles.soft,p.subtitles.softHint,se,U,!1]].map(([D,Ae,ts,ps,Cs])=>s.jsxs("div",{className:"ms-exp-subs-row",role:"group","aria-label":D,children:[s.jsxs("span",{className:"ms-exp-subs-name",children:[s.jsx("b",{children:D}),s.jsx("span",{className:"ms-faint",children:Ae})]}),s.jsx("div",{className:"ms-exp-langs-list",children:K.map(ks=>{const Ms=Ce(ks),Bt=Cs?!ge(ks):!_e(ks),bt=Cs&&ts[ks]&&u&&ae?[u.primary,...u.extra].filter(nt=>Xe(ks,ue(nt))).map(nt=>({value:nt,label:nt===u.primary?x.web.languages.renderOriginal({language:Js(nt,g)}):Js(nt,g)})):null;return s.jsxs("span",{className:"ms-exp-sub-lang",children:[s.jsxs("label",{className:le("ms-exp-lang",Bt&&"ms-off"),title:Bt&&Ms?p.subtitles.voicedOnly({language:Js(Ms,g)}):void 0,children:[s.jsx(Rn,{on:!!ts[ks]&&!Bt,label:`${D}: ${Js(ks,g)}`,disabled:Ue||Bt,onChange:nt=>ps(fn=>({...fn,[ks]:nt}))}),s.jsx("span",{children:Js(ks,g)})]}),bt&&u?s.jsx(At,{variant:"pill",label:p.subtitles.drawnVideo({language:Js(ks,g)}),value:Be(ks)??u.primary,options:bt,disabled:Ue||bt.length<2,onChange:nt=>G(fn=>({...fn,[ks]:nt}))}):null]},ks)})})]},D)),bs?s.jsx("p",{className:"ms-exp-note ms-exp-subs-note",children:p.subtitles.cleanNote}):null,mt.length>0||Ns.length>0?s.jsxs("div",{className:"ms-exp-preview ms-exp-subs-out",children:[mt.map(D=>s.jsxs("span",{className:"ms-exp-preview-line",children:[s.jsx("span",{className:"ms-exp-preview-label",children:u&&ae?p.subtitles.previewDrawnOn({language:Js(D.lang,g),video:Js(D.video??u.primary,g)}):p.subtitles.previewDrawn({language:Js(D.lang,g)})}),s.jsx("span",{className:"ms-exp-file",children:D.names.join(", ")})]},`sub-${D.video??""}-${D.lang}`)),Ns.length>0?s.jsxs("span",{className:"ms-exp-preview-line",children:[s.jsx("span",{className:"ms-exp-preview-label",children:p.subtitles.files}),s.jsx("span",{className:"ms-exp-file",children:Ns.join(", ")})]}):null]}):null]}):null,Ne?s.jsxs("div",{className:"ms-exp-refused",role:"alert",children:[s.jsx("b",{children:x.web.languages.needsForceTitle}),s.jsx("ul",{children:Ne.map(D=>s.jsx("li",{children:D},D))}),s.jsx($,{variant:"outline",size:"sm",disabled:Ue,onClick:()=>{rn(!0)},children:x.web.languages.renderAnyway})]}):null,s.jsxs("div",{className:"ms-exp-dest",children:[s.jsx("span",{className:"ms-exp-dest-label",id:is,children:p.saveTo}),s.jsxs("div",{className:"ms-exp-dest-field",children:[b?s.jsxs("div",{className:"ms-exp-folder","aria-labelledby":is,children:[s.jsx(F,{name:"folder",size:14}),s.jsx("span",{className:le("ms-exp-path",!T&&"ms-faint"),children:T||p.noFolder}),Z?s.jsx("span",{className:"ms-exp-last",children:p.lastUsed}):null]}):s.jsx(ms,{"aria-label":p.folder,value:T,disabled:Ue,placeholder:p.placeholder,spellCheck:!1,onChange:D=>W(D.target.value),onKeyDown:D=>{D.key==="Enter"&&rn()}}),b?s.jsx($,{variant:"outline",disabled:Ue,onClick:()=>{Os()},children:p.choose}):null]}),vt?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-exp-dest-label",id:As,children:p.resolution}),s.jsx("div",{className:"ms-exp-dest-field","aria-labelledby":As,children:s.jsx(At,{label:p.resolution,value:Mt||Fe.resolution===null?"original":String(Fe.resolution),disabled:Ue||Mt,options:[{value:"original",label:p.resolutionOriginal},...ux.map(D=>({value:String(D),label:p.resolutionOption({n:D})}))],onChange:D=>je(Ae=>({...Ae,resolution:D==="original"?null:Number(D)}))})}),s.jsx("span",{className:"ms-exp-dest-label",id:Oe,children:p.frameRate}),s.jsx("div",{className:"ms-exp-dest-field","aria-labelledby":Oe,children:s.jsx(At,{label:p.frameRate,value:Mt||Fe.fps===null?"original":String(Fe.fps),disabled:Ue||Mt,options:[{value:"original",label:p.frameRateOriginal({fps:Zt})},...Dj.map(D=>({value:String(D),label:p.frameRateOption({n:D})}))],onChange:D=>je(Ae=>({...Ae,fps:D==="original"?null:Number(D)}))})}),s.jsx("span",{className:"ms-exp-dest-label",id:hs,children:p.quality}),s.jsxs("div",{className:"ms-exp-quality",children:[s.jsx(it,{label:p.quality,value:Mt?No:Fe.quality,disabled:Ue||Mt,describedBy:be,options:mx.map(D=>({value:D,label:p.qualityNames[D]})),onChange:D=>je(Ae=>({...Ae,quality:D}))}),s.jsx("span",{id:be,className:"ms-exp-note",children:Mt?p.profileLocked:`${p.qualityHints[Fe.quality]}. ${p.profileHint}.`})]})]}):null,s.jsx("span",{className:"ms-exp-dest-label",id:Qe,children:p.names}),s.jsxs("div",{className:"ms-exp-pattern",children:[s.jsxs("div",{className:"ms-exp-dest-field",children:[s.jsx(ms,{ref:Re,"aria-label":p.pattern,"aria-describedby":gs,"aria-invalid":js!==null||void 0,value:E,disabled:Ue,spellCheck:!1,autoComplete:"off",className:"ms-exp-pattern-field",onChange:D=>{N(D.target.value),z(Ae=>Ae.kind==="saving"?Ae:{kind:"idle"})}}),s.jsx($,{variant:"outline",disabled:Ue||P.kind==="saving"||E===C||as||!E.trim()||Ks,loading:P.kind==="saving",onClick:()=>{un()},children:p.saveDefault})]}),s.jsx("div",{className:"ms-exp-tokens",role:"group","aria-labelledby":Qe,children:Bj.map(D=>s.jsx(sn,{className:"ms-exp-token",disabled:Ue,title:p.insertToken({token:D}),onClick:()=>ht(D),children:`{${D}}`},D))}),s.jsxs("div",{id:gs,className:"ms-exp-preview",children:[Ds?s.jsxs("span",{className:"ms-exp-preview-line",children:[s.jsx("span",{className:"ms-exp-preview-label",children:p.preview}),s.jsx("span",{className:"ms-exp-file",children:Ds})]}):null,Is.map(D=>s.jsxs("span",{className:"ms-exp-preview-line",children:[s.jsx("span",{className:"ms-exp-preview-label",children:p.previewLanguage({language:Js(D.tag,g)})}),s.jsx("span",{className:"ms-exp-file",children:D.names.join(", ")})]},D.tag)),ee.length?s.jsx("span",{className:"ms-exp-hint",children:p.unknownVars({list:ee.map(D=>`{${D}}`).join(", ")})}):null,js?s.jsx("span",{role:"alert",className:"ms-exp-error",children:js}):null,P.kind==="saved"?s.jsx("span",{role:"status",className:"ms-exp-note",children:p.savedDefault}):null,P.kind==="failed"?s.jsx("span",{role:"alert",className:"ms-exp-error",children:p.saveFailed({detail:P.detail})}):null]})]})]}),s.jsxs("div",{className:"ms-exp-foot",children:[A.kind==="job"?s.jsxs("div",{className:"ms-exp-progress",children:[s.jsx("span",{children:Yd(he,p)}),s.jsx(MT,{job:he,label:Yd(he,p)}),s.jsx("span",{className:"ms-exp-note",role:"status",children:p.background})]}):Ue?s.jsxs("div",{className:"ms-exp-progress",children:[s.jsx("span",{children:p.running}),s.jsx("div",{className:"ms-progress ms-indet",role:"progressbar","aria-label":p.running,children:s.jsx("i",{})})]}):s.jsxs("div",{className:"ms-exp-summary",children:[s.jsx("b",{children:p.files({count:ls})}),_?s.jsx("span",{role:"alert",className:"ms-exp-error",children:_}):s.jsx("span",{className:"ms-exp-note",children:p.noOverwrite})]}),A.kind==="job"?s.jsxs(s.Fragment,{children:[s.jsx($,{size:"lg",variant:"ghost",onClick:Jt,children:p.cancelExport}),s.jsx($,{size:"lg",variant:"ink",onClick:e,children:x.common.close})]}):s.jsxs(s.Fragment,{children:[s.jsx($,{size:"lg",variant:"ghost",onClick:e,children:x.common.cancel}),s.jsx($,{size:"lg",variant:"ink",loading:Ue,disabled:!gt||ae&&mn.length===0,onClick:()=>{rn()},children:p.run({count:ls})})]})]})]})}function MT({job:e,label:t}){const n=e?.export?.stage==="rendering"&&e.export.renders?.length?e.export.pct:null;return n==null?s.jsx("div",{className:"ms-progress ms-indet",role:"progressbar","aria-label":t,children:s.jsx("i",{})}):s.jsx(kr,{value:n,label:t})}const lp=e=>e.state==="queued"||e.state==="running";function $T(e,t,n){const a=t?Kj(t):null,r=a?e.find(c=>c.kind==="export"&&lp(c)&&c.key.startsWith(a)):void 0;if(r){const c=r.export;return{kind:"export",pct:c?.stage==="rendering"&&c.renders?.length?c.pct??0:null}}if(!t?.startsWith("creative:"))return null;if(n){const c=no(n.version,n.format,[...e],t);return c?.kind==="rendering"?{kind:"render",pct:c.pct}:c?.kind==="queued"?{kind:"render",pct:null}:null}const l=t.slice(9),o=e.filter(c=>c.kind==="render"&&lp(c)&&(c.key.startsWith(`render:${l}:v`)||c.key.startsWith(`render-export:${l}:v`)));return o.length?{kind:"render",pct:o.some(c=>c.state==="running")?Wj(o):null}:null}function FT(e){return typeof e.getAnimations!="function"?[]:e.getAnimations().filter(t=>t.effect?.getKeyframes?.().some(n=>"width"in n)===!0)}function Dm({jobs:e,jobKey:t,scope:n,disabled:a,secondary:r,onClick:l}){const o=V(),c=o.web.exportUi,d=o.web.render,m=$T(e,t,n),u=m?m.kind==="export"?m.pct!==null?c.exportingPct({pct:m.pct}):c.running:m.pct!==null?d.rendering({pct:m.pct}):d.queued:o.web.canvas.export,h=[c.exportingPct({pct:100}),c.running,d.rendering({pct:100}),d.queued],f=m!==null,x=i.useRef(null),p=i.useRef(null),g=i.useRef(f);return i.useLayoutEffect(()=>{const b=x.current;if(!b)return;const v=FT(b);if(g.current!==f){const y=b.getBoundingClientRect().width;for(const j of v)j.cancel();const w=b.getBoundingClientRect().width;p.current!==null&&Hy(b,v.length?y:p.current),p.current=w}else v.length||(p.current=b.getBoundingClientRect().width);g.current=f}),s.jsxs($,{ref:x,variant:r?"outline":"ink",className:le("ms-cv-export ms-exp-ctl",m&&"ms-working"),disabled:a,onClick:l,children:[m&&m.pct!==null?s.jsx("span",{className:"ms-exp-ctl-fill",style:{width:`${m.pct}%`},"aria-hidden":"true"}):null,m?s.jsx(Ts,{decorative:!0,size:13}):s.jsx(F,{name:"download",size:13,strokeWidth:1.7}),f?s.jsxs("span",{className:"ms-exp-ctl-label",children:[h.map(b=>s.jsx("span",{className:"ms-exp-ctl-sizer","aria-hidden":"true",children:b},b)),s.jsx("span",{className:"ms-exp-ctl-text",children:u})]}):s.jsx("span",{className:"ms-exp-ctl-text",children:u})]})}function PT({open:e,onClose:t,onPack:n,onFormats:a}){const l=V().web.storePack.exportChoice;return s.jsx(rt,{open:e,onClose:t,label:l.title,width:440,children:s.jsxs("div",{className:"ms-exp",children:[s.jsx("div",{className:"ms-exp-head",children:s.jsx("div",{className:"ms-exp-titles",children:s.jsx("h2",{children:l.title})})}),s.jsxs("div",{className:"ms-exp-choice",children:[s.jsxs("button",{type:"button",className:"ms-exp-choice-opt",onClick:n,children:[s.jsxs("span",{className:"ms-exp-choice-icon","aria-hidden":"true",children:[s.jsx(en,{channel:"appstore"}),s.jsx(en,{channel:"googleplay"})]}),s.jsxs("span",{className:"ms-exp-choice-text",children:[s.jsx("b",{children:l.pack}),s.jsx("span",{children:l.packHint})]})]}),s.jsxs("button",{type:"button",className:"ms-exp-choice-opt",onClick:a,children:[s.jsx("span",{className:"ms-exp-choice-icon","aria-hidden":"true",children:s.jsx(F,{name:"download",size:16,strokeWidth:1.6})}),s.jsxs("span",{className:"ms-exp-choice-text",children:[s.jsx("b",{children:l.formats}),s.jsx("span",{children:l.formatsHint})]})]})]})]})})}const AT={[pl.appstore["iphone-69"]]:{store:"appstore",device:"iphone69"},[pl.appstore["ipad-13"]]:{store:"appstore",device:"ipad13"},[pl.playstore.phone]:{store:"playstore",device:"phone"},[pl.playstore.tablet]:{store:"playstore",device:"tablet"},[pl.playstore.feature]:{store:"playstore",device:"feature"},[ph.appstore]:{store:"appstore",device:null},[ph.playstore]:{store:"playstore",device:null}};function LT(e,t){const n=[];for(const a of e){const r=AT[kt(a)];if(!r)continue;const l=pt(t.presets,a),o=l?sm(l,t.locale):a,c=r.device===null||r.device==="feature";let d=n.find(f=>f.store===r.store);d||n.push(d={store:r.store,devices:[]});const m=kt(a);let u=d.devices.find(f=>f.key===m);if(!u){const f=c?l?.kind==="video"?"video":"image":"shots";d.devices.push(u={key:m,label:c||!r.device?o:t.deviceName(r.device),single:c,kind:f,width:l?.width??0,height:l?.height??0,rows:[]})}const h=c?o:t.labels?.[a]??xn(l,a,t.locale,t.labels);u.rows.push({id:a,label:h,aspect:l?l.width/l.height:1,thumb:t.thumbOf(a)})}return n}function ip(e,t){const n=e.filter(a=>!t.has(a)).length;return{n,of:e.length,on:n===e.length,mixed:n>0&&n<e.length}}function IT(e,t,n){const a=new Set(e);for(const r of t)n?a.delete(r):a.add(r);return a}function zT(e,t){const n=e.flatMap(a=>a.devices);return n.find(a=>a.key===t)??n[0]??null}function OT(e){return e.width>e.height?2:4}function DT(e,t,n){const a=e.indexOf(t);return a<0?e[0]:e[Math.min(e.length-1,Math.max(0,a+n))]}function BT(e,t,n,a,r){if(!n)return null;const l=n.compositions?.find(c=>c.format===a);if(l&&rc(n,a,r)!=="rendered")return{still:{slug:e,creative:t,n:n.n,format:a,hash:l.hash}};const o=n.outputs.find(c=>c.format===a);return o?{media:Nr(e,t,n.n,o)}:null}function UT(e,t){return t?t.state==="needs-render"?t.hash?{still:{slug:e,creative:t.slug,n:t.version,format:t.format,hash:t.hash}}:null:t.state!=="ready"||!t.file?null:{media:Nr(e,t.slug,t.version,{format:t.format,file:t.file,width:t.width,height:t.height,preview:null})}:null}const op=()=>{try{return localStorage.getItem($c)??""}catch{return""}},_T=e=>{try{localStorage.setItem($c,e)}catch{}},qT=1200;function VT(e){const t=V(),[n,a]=i.useState(!1);return s.jsx(rt,{open:e.open,onClose:e.onClose,label:t.web.storePack.export.title({title:e.title}),width:qT,dismissible:!n,children:e.open?s.jsx(KT,{...e,onBusy:a}):null})}function KT({onClose:e,slug:t,creative:n,version:a,group:r,locales:l,untranslated:o=[],needsReview:c=[],formats:d,presets:m,labels:u,entry:h,subtitleHashes:f,onBusy:x}){const p=V(),g=p.web.storePack.export,b=rs(),v=xt(),[y,w]=i.useState(op),j=y!==""&&y===op(),S=!!(l&&l.extra.length>0),[k,E]=i.useState(()=>l?Object.fromEntries([l.primary,...l.extra].map(be=>[be,!0])):{}),[N,C]=i.useState(!1),[R,P]=i.useState(null),[z,O]=i.useState(null),T=i.useId(),[W,Z]=i.useState(null),[A,L]=i.useState(null);i.useEffect(()=>{if(!r)return;let be=!0;return Promise.resolve().then(()=>q.groupExportPlan(t,n)).then(Fe=>{be&&Z(Fe.items)},()=>{}),Promise.resolve().then(()=>q.storePackGroupFiles(t,n)).then(Fe=>{be&&L(Fe)},Fe=>{be&&L({error:pe(Fe)})}),()=>{be=!1}},[r,t,n]);const _=r?A&&"formats"in A?A:null:{formats:d??[],labels:u},X=i.useMemo(()=>_?.formats??[],[_?.formats]),ae=_?.labels,K=i.useMemo(()=>LT(X,{presets:m,...ae?{labels:ae}:{},locale:b,deviceName:be=>p.web.storePack.devices[be],thumbOf:be=>r?UT(t,W?.find(Fe=>Fe.format===be)):BT(t,n,h,be,f)}),[X,m,ae,b,p,r,t,n,W,h,f]),I=i.useMemo(()=>K.flatMap(be=>be.devices.flatMap(Fe=>Fe.rows.map(je=>je.id))),[K]),[H,de]=i.useState(()=>new Set),J=I.filter(be=>!H.has(be)),se=(be,Fe)=>de(je=>IT(je,be,Fe)),[U,te]=i.useState(null),G=zT(K,U);i.useEffect(()=>{x(N)},[N,x]),i.useEffect(()=>()=>x(!1),[x]);const re=i.useRef(!0);i.useEffect(()=>(re.current=!0,()=>{re.current=!1}),[]);const oe=l&&S?[l.primary,...l.extra].filter(be=>k[be]):[],Ne=J.length*(S?oe.length:1),Q=y.trim()!==""&&!N&&Ne>0,Re=async()=>{P(null);try{const be=await v?.pickFolder(g.pickTitle,y.trim()||void 0);be&&w(be)}catch(be){P(pe(be))}},Ue=async()=>{if(!Q)return;const be=y.trim();P(null),C(!0);try{const Fe={destination:be,...S?{locales:oe}:{},...J.length<I.length?{formats:J}:{}},je=await(r?q.exportStorePackGroup(t,n,Fe):q.exportStorePack(t,n,a,Fe));if(!re.current)return;_T(be),O(je)}catch(Fe){if(!re.current)return;const je=Fe.code;P(je==="not-store-pack"?g.notAPack:g.failed({detail:gv(Fe,p)}))}finally{re.current&&C(!1)}},is=s.jsxs("div",{className:"ms-exp-head",children:[s.jsxs("div",{className:"ms-exp-titles",children:[s.jsx("h2",{children:g.heading}),s.jsx("span",{className:"ms-exp-sub",children:r?g.subGroup:g.sub({n:a})})]}),s.jsx($,{variant:"ghost",icon:!0,"aria-label":p.common.close,disabled:N,onClick:e,children:s.jsx(F,{name:"close",size:13,strokeWidth:1.6})})]});if(z){const be=z.written.length===0,Fe=z.rendered?.reduce((he,Ke)=>he+Ke.formats.length,0)??0,je=Pt()?p.web.exportUi.showInFinder:p.web.exportUi.showInFolder;return s.jsxs("div",{className:"ms-exp ms-spx",children:[is,s.jsxs("div",{className:"ms-exp-done ms-sp-result",role:be?"alert":"status",children:[be?s.jsx("span",{className:"ms-sp-mark ms-bad","aria-hidden":"true",children:s.jsx(F,{name:"warn",size:22,strokeWidth:2})}):s.jsx("span",{className:"ms-exp-done-mark",ref:he=>{he&&ti(he)},children:s.jsx(F,{name:"check",size:24,strokeWidth:2.2})}),s.jsx("b",{children:be?g.noneWritten:g.writtenTitle({count:z.written.length})}),s.jsx("span",{className:"ms-exp-path",children:z.folder}),Fe>0?s.jsx("span",{className:"ms-sp-note",children:g.rendered({count:Fe})}):null,z.written.length>0?s.jsx("ul",{className:"ms-sp-files","aria-label":g.writtenTitle({count:z.written.length}),children:z.written.map(he=>s.jsx("li",{children:he},he))}):null,z.failed.length>0?s.jsxs("div",{className:"ms-sp-failed",children:[s.jsx("b",{children:g.failedTitle({count:z.failed.length})}),s.jsx("ul",{className:"ms-sp-files ms-bad","aria-label":g.failedTitle({count:z.failed.length}),children:z.failed.map(he=>s.jsx("li",{children:g.reason(he)},he.file))})]}):null,z.notInPack?.length?s.jsxs("div",{className:"ms-sp-failed",children:[s.jsx("b",{children:g.notInPack({count:z.notInPack.length})}),s.jsx("ul",{className:"ms-sp-files","aria-label":g.notInPack({count:z.notInPack.length}),children:z.notInPack.map(he=>s.jsx("li",{children:he},he))})]}):null,s.jsxs("div",{className:"ms-exp-done-actions",children:[v?s.jsxs($,{variant:"outline",onClick:()=>{Du(v,z.folder,[]).catch(he=>P(pe(he)))},children:[s.jsx(F,{name:"folder",size:14}),je]}):null,s.jsx($,{variant:"ink",onClick:e,children:g.finish})]}),R?s.jsx("p",{role:"alert",className:"ms-exp-error",children:R}):null]})]})}const Qe=be=>be==="appstore"?p.variants.storePack.appStore:p.variants.storePack.googlePlay,gs=(be,Fe)=>{const je=g.size({width:be.width,height:be.height});return be.kind==="shots"?Fe?`${g.shots({count:be.rows.length})} · ${je}`:g.shots({count:be.rows.length}):be.kind==="video"?g.video({size:je}):g.image({size:je})},As=K.flatMap(be=>be.devices.map(Fe=>Fe.key)),hs=be=>{if(be.key!=="ArrowDown"&&be.key!=="ArrowUp")return;const Fe=be.target.closest(".ms-spx-item")?.dataset.item;if(!Fe)return;be.preventDefault();const je=DT(As,Fe,be.key==="ArrowDown"?1:-1);be.currentTarget.querySelector(`.ms-spx-item[data-item="${je}"]`)?.focus()},Oe=S&&l?s.jsxs("div",{className:"ms-spx-langs",role:"group","aria-label":g.languages,children:[s.jsx("span",{className:"ms-spx-langs-title",children:g.languages}),[l.primary,...l.extra].map(be=>{const Fe=be===l.primary?g.original({language:Js(be,b)}):Js(be,b);return s.jsxs("label",{className:"ms-exp-lang",children:[s.jsx(Rn,{on:!!k[be],label:Fe,disabled:N,onChange:je=>E(he=>({...he,[be]:je}))}),s.jsx("span",{children:Fe}),o.includes(be)?s.jsx("span",{className:"ms-sp-untr",children:g.notTranslated}):c.includes(be)?s.jsx("span",{className:"ms-sp-untr",children:g.needsReview}):null]},be)})]}):null;return s.jsxs("div",{className:"ms-exp ms-spx ms-spx-pick",children:[is,r&&!_?A&&"error"in A?s.jsx("p",{className:"ms-exp-error ms-exp-empty",role:"alert",children:p.web.exportUi.groupLoadFailed({detail:A.error})}):s.jsx("p",{className:"ms-exp-empty",role:"status",children:p.web.exportUi.groupLoading}):I.length>0&&G?s.jsxs("div",{className:"ms-spx-body",children:[s.jsxs("nav",{className:"ms-spx-nav","aria-label":g.nav,onKeyDown:hs,children:[K.map(be=>{const Fe=be.devices.flatMap(Ke=>Ke.rows.map(we=>we.id)),je=ip(Fe,H),he=Qe(be.store);return s.jsxs("div",{className:"ms-spx-store",children:[s.jsxs("label",{className:"ms-spx-storehead",children:[s.jsx(Rn,{on:je.on,mixed:je.mixed,label:he,disabled:N,onChange:Ke=>se(Fe,Ke)}),s.jsx("span",{className:"ms-spx-mark","aria-hidden":"true",children:s.jsx(en,{channel:be.store==="appstore"?"appstore":"googleplay",size:20})}),s.jsx("span",{className:"ms-spx-store-name",children:he}),s.jsxs("span",{className:"ms-spx-count",children:[je.n,"/",je.of]})]}),be.devices.map(Ke=>{const we=ip(Ke.rows.map(We=>We.id),H),ze=Ke.key===G.key;return s.jsxs("button",{type:"button",className:le("ms-spx-item",ze&&"ms-on"),"data-item":Ke.key,"aria-current":ze?"true":void 0,onClick:()=>te(Ke.key),children:[s.jsxs("span",{className:"ms-spx-item-text",children:[s.jsx("span",{className:"ms-spx-item-name",children:Ke.label}),s.jsx("span",{className:"ms-spx-item-meta",children:gs(Ke,!1)})]}),s.jsxs("span",{className:"ms-spx-item-count",children:[we.n,"/",we.of]})]},Ke.key)})]},be.store)}),Oe,s.jsx("p",{className:"ms-spx-total",children:g.selectedOf({n:J.length,of:I.length})})]}),s.jsxs("div",{className:"ms-spx-pane",children:[s.jsxs("div",{className:"ms-spx-pane-head",children:[s.jsx("h3",{children:G.label}),s.jsx("span",{className:"ms-spx-pane-meta",children:gs(G,!0)}),s.jsx("span",{className:"ms-grow"}),s.jsx("button",{type:"button",className:"ms-spx-link",disabled:N,onClick:()=>se(G.rows.map(be=>be.id),!0),children:g.selectAll}),s.jsx("button",{type:"button",className:"ms-spx-link",disabled:N,onClick:()=>se(G.rows.map(be=>be.id),!1),children:g.selectNone})]}),s.jsx("div",{className:"ms-spx-grid",role:"group","aria-label":g.files,style:{"--spx-cols":OT(G)},children:G.rows.map(be=>s.jsx(WT,{row:be,name:G.single?be.label:g.fileOf({group:G.label,file:be.label}),excluded:g.excluded,on:!H.has(be.id),disabled:N,onToggle:Fe=>se([be.id],Fe)},be.id))})]})]}):s.jsx("p",{className:"ms-exp-empty",children:g.noFiles}),r&&!_||!(I.length>0&&G)?Oe:null,N||R?s.jsx("div",{className:"ms-spx-status",children:N?s.jsxs("div",{className:"ms-exp-progress",children:[s.jsx("span",{children:g.running}),s.jsx("div",{className:"ms-progress ms-indet",role:"progressbar","aria-label":g.running,children:s.jsx("i",{})})]}):s.jsx("span",{role:"alert",className:"ms-exp-error ms-sp-error",children:R})}):null,s.jsxs("div",{className:"ms-spx-foot",children:[s.jsx("span",{className:"ms-exp-dest-label",id:T,children:g.saveTo}),s.jsx("div",{className:"ms-spx-dest",children:v?s.jsxs("div",{className:"ms-exp-folder","aria-labelledby":T,children:[s.jsx(F,{name:"folder",size:14}),s.jsx("span",{className:le("ms-exp-path",!y&&"ms-faint"),children:y||g.noFolder}),j?s.jsx("span",{className:"ms-exp-last",children:g.lastUsed}):null]}):s.jsx(ms,{"aria-label":g.folder,value:y,disabled:N,placeholder:g.placeholder,spellCheck:!1,onChange:be=>w(be.target.value),onKeyDown:be=>{be.key==="Enter"&&Ue()}})}),v?s.jsx($,{variant:"outline",size:"lg",disabled:N,onClick:()=>{Re()},children:g.choose}):null,s.jsx($,{size:"lg",variant:"ghost",disabled:N,onClick:e,children:g.cancel}),s.jsx($,{size:"lg",variant:"ink",loading:N,disabled:!Q,onClick:()=>{Ue()},children:g.run({count:Ne})})]})]})}function WT({row:e,name:t,excluded:n,on:a,disabled:r,onToggle:l}){const o=e.thumb;return s.jsxs("button",{type:"button",className:le("ms-spx-tile",!a&&"ms-off"),"aria-pressed":a,"aria-label":t,title:e.label,disabled:r,onClick:()=>l(!a),style:{"--spx-a":e.aspect},children:[s.jsxs("span",{className:"ms-spx-thumb",children:[o&&"still"in o?s.jsx(Mc,{still:o.still}):o?o.media.video?s.jsx("video",{src:o.media.src,muted:!0,preload:"metadata"}):s.jsx("img",{src:o.media.src,alt:""}):null,s.jsx("span",{className:"ms-spx-badge",title:a?void 0:n,children:a?s.jsx(F,{name:"check",size:14,strokeWidth:2.6}):null})]}),s.jsx("span",{className:"ms-spx-file-name",children:e.label})]})}const Ki=e=>e==="translated"?"translate":e==="muted"?"muted":"original";function HT({slug:e,creative:t,n,locale:a,instanceId:r,formatLabel:l,composition:o,row:c,voiceReason:d,busy:m=!1,onSaved:u}){const h=V(),f=h.web.languages,x=rs(),p=i.useMemo(()=>Hj(o),[o]),[g,b]=i.useState(null),[v,y]=i.useState(null),[w,j]=i.useState({}),[S,k]=i.useState({}),[E,N]=i.useState({}),[C,R]=i.useState(Ki(c?.voice)),[P,z]=i.useState(!1),[O,T]=i.useState(null),[W,Z]=i.useState(!1),A=i.useId(),L=c?.hash??null;i.useEffect(()=>{let G=!0;if(y(null),L===null){b(null),j({}),k({}),N({}),R("original");return}return Promise.resolve().then(()=>q.getLocalization(e,t,n,a,r)).then(re=>{G&&(b(re),j(Object.fromEntries(Object.entries(re.overlay.texts).map(([oe,Ne])=>[oe,Ne.text]))),k(Object.fromEntries(Object.entries(re.overlay.params).map(([oe,Ne])=>[oe,Ne.text]))),N(Object.fromEntries(Object.entries(re.overlay.fit).map(([oe,Ne])=>[oe,Math.round(Ne*100)]))),R(Ki(re.voice)))}).catch(re=>{G&&y(pe(re))}),()=>{G=!1}},[e,t,n,a,r,L]);const _=new Set(g?.stale??c?.stale??[]),ae={problems:g?.problems??c?.problems??[],...g?.issues??c?.issues?{issues:g?.issues??c?.issues}:{}},K=g?.overlay,I=i.useMemo(()=>{const G={},re=K?.texts??{};for(const oe of p.texts){const Ne=(w[oe.clipId]??"").trim()===""?null:w[oe.clipId],Q=re[oe.clipId]?.text??null;Ne!==Q&&((G.texts??={})[oe.clipId]=Ne)}for(const oe of p.params){const Ne=(S[oe.key]??"").trim()===""?null:S[oe.key],Q=K?.params[oe.key]?.text??null;Ne!==Q&&((G.params??={})[oe.key]=Ne)}for(const oe of p.texts){const Ne=E[oe.clipId],Q=K?.fit[oe.clipId];Ne!==void 0&&(Q!==void 0&&Math.round(Q*100)!==Ne)&&w[oe.clipId]!==void 0&&re[oe.clipId]&&((G.fit??={})[oe.clipId]=Ne/100)}return C!=="translate"&&C!==Ki(g?.voice??c?.voice)&&(G.voice=C),G},[p,w,S,E,C,K,g,c]),H=Object.keys(I).length>0,de=i.useCallback(async()=>{z(!0),T(null),Z(!1);try{const G=await q.saveLocalization(e,t,n,a,r,I);b(G),j(Object.fromEntries(Object.entries(G.overlay.texts).map(([re,oe])=>[re,oe.text]))),k(Object.fromEntries(Object.entries(G.overlay.params).map(([re,oe])=>[re,oe.text]))),N(Object.fromEntries(Object.entries(G.overlay.fit).map(([re,oe])=>[re,Math.round(oe*100)]))),R(Ki(G.voice)),Z(!0),u?.(G)}catch(G){T(G instanceof lt&&G.code==="localization-busy"?f.busy:pe(G))}finally{z(!1)}},[e,t,n,a,r,I,u,f.busy]),J=(G,re,oe)=>{const Ne=re?FN(ae,re):[];return oe?_.has(G)?{tone:"warn",text:f.rowStale,own:Ne}:Ne.length?{tone:"warn",text:f.rowOverflow,own:Ne}:{tone:"ok",text:f.rowOk,own:Ne}:{tone:"neutral",text:f.rowNotTranslated,own:Ne}},se=c?.noScript??[],U=G=>Gr(p.texts.find(re=>re.clipId===G)??p.voices.find(re=>re.clipId===G)??{clipId:G}),te=PN(ae,p.texts);return s.jsxs("section",{className:"ms-lt","aria-labelledby":A,children:[s.jsxs("div",{className:"ms-lt-head",children:[s.jsx("b",{id:A,children:f.tableTitle({language:Js(a,x),format:l})}),s.jsx(it,{label:f.voiceLabel,value:C,onChange:R,disabled:m||!c,options:[{value:"translate",label:f.voiceTranslate,disabled:c?.voice!=="translated",title:c?.voice==="translated"?void 0:d?to(d,h):f.voiceTranslateFromPanel},{value:"original",label:f.voiceOriginal},{value:"muted",label:f.voiceMuted}]})]}),v?s.jsx("p",{role:"alert",className:"ms-lt-error",children:v}):null,te.length?s.jsx("ul",{className:"ms-lt-general","aria-label":f.problemsLabel,children:te.map(G=>s.jsx("li",{children:G},G))}):null,p.texts.length+p.params.length===0?s.jsx("p",{className:"ms-lt-empty",children:f.nothingToTranslate}):s.jsxs("table",{className:"ms-lt-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{scope:"col",children:f.colSource}),s.jsx("th",{scope:"col",children:f.colTranslation}),s.jsx("th",{scope:"col",children:f.colStatus}),s.jsx("th",{scope:"col",children:f.colFit})]})}),s.jsxs("tbody",{children:[p.texts.map(G=>{const re=Gr(G),oe=!!K?.texts[G.clipId]||(w[G.clipId]??"").trim()!=="",Ne=J(G.clipId,G,!!K?.texts[G.clipId]),Q=E[G.clipId]??100;return s.jsxs("tr",{"data-clip":G.clipId,className:le(Ne.own.length>0&&"ms-lt-over",_.has(G.clipId)&&"ms-lt-stale"),children:[s.jsxs("th",{scope:"row",className:"ms-lt-src",children:[s.jsx("span",{className:"ms-lt-name",children:re}),s.jsx("span",{className:"ms-lt-text",children:G.text})]}),s.jsxs("td",{children:[s.jsx(nn,{rows:2,"aria-label":f.translationOf({clip:re}),value:w[G.clipId]??"",disabled:m,"aria-invalid":Ne.own.length>0||void 0,onChange:Re=>j(Ue=>({...Ue,[G.clipId]:Re.target.value}))}),Ne.own.map(Re=>s.jsx("p",{role:"alert",className:"ms-lt-inline",children:Re},Re))]}),s.jsx("td",{children:s.jsx(Qs,{tone:Ne.tone,children:Ne.text})}),s.jsxs("td",{className:"ms-lt-fit",children:[oe?s.jsx(cl,{label:f.fitOf({clip:re}),value:Q,min:70,max:100,step:5,valueText:`${Q}%`,disabled:m,onChange:Re=>N(Ue=>({...Ue,[G.clipId]:Re}))}):null,oe?s.jsxs("span",{className:"ms-lt-fit-value","aria-hidden":"true",children:[Q,"%"]}):null]})]},G.clipId)}),p.params.map(G=>{const re=G.label??G.key,oe=J(G.key,null,!!K?.params[G.key]);return s.jsxs("tr",{"data-param":G.key,className:le(_.has(G.key)&&"ms-lt-stale"),children:[s.jsxs("th",{scope:"row",className:"ms-lt-src",children:[s.jsx("span",{className:"ms-lt-name",children:re}),s.jsx("span",{className:"ms-lt-text",children:G.text})]}),s.jsx("td",{children:s.jsx(nn,{rows:2,"aria-label":f.translationOf({clip:re}),value:S[G.key]??"",disabled:m,onChange:Ne=>k(Q=>({...Q,[G.key]:Ne.target.value}))})}),s.jsx("td",{children:s.jsx(Qs,{tone:oe.tone,children:oe.text})}),s.jsx("td",{})]},G.key)})]})]}),se.length?s.jsxs("div",{className:"ms-lt-noscript",role:"note",children:[s.jsx("b",{children:f.noScriptTitle}),s.jsx("ul",{children:se.map(G=>s.jsx("li",{children:f.noScriptItem({clip:U(G)})},G))})]}):null,g?.warnings?.length?s.jsx("ul",{className:"ms-lt-warnings","aria-label":f.warningsLabel,children:g.warnings.map(G=>s.jsx("li",{children:G},G))}):null,s.jsxs("div",{className:"ms-lt-foot",children:[O?s.jsx("span",{role:"alert",className:"ms-lt-error",children:O}):W?s.jsx("span",{role:"status",className:"ms-lt-saved",children:f.saved}):s.jsx("span",{}),s.jsx($,{variant:"ink",size:"sm",loading:P,disabled:!H||m||P,onClick:()=>{de()},children:f.save})]})]})}function GT(e){const t=V();return s.jsx(rt,{open:e.open,onClose:e.onClose,label:t.web.languages.title,width:880,children:e.open?s.jsx(ZT,{...e}):null})}const XT=e=>{const t=e.filter(r=>r.kind!=="none");if(t.length===0)return{kind:"none"};const n=t.reduce((r,l)=>r+(l.kind==="stale"?l.count:l.kind==="both"?l.stale:0),0),a=t.reduce((r,l)=>r+(l.kind==="problems"?l.count:l.kind==="both"?l.problems:0),0);return n&&a?{kind:"both",stale:n,problems:a}:n?{kind:"stale",count:n}:a?{kind:"problems",count:a}:{kind:"ok"}};function ZT({onClose:e,slug:t,creative:n,detail:a,version:r,presets:l,live:o,onChanged:c}){const d=V(),m=d.web.languages,u=rs(),h=Ht(a.creative.brief),f=Sc(),x=Cc(),p=a.creative.brief.formatLabels,g=i.useMemo(()=>(r.compositions??[]).map(I=>I.format),[r]),b=I=>xn(pt(l,I),I,u,p),v=r.localizations??[],y=I=>v.filter(H=>H.locale===I),w=TN(a.creative.brief,f,x),[j,S]=i.useState({}),[k,E]=i.useState({}),[N,C]=i.useState({}),[R,P]=i.useState(null),[z,O]=i.useState(!1),[T,W]=i.useState(null),A=Object.values(o.jobs).filter(I=>I.key===a.jobKey&&I.kind==="localize").some(I=>I.state==="queued"||I.state==="running"),L=Object.values(o.approvals).filter(I=>I.projectSlug===t&&I.creativeSlug===n),_=I=>{const H=N[I];return H||(y(I).find(se=>se.voice!=="original")?.voice==="muted"?"muted":w===null?"translate":"original")};if(!h)return null;const X=h.extra.filter(I=>j[I]??!0),ae=g.filter(I=>k[I]??!0),K=async()=>{O(!0),W(null);try{await q.localize(t,n,r.n,{locales:X,...ae.length!==g.length?{formats:ae}:{},voice:Object.fromEntries(X.map(I=>[I,_(I)]))}),Pe.show(m.started({count:X.length}),{tone:"ok"})}catch(I){W(I instanceof lt&&I.code==="locale-not-in-brief"?m.notInBrief:pe(I))}finally{O(!1)}};return s.jsxs("div",{className:"ms-lp",children:[s.jsxs("div",{className:"ms-lp-head",children:[s.jsxs("div",{className:"ms-lp-titles",children:[s.jsx("h2",{children:m.title}),s.jsx("span",{className:"ms-lp-sub",children:m.sub({n:r.n,primary:Js(h.primary,u)})})]}),s.jsx($,{variant:"ghost",icon:!0,"aria-label":d.common.close,onClick:e,children:s.jsx(F,{name:"close",size:13,strokeWidth:1.6})})]}),g.length===0?s.jsx("p",{className:"ms-lp-note",children:m.noCompositions({n:r.n})}):s.jsxs(s.Fragment,{children:[g.length>1?s.jsxs("div",{className:"ms-lp-formats",role:"group","aria-label":m.formatsLabel,children:[s.jsx("span",{className:"ms-cap",children:m.formatsLabel}),g.map(I=>s.jsxs("label",{className:"ms-lp-format",children:[s.jsx(Rn,{on:k[I]??!0,label:b(I),disabled:A,onChange:H=>E(de=>({...de,[I]:H}))}),s.jsx("span",{children:b(I)})]},I))]}):null,s.jsx("ul",{className:"ms-lp-list",children:h.extra.map(I=>{const H=y(I),de=XT(g.map(Ne=>SN(H.find(Q=>Q.instanceId===Ne)))),J=RN(H),se=w??null,U=se??(J==="declined"||J==="failed"?J:null),te=_(I),G=Js(I,u),re=H.flatMap(Ne=>Ne.noScript??[]),oe=`ms-lp-voice-${I}`;return s.jsxs("li",{className:"ms-lp-lang","data-locale":I,children:[s.jsxs("div",{className:"ms-lp-line",children:[s.jsx(Rn,{on:j[I]??!0,label:m.pick({language:G}),disabled:A,onChange:Ne=>S(Q=>({...Q,[I]:Ne}))}),s.jsx("b",{className:"ms-lp-name",children:G}),s.jsx(Qs,{tone:de.kind==="ok"?"ok":de.kind==="none"?"neutral":"warn",children:CN(de,d)}),s.jsx(it,{className:"ms-lp-voice",label:m.voiceFor({language:G}),value:te,disabled:A,onChange:Ne=>C(Q=>({...Q,[I]:Ne})),describedBy:U?oe:void 0,options:[{value:"translate",label:m.voiceTranslate,disabled:se!==null,...se?{title:to(se,d)}:{}},{value:"original",label:m.voiceOriginal},{value:"muted",label:m.voiceMuted}]})]}),U?s.jsxs("p",{id:oe,className:"ms-lp-reason",children:[s.jsx(F,{name:"warn",size:12}),U===se?m.voiceUnavailable({reason:to(U,d)}):m.voiceFellBack({reason:to(U,d)})]}):null,re.length?s.jsxs("p",{className:"ms-lp-reason",children:[s.jsx(F,{name:"warn",size:12}),m.noScriptCount({count:re.length})]}):null,s.jsx("div",{className:"ms-lp-review",children:g.map(Ne=>{const Q=H.find(Ue=>Ue.instanceId===Ne),Re=R?.locale===I&&R.instanceId===Ne;return s.jsx($,{size:"sm",variant:Re?"ink":"outline","aria-pressed":Re,disabled:!Q,title:Q?void 0:m.statusNone,onClick:()=>P(Re?null:{locale:I,instanceId:Ne}),children:m.review({format:b(Ne)})},Ne)})}),R?.locale===I?s.jsx(JT,{slug:t,creative:n,version:r,locale:I,instanceId:R.instanceId,formatLabel:b(R.instanceId),row:H.find(Ne=>Ne.instanceId===R.instanceId),voiceReason:se,busy:A,onSaved:()=>c?.()}):null]},I)})})]}),L.length?s.jsx("div",{className:"ms-lp-cards","aria-label":m.confirmations,children:L.map(I=>s.jsx(ri,{approval:I},I.id))}):null,A&&L.length===0?s.jsx("p",{className:"ms-lp-note",role:"status",children:m.working}):null,T?s.jsx("p",{role:"alert",className:"ms-lp-error",children:T}):null,s.jsxs("div",{className:"ms-lp-foot",children:[s.jsx($,{variant:"ghost",onClick:e,children:d.common.close}),s.jsx($,{variant:"ink",loading:z,disabled:A||z||X.length===0||ae.length===0||g.length===0,onClick:()=>{K()},children:m.translate({count:X.length})})]})]})}function JT({slug:e,creative:t,version:n,locale:a,instanceId:r,formatLabel:l,row:o,voiceReason:c,busy:d,onSaved:m}){const u=V().web.languages,[h,f]=i.useState(null),[x,p]=i.useState(null);return i.useEffect(()=>{let g=!0;return f(null),p(null),Promise.resolve().then(()=>q.getEditorComposition(e,t,n.n,r)).then(b=>{g&&f(b.composition)}).catch(b=>{g&&p(pe(b))}),()=>{g=!1}},[e,t,n.n,r]),x?s.jsx("p",{role:"alert",className:"ms-lp-error",children:x}):h?s.jsx("div",{className:le("ms-lp-table"),children:s.jsx(HT,{slug:e,creative:t,n:n.n,locale:a,instanceId:r,formatLabel:l,composition:h,row:o,voiceReason:c,busy:d,onSaved:m})}):s.jsx("p",{className:"ms-lp-note",role:"status",children:u.loading})}function Bm({slug:e,creative:t,detail:n,version:a,presets:r,live:l,onChanged:o,readOnly:c=null}){const d=V().web.languages,[m,u]=i.useState(!1),h=n?Ht(n.creative.brief):null;return!n||!h||h.extra.length===0||!a?null:s.jsxs(s.Fragment,{children:[s.jsx(pn,{label:c??d.button,whenHidden:".ms-bar-label",children:s.jsxs($,{variant:"outline",className:"ms-cv-languages ms-fold-2","aria-label":d.button,disabled:c!==null,...c!==null?{title:c}:{},onClick:()=>u(!0),children:[s.jsx(F,{name:"globe",size:13,strokeWidth:1.7}),s.jsx("span",{className:"ms-bar-label",children:d.button})]})}),s.jsx(GT,{open:m&&c===null,onClose:()=>u(!1),slug:e,creative:t,detail:n,version:a,presets:r,live:l,...o?{onChanged:o}:{}})]})}function YT(e,t,n){return n!==t?e.some(a=>a.lang===n)?n:null:e.some(a=>a.lang===t)?t:e.find(a=>a.origin==="speech"&&a.timing.locale===void 0)?.lang??null}function QT(e){const t=V();return s.jsx(rt,{open:e.open,onClose:e.onClose,label:t.web.languages.renderTitle,width:560,children:e.open?s.jsx(eR,{...e}):null})}function eR({onClose:e,slug:t,creative:n,plan:a,locales:r,rowsOf:l,labelOf:o,subtitles:c=[],drawsSubtitles:d=!1}){const m=V(),u=m.web.languages,h=rs(),f=P=>a.every(([z,O])=>O.every(T=>l(z).some(W=>W.locale===P&&W.instanceId===T))),[x,p]=i.useState(()=>({[r.primary]:!0,...Object.fromEntries(r.extra.map(P=>[P,f(P)]))})),[g,b]=i.useState(!1),[v,y]=i.useState(null),[w,j]=i.useState(null),S=i.useRef(new Set),k=i.useId(),E=r.extra.filter(P=>x[P]&&f(P)),N=!!x[r.primary],C=P=>d&&YT(c,r.primary,P)!==null?s.jsx("span",{className:"ms-lp-muted",children:u.renderWithSubtitles}):null,R=async P=>{b(!0),y(null);const z=P&&w?w.versions:a,O=[],T=[];let W=0,Z=null;for(const[A,L]of z)try{N&&!S.current.has(A)&&(await q.renderVersion(t,n,A,L),S.current.add(A),W+=L.length),E.length&&(await q.renderVersion(t,n,A,L,{locales:E,force:P}),W+=L.length*E.length)}catch(_){_ instanceof lt&&_.code==="localization-needs-force"&&!P?(O.push([A,L]),T.push(..._.problems??[_.message])):Z??=pe(_)}if(b(!1),O.length?j({versions:O,list:[...new Set(T)]}):j(null),Z){y(Z);return}O.length||(Pe.show(m.web.render.started({count:W}),{tone:"ok"}),e())};return s.jsxs("div",{className:"ms-lp ms-rl",children:[s.jsxs("div",{className:"ms-lp-head",children:[s.jsxs("div",{className:"ms-lp-titles",children:[s.jsx("h2",{children:u.renderTitle}),s.jsx("span",{className:"ms-lp-sub",children:u.renderSub({formats:[...new Set(a.flatMap(([,P])=>P.map(o)))].join(", ")})})]}),s.jsx($,{variant:"ghost",icon:!0,"aria-label":m.common.close,onClick:e,children:s.jsx(F,{name:"close",size:13,strokeWidth:1.6})})]}),s.jsxs("div",{role:"group","aria-label":u.renderLanguages,className:"ms-rl-list",children:[s.jsxs("label",{className:"ms-lp-format",children:[s.jsx(Rn,{on:N,label:u.renderOriginal({language:Js(r.primary,h)}),disabled:g,onChange:P=>p(z=>({...z,[r.primary]:P}))}),s.jsx("span",{children:u.renderOriginal({language:Js(r.primary,h)})}),C(r.primary)]}),r.extra.map(P=>{const z=f(P);return s.jsxs("label",{className:"ms-lp-format",children:[s.jsx(Rn,{on:z&&!!x[P],label:Js(P,h),disabled:g||!z,onChange:O=>p(T=>({...T,[P]:O}))}),s.jsx("span",{children:Js(P,h)}),z?C(P):s.jsx("span",{className:"ms-lp-muted",children:u.statusNone})]},P)})]}),w?s.jsxs("div",{className:"ms-rl-refused",role:"alert","aria-labelledby":k,children:[s.jsx("b",{id:k,children:u.needsForceTitle}),s.jsx("ul",{children:w.list.map(P=>s.jsx("li",{children:P},P))})]}):null,v?s.jsx("p",{role:"alert",className:"ms-lp-error",children:v}):null,s.jsxs("div",{className:"ms-lp-foot",children:[s.jsx($,{variant:"ghost",onClick:e,disabled:g,children:m.common.cancel}),w?s.jsx($,{variant:"ink",loading:g,onClick:()=>{R(!0)},children:u.renderAnyway}):s.jsx($,{variant:"ink",loading:g,disabled:g||!N&&E.length===0,onClick:()=>{R(!1)},children:u.renderAction})]})]})}const bd=[],wl=new Map,fu=new Set,sR=e=>(fu.add(e),()=>{fu.delete(e)}),tR=(e,t)=>`${e}/${t}`;function nR(e){const t=i.useSyncExternalStore(sR,()=>wl.get(e)??bd,()=>wl.get(e)??bd),n=i.useCallback(a=>{const r=a(wl.get(e)??bd);r.length?wl.set(e,r):wl.delete(e);for(const l of fu)l()},[e]);return[t,n]}function Um(e,t,n){const[a,r]=nR(tR(e,n?n.host:t)),l=n?.letter??null,o=i.useCallback(h=>l===null||(h.pin.variant??"a")===l,[l]),c=i.useMemo(()=>l===null?a:a.filter(o),[a,l,o]),d=i.useMemo(()=>l===null?[]:a.filter(h=>!o(h)).map(h=>h.pin),[a,l,o]),m=i.useCallback(h=>r(f=>{if(l===null)return h(f);const x=h(f.filter(o)).map(p=>p.pin.variant===l?p:{...p,pin:{...p.pin,variant:l}});return[...f.filter(p=>!o(p)),...x]}),[r,l,o]),u=i.useCallback(h=>r(f=>f.filter(x=>!h.includes(x.pin))),[r]);return{stored:c,setStored:m,others:d,drop:u}}const aR=e=>new Date(e).toDateString()===new Date().toDateString();function lb(){const e=rs();return t=>ca(e,t,aR(t)?Wr:{day:"numeric",month:"short",...Wr})}function _m({slug:e,creative:t,states:n,labelOf:a,resumeFrom:r,onChanged:l,onError:o,groupPick:c}){const d=V(),m=d.web.formatVersions,u=d.web.canvas.versions,h=i.useRef(new AbortController);i.useEffect(()=>{const v=new AbortController;return h.current=v,()=>v.abort()},[]);const f=i.useRef(new Set),[,x]=i.useState(0),p=(v,y)=>{y?f.current.add(v):f.current.delete(v),h.current.signal.aborted||x(w=>w+1)},g=(v,y,w,j,S=o)=>{if(j!==void 0){if(f.current.has(j))return;p(j,!0)}o(null);const k=h.current.signal;Promise.resolve().then(()=>pv(v,iu(k))).then(()=>{k.aborted||(w?.(),l())}).catch(E=>{k.aborted||(Zr(E)==="hashes-pending"?Pe.show(m.errors.hashesPending):S(xv(E,d,y)))}).finally(()=>{j!==void 0&&p(j,!1)})},b=(v,y)=>{o(null);const w=h.current.signal;Promise.resolve().then(()=>q.restoreVersion(e,t,v)).then(()=>{w.aborted||(l(),y())}).catch(j=>{w.aborted||o(u.actionFailed({detail:pe(j)}))})};return{star:(v,y,w)=>{const j=a(v),S=n[v]?.follows;g(()=>c?c(v,y):q.setExportPick(e,t,v,y),{label:j,n:y,primary:S?a(S):void 0},()=>{Pe.show(m.starToast({n:y,label:j}),{tone:"ok"}),w?.done?.()},v,w?.fail)},resetStar:v=>{const y=a(v);g(()=>c?c(v,null):q.setExportPick(e,t,v,null),{label:y},()=>Pe.show(m.resetToast({label:y}),{tone:"ok"}),v)},pending:v=>f.current.has(v),link:(v,y)=>{const w=a(v),j=n[v]?.linkable.find(S=>S.primary===y)?.reason;g(()=>q.setFormatLink(e,t,v,y),{label:w,primary:a(y),reason:j},()=>Pe.show(m.linked({label:w,primary:a(y)}),{tone:"ok"}))},unlink:v=>{const y=a(v);g(()=>q.setFormatLink(e,t,v,null),{label:y},()=>Pe.show(m.unlinked({label:y}),{tone:"ok"}))},restart:v=>{const y=r;b(v,()=>Pe.show(u.restarted({n:v}),{tone:"ok",action:y!==null&&y!==v?{label:u.undo,run:()=>b(y,()=>{})}:void 0}))},reveal:v=>{o(null),Promise.resolve().then(()=>q.revealVersion(e,t,v)).catch(y=>o(u.actionFailed({detail:pe(y)})))}}}function qm(e){const n=V().web.formatVersions,a=i.useRef(null),r=e.buttonRef??a,[l,o]=i.useState(!1),c=e.state.star.version;if(c===null&&e.state.history.length===0)return null;const d=c??e.state.history.at(-1);return s.jsxs(s.Fragment,{children:[s.jsxs("button",{ref:r,type:"button",className:le(e.bar?"ms-btn ms-outline ms-fvb-bar":"ms-vbadge ms-star","ms-fvb",l&&"ms-open",e.className),"aria-haspopup":"dialog","aria-expanded":l,"aria-label":n.badge({label:e.label,n:d}),onClick:m=>{m.stopPropagation(),o(u=>!u)},children:[e.unstarred||c===null?"":"★ ","v",d,e.bar?s.jsxs("span",{className:"ms-fvb-count ms-bar-label","aria-hidden":"true",children:["· ",n.count({n:e.state.history.length})]}):null,s.jsx(F,{name:"chevron",size:e.bar?11:10})]}),e.shown!==null&&e.shown!==d?s.jsx("span",{className:"ms-fvb-viewing",children:n.viewing({n:e.shown})}):null,s.jsx(ot,{open:l,onClose:()=>o(!1),anchor:r,placement:"bottom-start",width:320,label:n.title({label:e.label}),children:s.jsx(rR,{...e,close:()=>o(!1)})})]})}function rR({slug:e,creative:t,label:n,state:a,versions:r,shown:l,resumeFrom:o,labelOf:c,actions:d,busy:m,onView:u,onCompare:h,subtitleHashes:f,close:x}){const p=V(),g=p.web.formatVersions,b=p.web.canvas.versions,v=rs(),y=lb(),w=r.at(-1)?.n??0,j=a.star.version,S=a.history.length?Gj(r,a.id):[],k=[...a.history].reverse().flatMap(P=>{const z=r.find(W=>W.n===P),O=z?.outputs.find(W=>W.format===a.id)??null,T=S.find(W=>W.n===P)?.last??P;return z&&(O||z.compositions?.some(W=>W.format===a.id))?[{ver:z,out:O,last:T}]:[]}),E=(P,z,O)=>P!==null&&P>=z&&P<=O,N=l!==null&&l!==ja(r,a,o??w),C=d.pending(a.id),R=a.linkable.filter(P=>P.ok);return s.jsxs("div",{className:"ms-vmenu ms-fvpop",children:[s.jsxs("div",{className:"ms-vmenu-head",children:[s.jsx("b",{children:g.title({label:n})}),s.jsx("span",{className:"ms-vmenu-count",children:a.star.manual&&a.star.newer!==null?s.jsx(Qs,{tone:"accent",children:g.newer({n:a.star.newer})}):k.length})]}),s.jsx("p",{className:"ms-vmenu-explain ms-fvpop-only",children:g.onlyChanges}),a.starFileMissing&&j!==null?s.jsxs("p",{className:"ms-vmenu-explain ms-fvpop-warn",children:[s.jsx(F,{name:"warn",size:12}),g.fileMissing({n:j})]}):null,s.jsx("div",{className:"ms-vmenu-list",children:k.map(({ver:P,out:z,last:O})=>{const T=P.compositions?.find(J=>J.format===a.id),W=T&&rc(P,a.id,f)!=="rendered"?{slug:e,creative:t,n:P.n,format:a.id,hash:T.hash}:null,Z=!W&&z?Nr(e,t,P.n,z):null,A=P.request.trim()||b.fromBrief,L=E(j,P.n,O),_=E(l,P.n,O),X=E(a.defaultVersion,P.n,O),ae=L?a.star.manual?g.pickedByYou:g.automatic:X&&a.star.manual?g.automatic:null,K=Xj(r,a.id,P.n),I=O>P.n?g.unchangedUntil({last:O}):null,H=P.usage?p.web.usage.tokens({count:ia(v,_n(P.usage.tokens))}):null,de=z&&z.width>0&&z.height>0?`${z.width} / ${z.height}`:void 0;return s.jsxs("div",{"data-row":"",className:le("ms-fvpop-row",_&&"ms-on"),children:[s.jsxs("button",{type:"button",className:"ms-vmenu-row","aria-pressed":_,"aria-label":[g.viewRow({n:P.n,when:y(P.createdAt),note:A}),I,H,ae===g.automatic?g.autoTip:null].filter(Boolean).join(" · "),onClick:()=>{u(P.n),x()},children:[s.jsx("span",{className:le("ms-vmenu-thumb",de&&"ms-fit"),style:de?{aspectRatio:de}:void 0,"aria-hidden":"true",children:W?s.jsx(Mc,{still:W}):Z?Z.video?s.jsx("video",{src:Z.src,muted:!0,preload:"metadata"}):s.jsx("img",{src:Z.src,alt:""}):s.jsx(F,{name:"video",size:14})}),s.jsxs("span",{className:"ms-vmenu-text",children:[s.jsxs("span",{className:"ms-vmenu-line",children:[s.jsx("b",{title:I??void 0,children:I?g.range({n:P.n,last:O}):`v${P.n}`}),s.jsx("span",{className:"ms-vmenu-when",children:y(P.createdAt)}),ae?s.jsx("span",{className:"ms-fvpop-auto",title:ae===g.automatic?g.autoTip:void 0,children:s.jsx(Qs,{tone:L?"accent":void 0,children:ae})}):null,K?s.jsx(Qs,{tone:"warn",children:b.incomplete}):null,s.jsx(ar,{tokens:P.usage?_n(P.usage.tokens):null,className:"ms-vmenu-tokens"})]}),s.jsx("span",{className:"ms-vmenu-note ms-clamp2",title:A,children:A})]})]}),s.jsx("button",{type:"button",className:le("ms-fvpop-star",L&&"ms-on"),"aria-pressed":L,disabled:C&&!L,"aria-busy":C||void 0,"aria-label":L?g.starred({n:j}):g.star({n:P.n}),title:L?g.starred({n:j}):g.star({n:P.n}),onClick:()=>{L||d.star(a.id,P.n)},children:s.jsx(F,{name:"star",size:14,fill:L})})]},P.n)})}),N?s.jsx("p",{className:"ms-vmenu-explain",children:b.restartNote({n:l})}):null,R.length&&!m?s.jsxs("div",{className:"ms-fvpop-links",children:[s.jsx("p",{className:"ms-vmenu-explain",children:g.linkHint}),R.map(P=>s.jsxs($,{size:"sm",variant:"outline",onClick:()=>{x(),d.link(a.id,P.primary)},children:[s.jsx(F,{name:"link",size:13}),g.linkTo({primary:c(P.primary)})]},P.primary))]}):null,k.length>=2||N||a.star.manual?s.jsxs("div",{className:"ms-vmenu-foot",children:[k.length>=2?s.jsx($,{size:"sm",className:"ms-grow",onClick:()=>{x(),h()},children:b.compare}):null,N?s.jsx($,{size:"sm",className:"ms-grow",onClick:()=>{x(),d.restart(l)},children:b.restart}):null,a.star.manual?s.jsx($,{size:"sm",className:"ms-grow",title:g.autoTip,loading:C,onClick:()=>d.resetStar(a.id),children:g.resetAuto}):null]}):null]})}function Vm({label:e,primary:t,short:n,primaryStar:a,actions:r,follower:l,busy:o,missing:c}){const d=V().web.formatVersions,m=i.useRef(null),[u,h]=i.useState(!1),f=!!c&&a!==null;return s.jsxs(s.Fragment,{children:[s.jsxs("button",{ref:m,type:"button",className:le("ms-chip ms-fv-linkchip",u&&"ms-on"),"aria-haspopup":"dialog","aria-expanded":u,"aria-label":[d.linkedMenu({primary:t}),f?d.followerMissingShort:null].filter(Boolean).join(" · "),title:f?d.followerMissing({primary:t,n:a}):void 0,onClick:x=>{x.stopPropagation(),h(p=>!p)},children:[s.jsx(F,{name:f?"warn":"link",size:11,className:f?"ms-fv-linkchip-warn":void 0}),s.jsx("span",{className:"ms-fv-linkchip-text",children:d.linkedTo({primary:n??t})})]}),s.jsx(ot,{open:u,onClose:()=>h(!1),anchor:m,placement:"bottom-start",width:280,label:d.linkedTo({primary:t}),children:s.jsxs("div",{className:"ms-fvlink",children:[s.jsx("p",{children:d.followsNote({label:e,primary:t})}),a!==null?s.jsx("span",{className:"ms-fvlink-star",children:d.followsStar({primary:t,n:a})}):null,f?s.jsxs("p",{className:"ms-fvpop-warn ms-fvlink-warn",role:"note",children:[s.jsx(F,{name:"warn",size:12}),d.followerMissing({primary:t,n:a})]}):null,s.jsx($,{size:"sm",variant:"outline",disabled:o,onClick:()=>{h(!1),r.unlink(l)},children:d.unlink})]})})]})}function Km({slug:e,creative:t,versions:n,resumeFrom:a,actions:r,open:l,onClose:o,anchor:c}){const d=V(),m=d.web.canvas.versions,u=rs(),h=lb(),f=n.at(-1)?.n??0,x=a??f,[p,g]=i.useState(x);i.useEffect(()=>{l&&g(x)},[l]);const b=p!==x,v=o;return s.jsx(s.Fragment,{children:s.jsx(ot,{open:l,onClose:v,anchor:c,placement:"bottom-end",width:320,children:s.jsxs("div",{className:"ms-vmenu",role:"dialog","aria-label":m.title,children:[s.jsxs("div",{className:"ms-vmenu-head",children:[s.jsx("b",{children:m.title}),s.jsx("span",{className:"ms-vmenu-count",children:n.length})]}),s.jsx("div",{className:"ms-vmenu-list",children:[...n].reverse().map(y=>{const w=y.outputs[0],j=w?null:y.compositions?.[0],S=j?{slug:e,creative:t,n:y.n,format:j.format,hash:j.hash}:null,k=w?Nr(e,t,y.n,w):null,E=y.request.trim()||m.fromBrief,N=y.n===p,C=y.usage?d.web.usage.tokens({count:ia(u,_n(y.usage.tokens))}):null;return s.jsxs("button",{type:"button","data-row":"",className:le("ms-vmenu-row",N&&"ms-on"),"aria-pressed":N,"aria-label":[m.timelineRow({n:y.n,when:h(y.createdAt),note:E}),C].filter(Boolean).join(" · "),onClick:()=>g(y.n),children:[s.jsx("span",{className:"ms-vmenu-thumb","aria-hidden":"true",children:S?s.jsx(Mc,{still:S}):k?k.video?s.jsx("video",{src:k.src,muted:!0,preload:"metadata"}):s.jsx("img",{src:k.src,alt:""}):s.jsx(F,{name:"image",size:14})}),s.jsxs("span",{className:"ms-vmenu-text",children:[s.jsxs("span",{className:"ms-vmenu-line",children:[s.jsxs("b",{children:["v",y.n]}),s.jsx("span",{className:"ms-vmenu-when",children:h(y.createdAt)}),y.status==="incomplete"?s.jsx(Qs,{tone:"warn",children:m.incomplete}):null,s.jsx(ar,{tokens:y.usage?_n(y.usage.tokens):null,className:"ms-vmenu-tokens"})]}),s.jsx("span",{className:"ms-vmenu-note ms-clamp2",title:E,children:E})]})]},y.n)})}),b?s.jsx("p",{className:"ms-vmenu-explain",children:m.restartNote({n:p})}):null,s.jsxs("div",{className:"ms-vmenu-foot",children:[b?s.jsx($,{size:"sm",className:"ms-grow",onClick:()=>{v(),r.restart(p)},children:m.restart}):s.jsx("span",{className:"ms-grow"}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":Pt()?m.showInFinder:m.showInFolder,title:Pt()?m.showInFinder:m.showInFolder,onClick:()=>{v(),r.reveal(p)},children:s.jsx(F,{name:"folder",size:14})})]})]})})})}function Wm(e,t,n,a){const r=V(),l=i.useRef(void 0);i.useEffect(()=>{if(!e)return;const o=l.current;l.current=t,!(o===void 0||t===null||o!==null&&t<=o||!n)&&(Pe.show(r.web.canvas.versionReady({n:t}),{tone:"ok"}),ti(a.current))},[e,t,n,r,a])}function lR(e,t,n){const[a,r]=i.useState({}),l=[...new Set(n)].sort((o,c)=>o-c).join(",");return i.useEffect(()=>{if(!l)return;let o=!0;const c=new Map,d=(u,h,f)=>{window.clearTimeout(c.get(u)),c.set(u,window.setTimeout(()=>{o&&f()},h))},m=(u,h)=>{Promise.resolve().then(()=>q.getPinFrames(e,t,u)).then(f=>{if(!o)return;r(p=>({...p,[u]:Object.fromEntries(f.frames.map(g=>[g.file,g.url]))}));const x=f.expiresAt?Date.parse(f.expiresAt):Number.NaN;Number.isFinite(x)&&d(u,Fm(x),()=>m(u,0))},()=>{o&&h<Wv&&d(u,Yr(h),()=>m(u,h+1))})};for(const u of l.split(",").map(Number))m(u,0);return()=>{o=!1,c.forEach(u=>window.clearTimeout(u))}},[e,t,l]),a}function Hm(e,t,n){const a=`${t}/${lc(n)}`;let r=0;for(const[l,o]of Object.entries(e))(l===a||l.startsWith(`${a}~`))&&(r+=o);return r}const cp=e=>e.state==="queued"||e.state==="running";function Gm(e,t,n,a){const r=a?.variants,l=r&&!r.orphan?r:null,o=i.useMemo(()=>l?l.group.members.map(x=>x.slug):[n],[l,n]),c=!!l?.single,d=i.useMemo(()=>{if(!l||!a)return[];const x=a.jobKey.slice(0,a.jobKey.length-n.length),p=Object.values(e.jobs);return l.group.members.filter(g=>c||g.slug!==n).flatMap(g=>{const b=p.filter(y=>y.key===`${x}${g.slug}`),v=b.find(cp)??[...b].sort((y,w)=>w.createdAt.localeCompare(y.createdAt))[0];return v?[{job:v,live:e.events[v.id]??[],variant:g.letter}]:[]})},[l,a,n,e.jobs,e.events,c]),m=l?.single?.groupJobKey??null,u=i.useMemo(()=>{if(!m)return;const x=Object.values(e.jobs).filter(p=>p.key===m);return x.find(cp)??[...x].sort((p,g)=>g.createdAt.localeCompare(p.createdAt))[0]},[m,e.jobs]),h=l?.letter??Bl(n),f=l?.host??null;return i.useMemo(()=>({self:h,memberJobs:d,shows:x=>x.projectSlug===t&&x.creativeSlug!==null&&o.includes(x.creativeSlug),single:c,groupJob:u,pinScope:c&&f?{host:f,letter:h}:null}),[h,d,t,o,c,u,f])}function dp({open:e,onClose:t,bases:n,onAdd:a}){const r=V(),l=r.web.variantGroup,[o,c]=i.useState(""),[d,m]=i.useState("brief"),[u,h]=i.useState(!1),[f,x]=i.useState(null),p=[{value:"brief",label:l.addBaseBrief},...n.map(b=>({value:b.slug,label:l.addBaseOf({letter:It(b.letter),n:b.version})}))],g=async()=>{if(u)return;h(!0),x(null);const b=n.find(v=>v.slug===d);try{await a(o.trim()||null,b?{slug:b.slug,version:b.version}:null),c(""),m("brief")}catch(v){x(l.addFailed({detail:v instanceof Error?v.message:String(v)}))}finally{h(!1)}};return s.jsx(rt,{open:e,onClose:t,label:l.addTitle,width:460,dismissible:!u,children:s.jsxs("form",{className:"ms-vdlg",onSubmit:b=>{b.preventDefault(),g()},children:[s.jsx("h2",{children:l.addTitle}),s.jsx("label",{htmlFor:"ms-vadd-dir",children:l.addDirection}),s.jsx(ms,{id:"ms-vadd-dir",value:o,maxLength:_o,placeholder:l.directionPlaceholder,onChange:b=>c(b.target.value)}),s.jsx("p",{className:"ms-vdlg-hint",children:l.directionAuto}),n.length>0?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-vdlg-lbl",children:l.addBase}),s.jsx(At,{label:l.addBase,value:d,options:p,onChange:m})]}):null,f?s.jsx("p",{role:"alert",className:"ms-vdlg-err",children:f}):null,s.jsxs("div",{className:"ms-vdlg-actions",children:[s.jsx($,{type:"button",variant:"ghost",onClick:t,disabled:u,children:r.common.cancel}),s.jsx($,{type:"submit",variant:"ink",loading:u,children:l.addSubmit})]})]})})}function iR({open:e,onClose:t,letter:n,initial:a,onSave:r}){const l=V(),o=l.web.variantGroup,[c,d]=i.useState(a),[m,u]=i.useState(!1),[h,f]=i.useState(null),x=async()=>{if(!m){u(!0),f(null);try{await r(c.trim())}catch(p){f(o.directionFailed({detail:p instanceof Error?p.message:String(p)}))}finally{u(!1)}}};return s.jsx(rt,{open:e,onClose:t,label:`${o.editDirection} · ${It(n)}`,width:460,dismissible:!m,children:s.jsxs("form",{className:"ms-vdlg",onSubmit:p=>{p.preventDefault(),x()},children:[s.jsxs("h2",{children:[o.editDirection," · ",It(n)]}),s.jsx("label",{htmlFor:"ms-vdir",children:o.directionOf({letter:It(n)})}),s.jsx(ms,{id:"ms-vdir",value:c,maxLength:_o,placeholder:o.directionPlaceholder,onChange:p=>d(p.target.value)}),s.jsx("p",{className:"ms-vdlg-hint",children:o.directionLimit({max:_o})}),h?s.jsx("p",{role:"alert",className:"ms-vdlg-err",children:h}):null,s.jsxs("div",{className:"ms-vdlg-actions",children:[s.jsx($,{type:"button",variant:"ghost",onClick:t,disabled:m,children:l.common.cancel}),s.jsx($,{type:"submit",variant:"ink",loading:m,children:o.directionSave})]})]})})}function oR({open:e,onClose:t,slug:n,rows:a,label:r,formats:l,onPick:o}){const c=V(),d=c.web.variantGroup,m=u=>{const h=r(u.format);return u.source==="pick"?d.finalPick({format:h,variant:It(u.variant),n:u.n}):u.variant!==null&&u.n!==null?d.finalDefaultFrom({format:h,variant:It(u.variant),n:u.n}):d.finalDefault({format:h})};return s.jsx(rt,{open:e,onClose:t,label:d.finalSelection,width:760,children:s.jsxs("div",{className:"ms-vfinal",children:[s.jsxs("div",{className:"ms-vfinal-head",children:[s.jsx("h2",{children:d.finalSelection}),s.jsx("button",{type:"button",className:"ms-vfinal-close","aria-label":c.common.close,onClick:t,children:s.jsx(F,{name:"close",size:14})})]}),s.jsx("p",{className:"ms-vfinal-hint",children:d.chooserHint}),a===null?s.jsx("p",{className:"ms-vfinal-empty",role:"status",children:c.web.exportUi.groupLoading}):a.length===0?s.jsx("p",{className:"ms-vfinal-empty",children:d.finalEmpty}):s.jsx("ul",{className:"ms-vfinal-list","aria-label":d.finalSelection,children:a.map(u=>{const h=l.find(f=>f.format===u.format);return s.jsxs("li",{className:"ms-vfinal-format",children:[s.jsx("p",{className:"ms-vfinal-row","data-source":u.source,children:m(u)}),h&&h.options.length?s.jsx("div",{className:"ms-vfinal-options",role:"group","aria-label":h.label,children:h.options.map(f=>{const x=u.variant===f.letter,p=x&&u.source==="pick",g=d.chooserPick({format:h.label,variant:It(f.letter),n:f.n??0});return s.jsxs("button",{type:"button",className:le("ms-vfinal-option",x&&"ms-current",p&&"ms-on"),"aria-pressed":p,"aria-label":g,title:g,disabled:f.n===null||f.follows,onClick:()=>{f.n!==null&&o(f.slug,u.format,p?null:f.n)},children:[s.jsx(dR,{slug:n,thumb:f.thumb,width:h.width,height:h.height}),s.jsxs("span",{className:"ms-vfinal-name",children:[s.jsx("span",{className:"ms-vcard-letter",children:It(f.letter)}),s.jsx("span",{className:"ms-vfinal-dir",children:f.name??d.letterLabel({letter:It(f.letter)})})]}),s.jsxs("span",{className:"ms-vfinal-meta",children:[f.n!==null?s.jsxs("span",{className:"ms-vbadge",children:["v",f.n]}):null,p?s.jsxs("span",{className:"ms-vfinal-tag ms-on",children:[s.jsx(F,{name:"star",size:11,fill:!0}),d.chosen]}):x?s.jsx("span",{className:"ms-vfinal-tag",children:d.chooserDefaultTag}):null]})]},f.letter)})}):s.jsx("p",{className:"ms-vfinal-empty",children:d.chooserNone})]},u.format)})})]})})}const cR=140;function dR({slug:e,thumb:t,width:n,height:a}){const{storyboard:r}=ci({slug:e,creative:t?.creative??"",n:t?.n??null,format:t?.format??"",hash:t?.hash??null,enabled:!!t?.hash}),l=Rc(r),o=l?{src:l.url,video:!1}:t?.out?Nr(e,t.creative,t.n,t.out):null;return s.jsx("span",{className:"ms-vfinal-thumb","aria-hidden":"true",children:s.jsx("span",{className:"ms-vfinal-pic",style:{aspectRatio:`${n} / ${a}`,width:`min(100%, ${Math.round(cR*n/a)}px)`},children:o?o.video?s.jsx("video",{src:o.src,muted:!0,playsInline:!0,preload:"metadata"}):s.jsx("img",{src:o.src,alt:"",draggable:!1}):null})})}function up({label:e,variant:t,n,picked:a,pending:r,onToggle:l}){const o=V().web.variantGroup,c=a?o.starUsed({label:e,variant:t,n}):o.starUse({label:e,variant:t,n});return s.jsxs("button",{type:"button",className:le("ms-vstar",a&&"ms-on"),"aria-pressed":a,"aria-label":c,title:c,disabled:r,onClick:d=>{d.stopPropagation(),l()},onDoubleClick:d=>d.stopPropagation(),children:[s.jsx(F,{name:"star",size:12,fill:a}),s.jsx("span",{className:"ms-vstar-text","aria-hidden":"true",children:a?o.chosen:o.choose})]})}function uR(e,t,n,a,r){const[l,o]=i.useState({}),c=t?t.members.filter(m=>m.slug!==n&&!a.includes(m.letter)).map(m=>m.slug):[],d=c.map(m=>`${m}:${r[`${e}/${m}`]??0}`).join("|");return i.useEffect(()=>{if(c.length===0){o(u=>Object.keys(u).length?{}:u);return}let m=!0;for(const u of c)Promise.resolve().then(()=>q.getCreative(e,u)).then(h=>{m&&o(f=>({...f,[u]:h}))}).catch(()=>{m&&o(h=>{if(!(u in h))return h;const{[u]:f,...x}=h;return x})});return()=>{m=!1}},[e,d]),l}function mR(){const e=V(),t=e.web.variantGroup,n=e.web.canvas.state;return a=>{switch(a.kind){case"discarded":return t.discarded;case"missing":return t.missing;case"needs":return n.needs;case"waiting":return a.reason?t.waitReasons[a.reason]:e.web.creatives.queued;case"working":return n.working;case"failed":return e.web.status.error;case"stopped":return e.web.status.interrupted;case"ready":return e.web.status.ready;case"incomplete":return e.web.status.incomplete;case"draft":return e.web.status.draft}}}function hR({member:e,state:t,focused:n,discardBlock:a,hasVersions:r,busy:l,actions:o,removal:c,width:d,hero:m,children:u}){const h=V(),f=h.web.variantGroup,x=mR(),[p,g]=i.useState(!1),b=i.useRef(null),v=i.useRef(null),y=c!==void 0&&e.letter!=="a",w=Rm(c?.project??"",e.slug,c?.onDone),{load:j}=w;i.useEffect(()=>{p&&y&&j()},[p,y,j]);const S=i.useId(),k=e.letter.toUpperCase(),E=a==="running"?f.discardRefused.running:a==="last-active"?f.discardRefused.lastActive:null,N=e.status==="discarded",C=t.kind==="missing",R=T=>{const W=[...v.current?.querySelectorAll('[role="menuitem"]')??[]],Z=W.indexOf(document.activeElement),A=T.key==="ArrowLeft"||T.key==="ArrowRight"?null:Ma(T.key,Z<0?0:Z,W.length);A!==null&&(T.preventDefault(),W[A]?.focus())},P=T=>()=>{g(!1),T()},z=t.kind==="needs"||t.kind==="failed"||t.kind==="stopped"||t.kind==="missing"?"warn":t.kind==="ready"?"ok":"neutral",O=tu(e.direction);return s.jsxs("section",{className:le("ms-vcard",n&&"ms-on",N&&"ms-discarded",C&&"ms-missing"),"aria-label":f.letterLabel({letter:k}),"data-variant":e.letter,style:{width:d},children:[s.jsxs("div",{className:"ms-vcard-head",children:[s.jsxs("button",{type:"button",className:le("ms-vrow-title",n&&"ms-on"),"aria-pressed":n,"aria-label":`${f.letterLabel({letter:k})}${e.direction?` · ${e.direction}`:""}`,title:e.direction??f.noDirection,disabled:C,onClick:o.onFocus,children:[s.jsx("span",{className:"ms-vcard-letter","aria-hidden":"true",children:k}),s.jsx("span",{className:"ms-vrow-dir",children:O??f.letterLabel({letter:k})})]}),N?s.jsx($,{size:"sm",variant:"outline",className:"ms-vrow-restore",disabled:l,onClick:o.onRestore,children:f.restore}):C?null:s.jsxs(s.Fragment,{children:[s.jsx($,{ref:b,size:"sm",variant:"ghost",icon:!0,className:"ms-vrow-more","aria-label":f.rowMenu({letter:k}),"aria-haspopup":"menu","aria-expanded":p,onClick:()=>g(T=>!T),children:s.jsx(F,{name:"more",size:14})}),s.jsx(ot,{open:p,onClose:()=>g(!1),anchor:b,placement:"bottom-end",width:290,children:s.jsxs("div",{ref:v,role:"menu","aria-label":f.rowMenu({letter:k}),onKeyDown:R,children:[s.jsx(dn,{"data-row":"",role:"menuitem",icon:"star","aria-disabled":!r||void 0,onClick:r?P(o.onUseForAll):void 0,children:f.useForAllFormats}),s.jsx(dn,{"data-row":"",role:"menuitem",icon:"download","aria-disabled":!r||void 0,onClick:r?P(o.onExport):void 0,children:f.exportVariant}),s.jsx(dn,{"data-row":"",role:"menuitem",icon:"edit",onClick:P(o.onEditDirection),children:f.editDirection}),s.jsx(dn,{"data-row":"",role:"menuitem",icon:"trash","aria-disabled":E?!0:void 0,"aria-describedby":E?S:void 0,onClick:E?void 0:P(o.onDiscard),children:f.discard}),E?s.jsx("p",{id:S,className:"ms-vmenu-why",role:"note",children:E}):null,y?s.jsx(Dv,{removal:w,close:()=>g(!1)}):null]})}),y?w.dialogs:null]})]}),s.jsxs("div",{className:"ms-vcard-status",children:[s.jsx(Qs,{tone:z,spinner:t.kind==="working",className:"ms-vrow-state",children:s.jsx("span",{"aria-label":f.stateLabel({letter:k}),children:x(t)})}),n?s.jsxs("span",{className:"ms-vcard-chat",title:f.inChatHint,children:[s.jsx(F,{name:"comment",size:11}),f.inChat]}):null,t.kind==="failed"||t.kind==="stopped"?s.jsxs($,{size:"sm",variant:"outline",className:"ms-vrow-retry",disabled:l,onClick:o.onRetry,children:[s.jsx(F,{name:"refresh",size:12}),h.web.creatives.tryAgain]}):null]}),e.direction&&O!==e.direction?s.jsx("p",{className:"ms-vcard-dir",title:e.direction,children:e.direction}):null,u?s.jsx("div",{className:le("ms-vcard-formats",m&&"ms-hero"),role:"group","aria-label":f.cardFormats({letter:k}),children:u}):null]})}const zr=.5,ib=2,fR=.1,mp=40,pu=(e,t,n)=>Math.min(n,Math.max(t,e));function pR(e,t,n=zr,a=ib){const r=pu(t,-mp,mp);return pu(Math.round(e*Math.exp(-r/100)*1e3)/1e3,n,a)}function xR(e,t,n,a){const r=a/n;return{left:Math.max(0,(e.left+t.x)*r-t.x),top:Math.max(0,(e.top+t.y)*r-t.y)}}function gR(e,t,n=zr,a=ib){return pu(Math.round((e+t*fR)*20)/20,n,a)}function hp(e,t=Pt()){return e.altKey||(t?!e.metaKey||e.ctrlKey:!e.ctrlKey||e.metaKey)?null:e.key==="="||e.key==="+"?"in":e.key==="-"||e.key==="_"?"out":e.key==="0"?"fit":null}let zl=null;function vR(e){return zl=e,()=>{zl===e&&(zl=null)}}function bR(e){if(zl){zl(e);return}const t=xt();if(typeof t?.zoomWindow=="function")try{Promise.resolve(t.zoomWindow(e)).catch(()=>{})}catch{}}function jR(){const e=xt();if(typeof e?.onZoom!="function")return()=>{};try{return e.onZoom(bR)}catch{return()=>{}}}const yR=400;function wR(e){const[t,n]=i.useState({route:e.creative,focus:null,all:!1,showDiscarded:!1,comment:null}),a=t.route===e.creative?t:{route:e.creative,focus:null,all:!1,showDiscarded:!1,comment:null};return s.jsx(kR,{...e,creative:a.focus??e.creative,routeCreative:e.creative,variantUi:a,onVariantUi:r=>n({...a,...r})},a.focus??"route")}function kR({slug:e,creative:t,routeCreative:n,live:a,exportNamePattern:r,onSettings:l,variantUi:o,onVariantUi:c}){const d=V(),m=ul(e,a),u=d.web.canvas,h=rs(),f=i.useContext(Mn),x=i.useRef(null);i.useEffect(()=>{vg(`${e}/${t}`)},[e,t]);const{detail:p,conversation:g,error:b,reload:v}=Mm(e,t,Hm(a.creativeTicks,e,t)),y=Gm(a,e,t,p),w=p?.variants,j=w&&!w.orphan?w:null,S=uR(e,j?.group??null,t,j?.missing??[],a.creativeTicks),[k,E]=i.useState(0),[N,C]=i.useState(null),[R,P]=i.useState(null),[z,O]=i.useState(null),T=j?j.group.members.map(M=>`${M.slug}:${a.creativeTicks[`${e}/${M.slug}`]??0}`).join("|"):"";i.useEffect(()=>{if(!j){C(null),P(null);return}let M=!0;return Promise.resolve().then(()=>q.groupExportPlan(e,t)).then(Y=>{M&&(C(Y.items),P(Y.formats??null))},()=>{M&&(C([]),P(null))}),()=>{M=!1}},[e,t,!!j,T,k]);const W=Zn({name:"creative",slug:e,creative:n}),Z=!f||Zn(f.route)===W,A=Tc(W,Z),[L,_]=i.useState([]),[X,ae]=i.useState(!1),[K,I]=i.useState(null),[H,de]=i.useState(null);i.useEffect(()=>{let M=!0;return Promise.resolve().then(()=>q.getFormats()).then(Y=>{M&&(_(Y.presets),I(Y.error),ae(!0))}).catch(Y=>{M&&(de(pe(Y)),ae(!0))}),()=>{M=!1}},[]);const J=i.useMemo(()=>p?.versions??[],[p]),se=i.useMemo(()=>Ul(p?.subtitles),[p]),U=J.at(-1)??null,te=i.useMemo(()=>p?Al(p,L):{},[p,L]),[G,re]=i.useState(()=>Gu(`${e}/${t}`)),oe=(M,Y)=>re(me=>{const Se={...me};return Y===te[M]?.star.version?delete Se[M]:Se[M]=Y,Se}),Ne=M=>re(Y=>{const me={...Y};for(const Se of Object.values(te)){if(Se.follows)continue;const Te=ja(J,Se,M);Te!==null&&(Te===Se.star.version?delete me[Se.id]:me[Se.id]=Te)}return me}),Q=i.useRef(null),[Re,Ue]=i.useState(!1);Wm(!!p,U?.n??null,Z,Q);const is=i.useMemo(()=>Object.values(a.approvals).filter(y.shows),[a.approvals,y]),Qe=i.useMemo(()=>{if(!p)return;const M=Object.values(a.jobs).filter(Y=>Y.key===p.jobKey);return M.find(Y=>Y.state==="queued"||Y.state==="running")??M.sort((Y,me)=>me.createdAt.localeCompare(Y.createdAt))[0]},[a.jobs,p]),gs=Qe?.state==="queued"||Qe?.state==="running",As=y.single?y.groupJob:Qe,hs=i.useMemo(()=>lu(Qe,te),[Qe,te]),Oe=i.useMemo(()=>!p||!X||H?[]:Yc(p.creative.brief.formats,L,J,M=>ga(te,M,G),p.creative.brief.formatLabels),[p,L,X,H,J,te,G]),[be,Fe]=i.useState(null),[je,he]=i.useState(o.comment?"comment":"select"),[Ke,we]=i.useState(o.comment);i.useEffect(()=>{o.comment&&c({comment:null})},[]);const ze=M=>{Xe(null),we(M),he("comment"),M&&Fe(M)},[We,Rs]=i.useState(1),us=p?p.creative.resumeFrom?.version??U?.n??null:null,fs=i.useCallback(M=>M.out!==null||Bn(J.find(Y=>Y.n===M.n),ga(te,M.id,G).format)!==null,[J,te,G]),fe=i.useMemo(()=>new Set(Oe.filter(M=>{const Y=ga(te,M.id,G);return fs(M)&&M.n!==null&&ja(J,te[Y.format],us)===M.n}).map(M=>M.id)),[Oe,te,G,J,us,fs]),Ge=fe.size>0,De=us!==null&&Oe.some(M=>fs(M)&&!fe.has(M.id)),{stored:os,setStored:Ze,others:vs,drop:Le}=Um(e,t,y.pinScope),ne=i.useMemo(()=>os.flatMap((M,Y)=>M.version===us?[{pin:M.pin,at:Y}]:[]),[os,us]),Ee=i.useMemo(()=>ne.map(M=>M.pin),[ne]),[Ce,Xe]=i.useState(null);i.useEffect(()=>{Ge||!p||!X||(Xe(null),he(M=>M==="comment"?"select":M))},[Ge,!!p,X]),i.useEffect(()=>{Xe(null)},[us]),i.useEffect(()=>{Xe(M=>M&&!fe.has(M.format)?null:M)},[fe]);const ue=M=>[...x.current?.querySelectorAll("[data-board]")??[]].find(Y=>Y.dataset.board===M)??null,xe=M=>{const Y=ue(M);Y?.scrollIntoView?.({block:"nearest",inline:"nearest",behavior:"smooth"}),cc(Y?.querySelector(".ms-cv-frame")??Y)},Be=(M,Y,me)=>{Fe(M),Xe(Se=>({format:M,x:Y,y:me,text:Se&&Se.index===null?Se.text:"",index:null}))},_e=M=>{const Y=Ee[M-1];if(!(!Y||us===null)){if(!fe.has(Y.format)){const me=ga(te,Y.format,G).format,Se=ja(J,te[me],us);if(Se===null)return;oe(me,Se)}Fe(Y.format),Xe({format:Y.format,x:Y.x,y:Y.y,text:Y.note??"",index:M-1}),xe(Y.format)}},ge=()=>{if(!Ce)return;const M=Ce.text.trim();if(M){if(Ce.index===null){const Y=Oe.find(Te=>Te.id===Ce.format),me=Y?.out?tr(Y.out.file):Y?.preset?.kind==="video",Se={format:Ce.format,x:Ce.x,y:Ce.y,timeSec:me?0:null,note:M};us!==null&&Ze(Te=>[...Te,{pin:Se,version:us}])}else{const Y=ne[Ce.index]?.at;Ze(me=>me.map((Se,Te)=>Te===Y?{...Se,pin:{...Se.pin,note:M}}:Se))}Xe(null),he("select"),we(null)}},qe=M=>{const Y=ne[M]?.at;Ze(me=>me.filter((Se,Te)=>Te!==Y)),Xe(me=>me&&me.index!==null?me.index===M?null:me.index>M?{...me,index:me.index-1}:me:me)};qt(x,M=>M.key==="Escape"&&!jr(M)&&!pr(M)&&(je!=="select"||Ce!==null),()=>{Xe(null),he("select"),we(null)});const[Ye,Ls]=i.useState(null),et=i.useCallback(()=>{p&&Ls(p.creative.title)},[p]);qt(x,M=>M.key==="F2"&&ui(M)&&!M.shiftKey&&!jr(M)&&!pr(M)&&!!p,et);const[bs,Us]=i.useState(null);i.useEffect(()=>{Us(null)},[p]);const Me=bs??p?.creative.title??"",ss=async M=>{Ls(null);const Y=M.trim();if(!(!p||!Y||Y===p.creative.title)){Us(Y);try{await q.updateCreative(e,t,{title:Y}),f?.catalog.refresh(),v()}catch(me){Us(null),Pe.show(u.title.saveFailed({detail:pe(me)}))}}},[Ie,ys]=i.useState(null),ns=M=>nr({id:M,preset:pt(L,M),labels:p?.creative.brief.formatLabels},h),Ys=_m({slug:e,creative:t,states:te,labelOf:ns,resumeFrom:p?.creative.resumeFrom?.version??null,onChanged:v,onError:ys,...j?{groupPick:(M,Y)=>q.setVariantPick(e,j.host,M,Y===null?null:{slug:t,version:Y})}:{}}),mt=i.useMemo(()=>Object.values(a.jobs),[a.jobs]),[Ns,ct]=i.useState(null),ls=M=>{if(p?.creative.brief.locales?.extra.length){ct(M);return}Promise.allSettled(M.map(([Y,me])=>Promise.resolve().then(()=>q.renderVersion(e,t,Y,me)))).then(Y=>{const me=Y.reduce((Ve,zs,Zs)=>Ve+(zs.status==="fulfilled"?M[Zs][1].length:0),0),Se=Y.flatMap((Ve,zs)=>Ve.status==="rejected"?[{n:M[zs][0],formats:M[zs][1],detail:pe(Ve.reason)}]:[]);if(!Se.length){Pe.show(d.web.render.started({count:me}),{tone:"ok"});return}const Te=Se.map(Ve=>`${Ve.formats.map(ns).join(", ")} v${Ve.n}`).join("; ");Pe.show(me>0?d.web.render.startedPartly({count:me,list:Te,detail:Se[0].detail}):d.web.render.startFailed({detail:Se[0].detail}))})},[Is,Hs]=i.useState(null),ee=M=>{const Y=te[M],me=Nc(Y,G[M]);if(!Y||me===null||Y.history.length<2)return;const Se=Y.history.indexOf(me),Te=Y.history[Se-1]??Y.history[Se+1];Hs({open:!0,init:Te<me?[Te,me]:[me,Te],format:M})},[as,ds]=i.useState(null),[Ks,tt]=i.useState(!1),[js,Ds]=i.useState(!1),[ht,un]=i.useState(null),[Os,gt]=i.useState(!1),[mn,Wt]=i.useState(!1),[$n,gn]=i.useState(null),[zt,Mt]=i.useState(null),[Yn,vt]=i.useState(null),St=p?.creative.brief.storePack,an=i.useMemo(()=>new Set(St?jo(St):[]),[St]),Zt=(M,Y)=>{Hl(`format:${e}/${t}/${M}`,Y.getBoundingClientRect()),Hu(`${e}/${t}`,G),Bs(es.format(e,t,M))},$t=i.useRef(!1),[rn]=i.useState(()=>performance.now());i.useLayoutEffect(()=>{if($t.current||!Oe.length||!x.current)return;$t.current=!0;const M=[...x.current.querySelectorAll(".ms-cv-board")],Y=performance.now()-rn<=yR,me=zo(`brief-panel:${e}/${t}`);if(me&&Y){const Ve=x.current.querySelector(".ms-cv-panel");Eo(Ve,me,qs.l),Gs(Ve?.querySelector(".ms-tabs")??null,{y:0,delay:qs.m}),x.current.querySelectorAll(".ms-cv-side:not(.ms-cv-panel)").forEach(zs=>{Gs(zs,{y:0,delay:.6*qs.s})}),Ud(M,{y:16,scale:.97,delay:.6*qs.s},70);return}const Se=Oe.map(Ve=>({id:Ve.id,rect:zo(`canvas:${e}/${t}/${Ve.id}`)})),Te=Y?Se.find(Ve=>Ve.rect):void 0;if(Te?.rect){const Ve=ue(Te.id)?.querySelector(".ms-cv-frame")??null;Eo(Ve,Te.rect,qs.m),M.forEach((zs,Zs)=>{zs.contains(Ve)||Gs(zs,{y:0,scale:.98,delay:80+Zs*30})}),x.current.querySelectorAll(".ms-cv-side").forEach((zs,Zs)=>{Gs(zs,{x:Zs?16:-16,y:0,delay:160})})}else Ud(M,{y:12},40)},[Oe.length]);const Jt=i.useRef(null),hn=i.useRef(null),[D,Ae]=i.useState(!1),ts=M=>{const Y=Jt.current;!Y||M.button!==1||(M.preventDefault(),hn.current={x:M.clientX,y:M.clientY,left:Y.scrollLeft,top:Y.scrollTop},M.currentTarget.setPointerCapture?.(M.pointerId),Ae(!0))},ps=M=>{const Y=Jt.current,me=hn.current;!Y||!me||(Y.scrollLeft=me.left-(M.clientX-me.x),Y.scrollTop=me.top-(M.clientY-me.y))},Cs=()=>{hn.current=null,Ae(!1)},ks=i.useRef(!1),[Ms,Bt]=i.useState({width:0,height:0}),bt=Ms.width,nt=M=>{const Y=Al(M,L);return{st:Y,bs:Yc(M.creative.brief.formats,L,M.versions,me=>ga(Y,me,{}),M.creative.brief.formatLabels)}},fn=j?Pi(j.group,o.showDiscarded).filter(M=>!j.missing.includes(M.letter)):[],Nn=M=>M.slug===t?Oe:S[M.slug]?nt(S[M.slug]).bs:[],Vn=j?Pi(j.group,o.showDiscarded).length:0,jt=j!==null&&Object.keys(j.group.picks).length>0,ha=j?.host??t,Ct=i.useMemo(()=>Q0(e,ha),[e,ha]),vn=jt?z??Ct:"all",ln=j&&vn==="chosen"&&p?(()=>{const M=Y0(R??p.creative.brief.formats,j.group,N),Y=me=>({id:me.format,preset:pt(L,me.format),out:null,labels:p.creative.brief.formatLabels,cell:me});return tS(M.chosen.map(Y),M.open.map(Y),an)})():null,Kn=ln?.map(M=>M.groups.map(Y=>Y.boards.map(me=>me.id).join(",")).join(";")).join("|")??"",Qn=j?`g:${Vn}:${vn}:${Kn}`:Oe.map(M=>`${M.id}:${M.preset?.width??0}x${M.preset?.height??0}`).join("|"),Ut=i.useRef(()=>null);Ut.current=()=>{const M=Jt.current;if(!M)return null;const Y={width:M.clientWidth,height:M.clientHeight};if(ln)return Fi(ln,Y,$i,sd);if(!j)return Fi([{groups:Uo(Oe,an),head:0}],Y,$i);const me=Kg(Vn,M.clientWidth,zr);return me===null?null:{zoom:me,all:me}},i.useLayoutEffect(()=>{const M=Jt.current;if(!M||!Oe.length)return;const Y=()=>{if(Bt(Ve=>Ve.width===M.clientWidth&&Ve.height===M.clientHeight?Ve:{width:M.clientWidth,height:M.clientHeight}),ks.current)return;const Te=Ut.current()?.zoom??null;Te!==null&&Rs(Ve=>Math.abs(Ve-Te)<1e-6?Ve:Te)};if(Y(),typeof ResizeObserver>"u")return;let me=0;const Se=new ResizeObserver(()=>{cancelAnimationFrame(me),me=requestAnimationFrame(Y)});return Se.observe(M),()=>{cancelAnimationFrame(me),Se.disconnect()}},[Qn,!!p]);const fa=M=>{ks.current=!0,Rs(M)},Sn=()=>Math.min(zr,j&&!ln?zr:Ut.current()?.all??zr),pa=M=>{if(M==="fit"){ks.current=!1;const Y=Ut.current()?.zoom??null;Y!==null&&Rs(Y),Jt.current?.scrollTo?.(0,0);return}fa(Y=>gR(Y,M==="in"?1:-1,Sn()))};qt(x,M=>hp(M)!==null&&!pr(M)&&!!p,M=>pa(hp(M)));const Fn=i.useRef(pa);Fn.current=pa;const _t=Z&&!!p;i.useEffect(()=>_t?vR(M=>Fn.current(M==="reset"?"fit":M)):void 0,[_t]);const ea=i.useRef(We);ea.current=We;const Wn=i.useRef(Sn);Wn.current=Sn;const Fa=i.useRef(null);i.useEffect(()=>{const M=Jt.current;if(!M)return;const Y=me=>{if(!me.ctrlKey)return;me.preventDefault();const Se=ea.current,Te=pR(Se,me.deltaMode===1?me.deltaY*16:me.deltaY,Wn.current());if(Te===Se)return;const Ve=M.getBoundingClientRect();Fa.current??={scroll:{left:M.scrollLeft,top:M.scrollTop},pointer:{x:me.clientX-Ve.left,y:me.clientY-Ve.top},from:Se},ea.current=Te,fa(()=>Te)};return M.addEventListener("wheel",Y,{passive:!1}),()=>M.removeEventListener("wheel",Y)},[!!p]),i.useLayoutEffect(()=>{const M=Fa.current,Y=Jt.current;if(Fa.current=null,!M||!Y)return;const me=xR(M.scroll,M.pointer,M.from,We);Y.scrollLeft=me.left,Y.scrollTop=me.top},[We]);const[dt,ya]=i.useState(!1),Hn=()=>{ya(!0);const M=fn.filter(Te=>Te.status==="active"),Y=M.filter(Te=>Te.slug===t||S[Te.slug]?.versions.length===0),me=j!==null&&Y.length>0&&(Y.length===M.length||Y.length>1),Se=Y.length===M.length?"all-active":Y.map(Te=>Te.letter);Promise.resolve().then(()=>me&&j?q.runVariants(e,j.host,{targets:Se,request:null}):q.sendCreativeTurn(e,t,{})).then(()=>{re({}),v()}).catch(Te=>Pe.show(u.generateFailed({detail:pe(Te)}))).finally(()=>ya(!1))},[Cn,Pn]=i.useState("chat"),Lt=i.useMemo(()=>RR(j?Zj(g,j.letter):g),[g,j]);if(b&&!p)return s.jsx("div",{className:"ms-cv-state",children:s.jsx(Rt,{icon:"warn",title:u.tryAgain,sub:s.jsx("span",{role:"alert",children:u.loadFailed({detail:b})}),action:s.jsxs($,{variant:"ink",onClick:v,children:[s.jsx(F,{name:"refresh",size:13}),u.tryAgain]})})});if(!p)return s.jsx("div",{className:"ms-cv-state","aria-busy":"true",children:s.jsx(Ts,{size:18,label:u.loading})});const Es=p.creative,st=U,sa=gm(p.variants),Yt=sa.discarded?d.web.variantGroup.discardedReadOnly:null,An=gs,wa=(M,Y)=>{const me=te[M];if(j){const Se=j.group.members.find(Ve=>Ve.slug===t),Te=Oe.find(Ve=>Ve.id===M)?.n??null;if(Se&&Te!==null)return ka(Se,M,Te).text}return me?.star.version!=null?`★ v${me.star.version}`:J.length?"—":Y?pm(Y):""},ut=M=>{const Y=j?.group.members.find(Se=>Se.slug===t);if(!Y||M.n===null)return{};const me=ka(Y,M.id,M.n);return{...me.source?{"data-source":me.source}:{},...me.title?{title:me.title}:{}}},Gn=M=>{const Y=te[M]?.follows;return Y?d.web.formatVersions.follows({primary:xn(pt(L,Y),Y,h,Es.brief.formatLabels)}):null},Qt=Es.brief.formats.filter(M=>te[M]&&!te[M].follows),En=J.length&&Qt.length>1?{primaries:Qt.map(M=>({id:M,label:ns(M),followers:Vo(te,M).map(ns)})),followerOf:M=>te[M]?.follows??null,groups:mm(Qt,L,Es.brief,h,d.web.formatUi.other)}:void 0,at=Bo(Oe,an);St&&!at.some(([M])=>M===Fl)&&at.push([Fl,[]]);const Xs=(()=>{const M=Uo(Oe,an),Y=Fi([{groups:M,head:0}],Ms,$i);return Qd(M,Y?.zoom??1,Y===null?null:Ms.width,void 0,Y?.cols??1)})(),xa=(M,Y)=>M.map((me,Se)=>s.jsx("div",{className:"ms-cv-line",children:me.map(Te=>Te.stack?s.jsx("div",{className:"ms-cv-stack",style:Te.cols>1?{gridTemplateColumns:`repeat(${Te.cols}, max-content)`}:void 0,children:Te.boards.map(Y)},Te.boards[0].id):Y(Te.boards[0]))},Se)),ta=M=>Ee.map((Y,me)=>({pin:Y,number:me+1})).filter(Y=>Y.pin.format===M),bn=M=>{const Y=te[M.id];if(!Y)return{badge:null,note:null};if(j&&Y.follows)return{badge:M.n===null?null:s.jsxs("span",{className:"ms-vbadge ms-vver",children:["v",M.n]}),note:Gn(M.id)};if(Y.follows){const Ve=ns(Y.follows),zs=xn(pt(L,Y.follows),Y.follows,h,Es.brief.formatLabels),Zs=te[Y.follows]?.star.version??null;return{badge:s.jsx(Vm,{label:ns(M.id),primary:Ve,short:zs,primaryStar:Zs,follower:M.id,actions:Ys,busy:An,missing:Y.starFileMissing}),note:Zs!==null?d.web.formatVersions.followsStar({primary:zs,n:Zs}):d.web.formatVersions.follows({primary:zs})}}const me=M.n!==null?J.find(Ve=>Ve.n===M.n):void 0,Se=no(me,M.id,mt,p.jobKey,se),Te=M.n!==null&&Se!==null&&Se.kind!=="queued"&&Se.kind!=="rendering";if(j){const Ve=lr(M.id);return{badge:M.n===null?null:s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"ms-vbadge ms-vver",children:["v",M.n]}),s.jsx(up,{label:ns(M.id),variant:It(j.letter),n:M.n,picked:Ve===M.n,pending:Ys.pending(M.id),onToggle:()=>{Ve===M.n?Ys.resetStar(M.id):Ys.star(M.id,M.n)}})]}),note:null}}return{badge:s.jsx(qm,{slug:e,creative:t,label:ns(M.id),state:Y,versions:J,shown:M.n,resumeFrom:Es.resumeFrom?.version??null,labelOf:ns,actions:Ys,busy:An,onView:Ve=>oe(M.id,Ve),onCompare:()=>ee(M.id),subtitleHashes:se,render:Te?{n:M.n,run:()=>ls([[M.n,[M.id]]])}:null}),note:null}};function ka(M,Y,me){const Se=N?.find(Te=>Te.format===Y);if(Se){if(Se.letter!==M.letter)return{text:`v${me}`,source:null};const Te=Se.source==="default"?Ws.finalDefaultFrom({format:ns(Y),variant:It(M.letter),n:Se.version}):void 0;return{text:`★ v${Se.version}`,source:Se.source,...Te?{title:Te}:{}}}if(N===null){const Te=j?.group.picks[Y];if(Te?.slug===M.slug&&Te.version===me)return{text:`★ v${me}`,source:"pick"}}return{text:`v${me}`,source:null}}function lr(M){const Y=j?.group.picks[M];return Y&&Y.slug===t?Y.version:null}const Ot=M=>{if(M.n===null)return null;const Y=ga(te,M.id,G).format,me=J.find(Ve=>Ve.n===M.n),Se=Bn(me,Y),Te=no(me,Y,mt,p.jobKey,se);return Se&&Te?{n:M.n,format:Y,hash:Se.hash,render:Te,onRender:()=>ls([[M.n,[Y]]])}:null},na=(M,Y)=>{const me=mo(hs,M.id)?fp(a,Qe,M.id):null;return s.jsx(Qf,{slug:e,creative:t,board:M,n:M.n,...j?{grouped:!0,card:!0}:{},tool:je==="comment"&&(Ke===null||Ke===M.id)?"comment":"select",zoom:Y??We,selected:be===M.id,rendering:!me&&mo(hs,M.id),commentable:fe.has(M.id),missing:M.n===null?U?.n??null:null,...bn(M),...me?{inProgress:!0}:{},composition:me??Ot(M),...fe.has(M.id)&&!Yt?{onComment:()=>ze(M.id)}:{},pins:fe.has(M.id)?ta(M.id):[],draft:fe.has(M.id)?Ce:null,nextNumber:Ee.length+1,onSelect:()=>{Fe(M.id),un(null)},onOpen:Se=>{je==="select"&&Zt(M.id,Se)},onPlace:(Se,Te)=>Be(M.id,Se,Te),onEditPin:_e,onDraftText:Se=>Xe(Te=>Te&&{...Te,text:Se}),onDraftCommit:ge,onDraftCancel:()=>Xe(null),onDraftDelete:()=>{Ce?.index!==null&&Ce?.index!==void 0&&qe(Ce.index)}},M.id)},Na=M=>at.filter(([Y])=>!0).map(([Y,me])=>{const Se=Te=>s.jsxs("button",{type:"button",className:le("ms-navitem ms-cv-fmt",be===Te.id&&"ms-on",Gn(Te.id)&&"ms-follower"),"aria-pressed":be===Te.id,onClick:()=>{Fe(Te.id),xe(Te.id)},children:[s.jsx(F,{name:Te.preset?.kind==="image"?"image":"video",size:14}),Gn(Te.id)?s.jsxs("span",{className:"ms-cv-fmt-text",children:[s.jsx("span",{className:"ms-navitem-label",children:hr(Te,h)}),s.jsxs("span",{className:"ms-cv-fmt-follows",children:[s.jsx(F,{name:"link",size:11}),Gn(Te.id)]})]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-navitem-label",children:hr(Te,h)}),s.jsx("span",{className:"ms-cv-fmt-side",...ut(Te),children:wa(Te.id,Te.preset)})]})]},Te.id);if(Y===Fl){const Te=Bo(me,new Set).map(([Ve,zs])=>[Ve,zs]);return s.jsxs("div",{className:"ms-cv-group ms-cv-pack",role:"group","aria-label":d.web.storePack.groupTitle,children:[s.jsxs("div",{className:"ms-cap ms-cv-group-head ms-cv-pack-head",children:[s.jsxs("span",{className:"ms-cv-pack-marks","aria-hidden":"true",children:[s.jsx(en,{channel:"appstore"}),s.jsx(en,{channel:"googleplay"})]}),s.jsx("span",{className:"ms-cv-pack-title",children:d.web.storePack.groupTitle})]}),Te.map(([Ve,zs])=>s.jsxs("div",{className:"ms-cv-subgroup",role:"group","aria-label":Ve!==""?Dn(Ve,h):d.web.formatUi.other,children:[s.jsxs("div",{className:"ms-cap ms-cv-subhead",children:[Ve!==""?s.jsx(en,{channel:da(Ve)}):null,Ve!==""?Dn(Ve,h):d.web.formatUi.other]}),zs.map(Se)]},Ve))]},Y)}return s.jsxs("div",{className:"ms-cv-group",role:"group","aria-label":Y!==""?Dn(Y,h):d.web.formatUi.other,children:[s.jsxs("div",{className:"ms-cap ms-cv-group-head",children:[Y!==""?s.jsx(en,{channel:da(Y)}):null,Y!==""?Dn(Y,h):d.web.formatUi.other]}),me.map(Se)]},Y)}),Ws=d.web.variantGroup,Et=j?.host??t,ie=M=>Y=>Pe.show(M({detail:pe(Y)})),ke=()=>{v(),f?.catalog.refresh(),E(M=>M+1)},cs=M=>M===t?p:S[M]??null,Ps=(M,Y,me)=>{Promise.resolve().then(()=>q.setVariantPick(e,Et,Y,me===null?null:{slug:M,version:me})).then(ke).catch(ie(Ws.pickFailed))},ft=M=>c({focus:M.slug===n?null:M.slug,all:!1}),Tn=M=>{if(M==="all"){c({all:!0});return}const Y=j?.group.members.find(me=>me.letter===M);Y&&ft(Y)},ir=M=>I0(a,e,M.slug),qa=M=>(cs(M.slug)?.versions.length??0)>0,aa=M=>({onFocus:()=>ft(M),onUseForAll:()=>{Promise.resolve().then(()=>q.useVariantForAll(e,Et,M.letter)).then(()=>{Pe.show(Ws.usedForAll({letter:It(M.letter)}),{tone:"ok"}),ke()}).catch(ie(Ws.useForAllFailed))},onDiscard:()=>{vt(M.letter),Promise.resolve().then(()=>q.discardVariant(e,Et,M.letter)).then(()=>{ke(),M.slug===t&&Et!==t&&c({focus:Et===n?null:Et})}).catch(ie(Ws.discardFailed)).finally(()=>vt(null))},onRestore:()=>{vt(M.letter),Promise.resolve().then(()=>q.restoreVariant(e,Et,M.letter)).then(ke).catch(ie(Ws.restoreFailed)).finally(()=>vt(null))},onExport:()=>{const Y=cs(M.slug);Y&&Mt({open:!0,detail:Y,snapshot:{versions:Y.versions,states:Al(Y,L)}})},onEditDirection:()=>gn(M),onRetry:()=>{vt(M.letter),Promise.resolve().then(async()=>q.runVariants(e,Et,{targets:[M.letter],request:Lg(await q.getConversation(e,M.slug),M.letter)})).then(ke).catch(ie(Ws.sendAllFailed)).finally(()=>vt(null))}}),B=M=>D0(M,j.missing.includes(M.letter),ir(M),cs(M.slug)?.creative.status??null),ye=(M,Y)=>{const me=ir(M),Se=j.missing.includes(M.letter),Te=Se?[]:Nn(M),Ve=Te.length===1,zs=Se?null:_s(M),Zs=H0(We,bt,Y,Te.length),on=Zs.width;return s.jsx(hR,{member:M,focused:M.slug===t,hasVersions:qa(M),busy:Yn===M.letter,actions:aa(M),removal:{project:e,onDone:cn=>{cn!=="restored"&&(M.slug===t?Bs(es.creative(e,Et)):ke())}},state:B(M),discardBlock:O0(j.group,M.letter,z0(me)),width:on,hero:Ve,children:zs?Te.map(cn=>s.jsx("div",{className:"ms-vcard-cell",style:{width:Zs.cell},children:zs(cn,Z0(cn,Zs.cell,Ve,Zs.scale))},cn.id)):null},M.letter)},He=(M,Y,me,Se,Te,Ve)=>{const zs=`${M.letter}:${Se.id}`,Zs=ga(me,Se.id,{}).format,on=Y.versions.find(Pa=>Pa.n===Se.n),cn=Se.n===null?null:Bn(on,Zs),Sa=cn?no(on,Zs,mt,Y.jobKey,Ul(Y.subtitles)):null,jn=j.group.picks[Se.id],Ln=jn?.slug===M.slug&&jn.version===Se.n,yn=Object.values(a.jobs).find(Pa=>Pa.key===Y.jobKey&&(Pa.state==="queued"||Pa.state==="running")),or=mo(lu(yn,me),Se.id),cr=or?fp(a,yn,Se.id):null;return s.jsx(Qf,{boardKey:zs,grouped:!0,card:!Ve,...Ve?{from:Ve.from}:{},slug:e,creative:M.slug,board:Se,n:Se.n,tool:"select",zoom:Te,selected:ht===zs,rendering:!cr&&or,...cr?{inProgress:!0}:{},commentable:!1,missing:Se.n===null?Y.versions.at(-1)?.n??null:null,...M.status==="active"&&Se.n!==null?{onComment:()=>c({focus:M.slug===n?null:M.slug,all:!1,comment:Se.id})}:{},badge:Se.n===null?null:s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"ms-vbadge ms-vver",children:["v",Se.n]}),me[Se.id]?.follows?null:s.jsx(up,{label:ns(Se.id),variant:It(M.letter),n:Se.n,picked:Ln,onToggle:()=>Ps(M.slug,Se.id,Ln?null:Se.n)})]}),note:me[Se.id]?.follows?d.web.formatVersions.follows({primary:xn(pt(L,me[Se.id].follows),me[Se.id].follows,h,Y.creative.brief.formatLabels)}):null,pins:[],draft:null,nextNumber:1,composition:cr??(cn&&Sa?{n:Se.n,format:Zs,hash:cn.hash,render:Sa,onRender:()=>{Promise.resolve().then(()=>q.renderVersion(e,M.slug,Se.n,[Zs])).catch(ie(d.web.render.startFailed))}}:null),onSelect:()=>{Fe(null),un(zs)},onOpen:Pa=>{Hl(`format:${e}/${M.slug}/${Se.id}`,Pa.getBoundingClientRect()),Bs(es.format(e,M.slug,Se.id))},onPlace:()=>{},onEditPin:()=>{},onDraftText:()=>{},onDraftCommit:()=>{},onDraftCancel:()=>{},onDraftDelete:()=>{}},zs)},_s=M=>{if(M.slug===t)return(Se,Te)=>na(Se,Te);const Y=S[M.slug];if(!Y)return null;const{st:me}=nt(Y);return(Se,Te)=>He(M,Y,me,Se,Te)},$s=()=>{if(!j)return null;if(vn==="chosen")return Ss();const M=Pi(j.group,o.showDiscarded);return M.map(Y=>ye(Y,M.length))},Ss=()=>{if(!j||!ln)return null;const M=Fi(ln,Ms,$i,sd),Y=(me,Se)=>{const Te=me.cell,Ve=Te.slug?j.group.members.find(yn=>yn.slug===Te.slug):void 0,zs=Ve?cs(Ve.slug):null,Zs=zs?Ve.slug===t?te:nt(zs).st:null,on=zs&&Zs&&Te.n!==null?Yc([Te.format],L,zs.versions,yn=>({format:ga(Zs,yn,{}).format,n:Te.n}),zs.creative.brief.formatLabels)[0]:void 0,cn=Ve?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-vcard-letter",children:It(Ve.letter)}),s.jsx("span",{className:"ms-vchosen-name",children:tu(Ve.direction)??Ws.letterLabel({letter:It(Ve.letter)})}),Se?s.jsxs("span",{className:"ms-vfinal-tag ms-vchosen-rule",title:Ws.chooserDefaultTag,children:[s.jsx(F,{name:"gear",size:11}),s.jsx("span",{className:"ms-vchosen-rule-text",children:Ws.chooserDefaultTag})]}):null]}):null;if(Ve&&zs&&Zs&&on)return He(Ve,zs,Zs,on,We,{from:cn});const Sa=gc(me),jn=ns(Te.format),Ln=Math.max(Math.round(Sa.width*We),um(We,!0));return s.jsxs("div",{className:"ms-cv-board ms-vchosen-empty","data-board":`${Te.letter??""}:${Te.format}`,children:[s.jsxs("div",{className:le("ms-cv-board-head",Ln<dm&&"ms-narrow-head"),style:{maxWidth:Ln},children:[s.jsx("div",{className:"ms-cv-board-line ms-cv-board-from",children:cn}),s.jsxs("div",{className:"ms-cv-board-line",children:[me.preset?s.jsx(en,{channel:da(me.preset.channel)}):null,s.jsx("b",{className:"ms-cv-board-name",title:jn,children:me.preset?hr(me,h):jn})]}),s.jsx("div",{className:"ms-cv-board-line ms-cv-board-sub"})]}),s.jsx("div",{className:"ms-cv-frame-wrap ms-vchosen-none",style:{width:Sa.width*We,height:Sa.height*We},children:Ve&&!zs&&!j.missing.includes(Ve.letter)?s.jsx(Ts,{size:14,label:d.web.canvas.loading}):s.jsx("span",{children:Ws.noVariantFile})})]},Te.format)};return ln.map((me,Se)=>{const Te=Se>0,Ve=Te?Ws.noChoiceTitle:Ws.chosenTitle,zs=me.groups.reduce((Zs,on)=>Zs+on.boards.length,0);return s.jsxs("section",{className:"ms-vchosen","aria-label":Ve,children:[s.jsxs("div",{className:"ms-vchosen-head",children:[s.jsxs("h3",{className:"ms-vchosen-title",children:[Te?null:s.jsx(F,{name:"star",size:13,fill:!0}),Ve,s.jsx("span",{className:"ms-vchosen-count",children:zs})]}),Te?s.jsx("p",{className:"ms-vchosen-hint",title:Ws.noChoiceHint,children:Ws.noChoiceHint}):null]}),xa(Qd(me.groups,M?.zoom??1,M===null?null:Ms.width,sd,M?.cols??1),Zs=>Y(Zs,Te))]},Ve)})},Ft=()=>{if(!j)return[];const M=fn.filter(Y=>Y.status==="active");return(R??Es.brief.formats).map(Y=>{const me=pt(L,Y),Se=M.flatMap(Te=>{const Ve=cs(Te.slug);if(!Ve)return[];const zs=Te.slug===t?te:nt(Ve).st,Zs=Nn(Te).find(jn=>jn.id===Y),on=Zs?.n??null,cn=ga(zs,Y,Te.slug===t?G:{}).format,Sa=on===null?null:Bn(Ve.versions.find(jn=>jn.n===on),cn);return[{letter:Te.letter,slug:Te.slug,name:tu(Te.direction),n:on,follows:!!zs[Y]?.follows,thumb:on===null?null:{creative:Te.slug,n:on,format:cn,hash:Sa?.hash??null,out:Zs?.out??null}}]});return{format:Y,label:ns(Y),width:me?.width??1,height:me?.height??1,options:Se}})},Sr=()=>{if(!j)return null;const M=(me,Se)=>Se.n===null?{text:"—",source:null}:ka(me,Se.id,Se.n),Y=(me,Se,Te)=>{const Ve=me.slug===t?Se.id:`${me.letter}:${Se.id}`,zs=me.slug===t?be===Se.id:ht===Ve;return s.jsxs("button",{type:"button",className:le("ms-navitem ms-cv-fmt",zs&&"ms-on"),"aria-pressed":zs,onClick:()=>{me.slug===t?(Fe(Se.id),un(null)):(Fe(null),un(Ve)),xe(Ve)},children:[s.jsx(F,{name:Se.preset?.kind==="image"?"image":"video",size:14}),s.jsx("span",{className:"ms-navitem-label",children:Te}),(()=>{const Zs=M(me,Se);return s.jsx("span",{className:"ms-cv-fmt-side",...Zs.source?{"data-source":Zs.source}:{},..."title"in Zs&&Zs.title?{title:Zs.title}:{},children:Zs.text})})()]},Ve)};return s.jsx(s.Fragment,{children:Pi(j.group,o.showDiscarded).map(me=>s.jsxs("div",{className:le("ms-cv-group",me.status==="discarded"&&"ms-discarded"),role:"group","aria-label":`${Ws.letterLabel({letter:It(me.letter)})}${me.direction?` · ${me.direction}`:""}`,children:[s.jsx("div",{className:"ms-cap ms-cv-group-head ms-vcol-head",title:me.direction?`${It(me.letter)} · ${me.direction}`:void 0,children:s.jsxs("span",{className:"ms-vcol-dir",children:[me.direction?`${It(me.letter)} · ${me.direction}`:It(me.letter),j.missing.includes(me.letter)?` · ${Ws.missing}`:""]})}),me.slug===t?Na():Nn(me).map(Se=>Y(me,Se,hr(Se,h)))]},me.letter))})},Ac=j?j.group.members.filter(M=>M.status==="active"&&!j.missing.includes(M.letter)).flatMap(M=>{const Y=cs(M.slug)?.versions.at(-1)?.n;return Y===void 0?[]:[{letter:M.letter,slug:M.slug,version:Y}]}):[],Lc=async(M,Y)=>{if(!j)return;const me=new Set(j.group.members.map(Ve=>Ve.letter)),Se=await q.addVariants(e,Et,{count:1,directions:[M],...Y?{baseFrom:Y}:{}}),Te=Se.variants&&!Se.variants.orphan?Se.variants.group.members.find(Ve=>!me.has(Ve.letter)):void 0;ke(),gt(!1),Te&&await q.runVariants(e,Et,{targets:[Te.letter],request:null}).catch(ie(Ws.startFailed))},pi=async(M,Y)=>{const me=await q.addVariants(e,t,{count:2,directions:[null,M],...Y?{baseFrom:Y}:{}}),Se=me.variants&&!me.variants.orphan?me.variants.group.members.find(Te=>Te.letter!=="a"):void 0;ke(),gt(!1),Se&&await q.runVariants(e,t,{targets:[Se.letter],request:null}).catch(ie(Ws.startFailed))},ml=j&&N&&R?B0(R,N):null,hl=j?s.jsxs("div",{className:"ms-vbar",role:"toolbar","aria-label":Ws.toolbarAria,children:[jt?s.jsx(it,{label:Ws.viewLabel,value:vn,className:"ms-vbar-view",options:[{value:"chosen",label:Ws.viewChosen,icon:"star"},{value:"all",label:Ws.viewAll}],onChange:M=>{O(M),eS(e,Et,M)}}):null,s.jsxs("span",{className:"ms-vbar-toggle",children:[s.jsx(Un,{size:"sm",on:o.showDiscarded,onChange:M=>c({showDiscarded:M}),label:Ws.showDiscarded}),s.jsx("span",{"aria-hidden":"true",children:Ws.showDiscarded})]}),s.jsx("span",{className:"ms-grow"}),s.jsx($,{size:"sm",variant:"outline",onClick:()=>gt(!0),children:Ws.addVariant}),s.jsxs($,{size:"sm",variant:"accent",className:"ms-vbar-final","aria-haspopup":"dialog",onClick:()=>Wt(!0),children:[s.jsx(F,{name:"star",size:13,fill:!0}),Ws.finalSelection]})]}):null,Va=j?J0(j.group,j.missing,M=>{const Y=j.group.members.find(me=>me.letter===M);return Y?B(Y).kind:"missing"}):null;return s.jsxs("div",{ref:x,className:"ms-cv",children:[A?.title?ma.createPortal(s.jsx(ER,{title:Me,renaming:Ye,onStart:et,onChange:Ls,onSave:M=>{ss(M)},onCancel:()=>Ls(null),state:s.jsxs(s.Fragment,{children:[s.jsx(TR,{status:Es.status,needs:is.length>0,working:gs}),gs&&Qe?s.jsx(ar,{tokens:Do(a,Qe.id),live:!0,partial:$l(a,Qe.id),className:"ms-cv-tokens"}):null]})}),A.title):null,A?.end?ma.createPortal(s.jsxs(s.Fragment,{children:[s.jsx(Bm,{slug:e,creative:t,detail:p,version:st??U,presets:L,live:a,onChanged:v,readOnly:Yt}),s.jsx(Dm,{jobs:mt,jobKey:p.jobKey,disabled:!st&&!j,secondary:!!j,onClick:()=>{!st&&!j||(St?Es.brief.formats.some(M=>!an.has(M))?Ds(!0):tt(!0):ds({open:!0,snapshot:{versions:J,states:te}}))}}),s.jsx(NR,{slug:e,target:j?Et:t,title:Me,onAddVariant:!j&&!w?()=>gt(!0):null,buttonRef:Q,onHistory:J.length?{letter:j?(/~([a-z])$/.exec(t)?.[1]??"a").toUpperCase():null,run:()=>Ue(!0)}:null,onRemoved:M=>{M!=="restored"&&Bs(es.project(e))}}),J.length?s.jsx(Km,{slug:e,creative:t,versions:J,resumeFrom:Es.resumeFrom?.version??null,actions:Ys,open:Re,onClose:()=>Ue(!1),anchor:Q}):null]}),A.end):null,s.jsxs("aside",{className:"ms-cv-side ms-cv-formats","aria-label":u.formatsAria,children:[s.jsxs("div",{className:"ms-cv-formats-head",children:[s.jsx("b",{children:u.formats}),s.jsx("span",{children:Oe.length})]}),j?Sr():Na()]}),s.jsxs("main",{className:"ms-cv-main","aria-label":u.canvasAria,children:[hl,s.jsxs(CR,{children:[m.state?s.jsx(vr,{slug:e,state:m.state,reload:m.reload},"integrity"):null,H?s.jsx("p",{role:"alert",className:"ms-cv-note ms-err",children:d.web.creative.formatsLoadFailed({detail:H})}):null,K?s.jsx("p",{className:"ms-cv-note",children:K}):null,w?.orphan?s.jsx("p",{className:"ms-cv-note ms-info",role:"status",children:Ws.orphanNotice}):null,Es.resumeFrom?s.jsx("p",{className:"ms-cv-note ms-info",children:d.web.creative.resumeNote({n:Es.resumeFrom.version})}):null,(Es.status==="error"||Es.status==="interrupted")&&Es.error&&!gs?s.jsx("p",{role:"alert",className:"ms-cv-note ms-err",children:Es.error}):null,st?.status==="incomplete"?s.jsxs("div",{className:"ms-cv-note",children:[s.jsx("b",{children:d.web.creative.versionIncomplete({n:st.n})}),s.jsx(im,{problems:st.problems})]}):null,Ie?s.jsx("p",{role:"alert",className:"ms-cv-note ms-err",children:Ie}):null,Va!==null?s.jsxs("div",{className:"ms-cv-note ms-info ms-vready",role:"status",children:[s.jsx(F,{name:"star",size:13}),s.jsx("b",{children:Ws.readyBanner({count:Va})}),s.jsx($,{size:"sm",variant:"outline",onClick:()=>Wt(!0),children:Ws.choose})]},"choose"):null]}),s.jsx("div",{ref:Jt,className:le("ms-cv-viewport",je==="comment"&&"ms-tool-comment",D&&"ms-grabbing"),onPointerDown:ts,onPointerMove:ps,onPointerUp:Cs,onPointerCancel:Cs,onClick:M=>{M.target.closest(".ms-cv-board")||(Xe(Y=>Y&&Y.text.trim()?Y:null),Fe(null))},children:s.jsx("div",{className:le("ms-cv-world",j&&!ln?"ms-cv-vworld":"ms-cv-lined",ln&&"ms-vchosen-world"),style:{"--cv-z":We},"aria-busy":hs==="all"||hs.size>0?!0:void 0,children:j?$s():xa(Xs,M=>na(M))})}),!J.length&&!gs?s.jsx("div",{className:"ms-cv-nothing",children:s.jsxs("div",{className:"ms-card ms-cv-nothing-card",children:[s.jsx("span",{className:"ms-cv-nothing-icon","aria-hidden":"true",children:s.jsx(F,{name:"sparkle",size:16})}),s.jsx("b",{children:u.nothingTitle}),s.jsx("p",{children:u.nothingBody}),s.jsxs($,{variant:"ink","aria-label":u.generate,loading:dt,onClick:Hn,children:[s.jsx(F,{name:"sparkle",size:13}),u.generate]})]})}):null,je==="comment"?s.jsx("div",{className:"ms-cv-hint",role:"status",children:u.commentHint}):null,De&&st&&us!==null?s.jsx("div",{className:"ms-cv-lockpill",id:"ms-cv-comment-lock",role:"status",title:u.versions.commentsOn({n:us}),children:u.versions.commentsOn({n:us})}):null]}),s.jsx("aside",{className:"ms-cv-side ms-cv-panel ms-chat-col","aria-label":u.panel,children:s.jsxs("div",{className:"ms-chat-card",children:[s.jsx(hc,{label:u.panel,value:Cn,onChange:Pn,tabs:[{value:"chat",label:u.tabs.chat},{value:"comments",label:u.tabs.comments,count:Lt.count},{value:"brief",label:u.tabs.brief}]}),Cn==="chat"?s.jsx(Ec,{slug:e,creative:t,entries:g,approvals:is,job:As,live:As?a.events[As.id]??[]:[],pins:Ee,onRemovePin:qe,onEditPin:M=>_e(M+1),formatName:ns,single:y.single,otherPins:vs,onRemoveOtherPin:M=>Le([M]),usageOf:M=>s.jsx(_h,{usage:M,billing:a.today?.billing??null}),canGenerate:J.length===0,onSent:({pins:M})=>{Le(M),re({}),v()},onSelectVersion:Ne,snapshots:a.snapshots,appliesTo:En,brief:p.creative.brief,onBriefSaved:v,queued:p.creative.queued,onQueueChanged:v,self:y.self,memberJobs:y.memberJobs,onOpenVariant:M=>{const Y=j?.group.members.find(me=>me.letter===M);Y&&ft(Y)},...j?{variants:{group:j.group,current:j.letter,all:o.all,missing:j.missing,onSelect:Tn,runAll:M=>q.runVariants(e,Et,{targets:"all-active",request:M})}}:{},versionExtra:M=>s.jsx(_h,{usage:J.find(Y=>Y.n===M)?.usage,billing:a.today?.billing??null}),versionSummary:M=>{const Y=J.find(me=>me.n===M);return Y?.origin==="editor"&&Y.request?Y.request:null},versionNote:M=>s.jsx(SR,{outputs:J.find(Y=>Y.n===M)?.outputs??[],formatLabel:ns})}):null,Cn==="comments"?s.jsx(MR,{slug:e,creative:t,sent:Lt,working:gs,formatLabel:ns,onStart:()=>ze(null)}):null,s.jsx("div",{className:"ms-cv-brief-wrap",hidden:Cn!=="brief",children:s.jsx(AR,{project:e,detail:p,presets:L,disabled:gs,readOnly:sa.host?null:Yt,formatLabel:ns,onChanged:v})})]})}),!j&&!w&&Os?s.jsx(dp,{open:!0,onClose:()=>gt(!1),onAdd:pi,bases:U?[{letter:"a",slug:t,version:U.n}]:[]}):null,j?s.jsxs(s.Fragment,{children:[s.jsx(dp,{open:Os,onClose:()=>gt(!1),bases:Ac,onAdd:Lc}),s.jsx(oR,{open:mn,onClose:()=>Wt(!1),slug:e,rows:ml,label:ns,formats:mn?Ft():[],onPick:(M,Y,me)=>Ps(M,Y,me)}),$n?s.jsx(iR,{open:!0,onClose:()=>gn(null),letter:$n.letter,initial:$n.direction??"",onSave:async M=>{await q.setVariantDirection(e,Et,$n.letter,M),gn(null),ke()}}):null,zt?s.jsx(Ho,{open:zt.open,onClose:()=>Mt(M=>M&&{...M,open:!1}),slug:e,creative:zt.detail.slug,title:zt.detail.creative.title,snapshot:zt.snapshot,presets:L,labels:zt.detail.creative.brief.formatLabels,pattern:r??So,onSettings:l,jobs:a.jobs,...Ht(zt.detail.creative.brief)?{locales:Ht(zt.detail.creative.brief)}:{},...zt.detail.subtitles?.length?{subtitles:zt.detail.subtitles}:{}}):null]}):null,Is?s.jsx(Im,{open:Is.open,onClose:()=>Hs(M=>M&&{...M,open:!1}),slug:e,creative:t,versions:J,presets:L,labels:Es.brief.formatLabels,states:te,format:Is.format,initial:Is.init,actions:Ys}):null,s.jsx(Ho,{open:!!as?.open,onClose:()=>ds(M=>M&&{...M,open:!1}),slug:e,creative:Et,title:Me,snapshot:as?.snapshot??null,...j?{group:!0}:{},presets:L,labels:Es.brief.formatLabels,pattern:r??So,onSettings:l,jobs:a.jobs,...Ht(Es.brief)?{locales:Ht(Es.brief)}:{},...!j&&p.subtitles?.length?{subtitles:p.subtitles}:{}}),St?s.jsx(PT,{open:js,onClose:()=>Ds(!1),onPack:()=>{Ds(!1),tt(!0)},onFormats:()=>{Ds(!1),ds({open:!0,snapshot:{versions:J,states:te}})}}):null,Es.brief.storePack&&(st||j)?(()=>{const M=st&&!j?IN(Es.brief.formats.filter(Y=>an.has(Y)),st,Ht(Es.brief)?.extra??[]):{untranslated:[],review:[]};return s.jsx(VT,{open:Ks,onClose:()=>tt(!1),slug:e,creative:j?Et:t,title:Me,version:st?.n??0,...j?{group:!0}:{},untranslated:M.untranslated,needsReview:M.review,presets:L,...j?{}:{formats:Jj(Es.brief,L),...Es.brief.formatLabels?{labels:Es.brief.formatLabels}:{},...st?{entry:st,subtitleHashes:se}:{}},...Ht(Es.brief)?{locales:Ht(Es.brief)}:{}})})():null,Ns&&Ht(Es.brief)?s.jsx(QT,{open:!0,onClose:()=>ct(null),slug:e,creative:t,plan:Ns,locales:Ht(Es.brief),rowsOf:M=>J.find(Y=>Y.n===M)?.localizations??[],labelOf:ns,...p.subtitles?.length?{subtitles:p.subtitles}:{},drawsSubtitles:Ns.some(([,M])=>M.some(Y=>p.formats?.find(me=>me.id===Y)?.subtitlesTrack===!0))}):null]})}function NR({slug:e,target:t,title:n,onAddVariant:a,onHistory:r,buttonRef:l,onRemoved:o}){const c=V(),d=c.web.variantGroup,m=c.web.canvas.versions;return s.jsx(Bv,{slug:e,creative:t,label:c.web.shell.moreActions,className:"ms-cv-more",variant:"ghost",buttonRef:l,onDone:o,extra:a||r?u=>s.jsxs(s.Fragment,{children:[a?s.jsx(dn,{"data-row":"",role:"menuitem",icon:"plus",onClick:()=>{u(),a()},children:d.addVariantMenu}):null,r?s.jsx(dn,{"data-row":"",role:"menuitem",icon:"clock",onClick:()=>{u(),r.run()},children:r.letter?m.historyItemVariant({letter:r.letter}):m.historyItem}):null]}):void 0})}function SR({outputs:e,formatLabel:t}){const n=rs(),a=e.flatMap(r=>(r.warnings??[]).map(l=>({format:r.format,text:dx(l,n)})));return a.length?s.jsx("ul",{className:"ms-convo-version-notes",children:a.map((r,l)=>s.jsxs("li",{children:[s.jsx(F,{name:"warn",size:12}),s.jsxs("span",{children:[s.jsx("b",{children:t(r.format)})," · ",r.text]})]},l))}):null}function fp(e,t,n){if(!t||t.kind!=="creative"||t.state!=="running")return null;const a=e.ready?.[t.id]?.[n];return a?{n:a.n,format:n,hash:a.hash,render:{kind:"none"},onRender:()=>{}}:null}function CR({children:e}){const t=(Array.isArray(e)?e:[e]).filter(Boolean);return t.length?s.jsx("div",{className:"ms-cv-notes",children:t}):null}function ER({title:e,renaming:t,onStart:n,onChange:a,onSave:r,onCancel:l,state:o}){const d=V().web.canvas.title,m=i.useRef(!1),u=i.useRef(null);i.useLayoutEffect(()=>{t!==null&&(m.current=!1,u.current?.focus(),u.current?.select())},[t===null]);const h=f=>{m.current||(m.current=!0,f?r(t??e):l())};return s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"ms-crumb ms-last ms-cv-crumb",children:[s.jsx("span",{className:"ms-crumb-sep","aria-hidden":"true",children:"/"}),t!==null?s.jsx(ms,{ref:u,className:"ms-cv-title-input","aria-label":d.field,value:t,spellCheck:!1,onChange:f=>a(f.target.value),onBlur:()=>h(!0),onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),h(!0)),f.key==="Escape"&&(f.preventDefault(),f.stopPropagation(),h(!1))}}):s.jsxs("button",{type:"button",className:"ms-cv-title","aria-label":d.rename({title:e}),"aria-keyshortcuts":"F2",title:d.rename({title:e}),onClick:n,children:[s.jsx("b",{"aria-current":"page",children:e}),s.jsx(F,{name:"edit",size:12})]})]}),o]})}function TR({status:e,needs:t,working:n}){const a=V(),r=a.web.canvas.state;if(t)return s.jsx(Qs,{tone:"warn",dot:!0,className:"ms-cv-state-pill",children:r.needs});if(n)return s.jsx(Qs,{spinner:!0,className:"ms-cv-state-pill",children:r.working});switch(e){case"ready":return s.jsx(Qs,{tone:"ok",dot:!0,className:"ms-cv-state-pill",children:a.web.status.ready});case"incomplete":case"error":case"interrupted":return s.jsx(Qs,{tone:"warn",className:"ms-cv-state-pill",children:a.web.status[e]});case"working":return s.jsx(Qs,{spinner:!0,className:"ms-cv-state-pill",children:r.working});default:return s.jsx(Qs,{className:"ms-cv-state-pill",children:a.web.status.draft})}}function RR(e){const t=[];let n=[],a=0,r=0;for(const l of e){if(l.type==="user"&&l.pins.length){r+=1;const c=r;n=[...n,...l.pins.map((d,m)=>({pin:d,at:l.at,message:c,frame:d.timeSec!==null||d.range?`${m+1}`:void 0,end:!!d.range}))],a+=l.pins.length}const o=Eu(l);if(o&&n.length){const c=o.n;t.push({n:c,items:n.map(({message:d,frame:m,end:u,...h})=>({...h,...d===r&&m&&!o.kept?{frame:`${c}-${m}.jpg`,...u?{frameEnd:`${c}-${m}e.jpg`}:{}}:{}}))}),n=[]}}return{applied:t.reverse(),open:n.map(({message:l,frame:o,end:c,...d})=>d),count:a}}function MR({slug:e,creative:t,sent:n,working:a,formatLabel:r,onStart:l}){const o=V(),c=o.web.canvas.comments,d=rs(),m=lR(e,t,n.applied.filter(h=>h.items.some(f=>f.frame)).map(h=>h.n));if(!n.count)return s.jsx("div",{className:"ms-cv-tabbody ms-cv-tabempty",children:s.jsx(Rt,{icon:"comment",title:c.emptyTitle,sub:c.emptySub,action:s.jsxs($,{variant:"outline",onClick:l,children:[s.jsx(F,{name:"comment",size:13}),c.start]})})});const u=(h,f,x,p)=>s.jsxs("div",{className:"ms-card ms-cv-comment",children:[p!==void 0&&h.frame&&m[p]?.[h.frame]?s.jsx("img",{className:"ms-cv-comment-frame",src:m[p][h.frame],alt:o.web.render.pinFrame({n:f+1}),draggable:!1}):null,p!==void 0&&h.frameEnd&&m[p]?.[h.frameEnd]?s.jsx("img",{className:"ms-cv-comment-frame",src:m[p][h.frameEnd],alt:o.web.render.pinFrame({n:f+1}),draggable:!1}):null,s.jsxs("span",{className:"ms-cv-comment-head",children:[x,s.jsxs("span",{className:"ms-cv-comment-where",children:[r(h.pin.format),h.pin.clipId?` · ${h.pin.clipName??h.pin.clipId}`:"",h.pin.range?` · ${aC(o,d,h.pin.range)}`:h.pin.timeSec?` · ${o.web.conversation.atSeconds({time:Vs(d,h.pin.timeSec,{maximumFractionDigits:1})})}`:""]}),s.jsx("span",{className:"ms-cv-comment-at",children:ca(d,h.at,Wr)})]}),s.jsx("span",{className:le("ms-cv-comment-text",!h.pin.note&&"ms-faint"),children:h.pin.note||c.noText})]},f);return s.jsxs("div",{className:"ms-cv-tabbody ms-cv-comments",children:[n.open.length?s.jsxs("section",{className:"ms-cv-cgroup",children:[s.jsx("span",{className:"ms-cap",children:a?c.working:c.open}),n.open.map((h,f)=>u(h,f,s.jsx(Qs,{tone:"accent",children:a?c.working:c.open})))]}):null,n.applied.map(h=>s.jsxs("section",{className:"ms-cv-cgroup",children:[s.jsx("span",{className:"ms-cap",children:c.applied({n:h.n})}),h.items.map((f,x)=>u(f,x,s.jsxs(Qs,{tone:"ok",dot:!0,children:["v",h.n]}),h.n))]},h.n))]})}function $R(e){const t=e.filter(r=>r.usage);if(!t.length)return null;const n=t.reduce((r,l)=>Yj(r,l.usage.tokens),{input:0,output:0,cacheRead:0,cacheWrite:0}),a=t.map(r=>r.usage.costUsd).filter(r=>r!==null);return{tokens:_n(n),costUsd:a.length?a.reduce((r,l)=>r+l,0):null,estimated:a.length<t.length||t.some(r=>r.usage.estimated),partial:t.length<e.length}}function FR({project:e,creative:t,versions:n,refresh:a}){const r=V(),l=rs(),[o,c]=i.useState(null);i.useEffect(()=>{let h=!0;return Promise.resolve().then(()=>q.getUsage({project:e,creative:t})).then(f=>{h&&c(f.total)},()=>{h&&c("failed")}),()=>{h=!1}},[e,t,a]);const d=n.some(h=>!h.usage);let m=null;if(o==="failed"){const h=$R(n);m=h&&{...h,partial:!0}}else o&&_n(o.tokens)>0&&(m={tokens:_n(o.tokens),costUsd:o.costUsd,estimated:o.estimated===!0,partial:d||o.estimated===!0});if(!m)return null;const u=dl(r,l,m.costUsd,m.estimated);return s.jsxs("div",{className:"ms-cv-brief-row",children:[s.jsx("span",{className:"ms-cap",children:r.web.usage.creativeTotal}),s.jsxs("div",{className:"ms-cv-brief-value",children:[s.jsxs("span",{className:"ms-cv-brief-tokens",children:[s.jsx(ar,{tokens:m.tokens,partial:m.partial}),u?` · ${u}`:""]}),d?s.jsx("span",{className:"ms-cv-brief-note",children:r.web.usage.untracked}):null]})]})}function PR({project:e,assets:t}){const n=V(),a=n.web.library.assets,[r,l]=i.useState(()=>new Set),[o,c]=i.useState(null),[d,m]=i.useState(0),u=t.join(`
|
|
16
|
+
`);i.useEffect(()=>{let f=!0;return Promise.resolve().then(()=>q.listAssets(e)).then(x=>{f&&l(new Set((x.creativeReferences??[]).map(p=>`assets/${p.file}`)))}).catch(()=>{}),()=>{f=!1}},[e,u,d]);const h=async f=>{const x=f.replace(/^assets\//,"");c(f);try{await q.setAssetReference(e,x,!1),Pe.show(a.savedToAssets({name:x}),{tone:"ok"}),m(p=>p+1)}catch(p){Pe.show(a.saveToAssetsFailed({detail:pe(p)}))}finally{c(null)}};return s.jsx("span",{className:"ms-cv-brief-tags",children:t.map(f=>{const x=f.replace(/^assets\//,"");return r.has(f)?s.jsxs("span",{className:"ms-cv-brief-ref",children:[s.jsx(tn,{children:x}),s.jsxs("span",{className:"ms-cv-brief-refnote",children:[s.jsx(F,{name:"pin",size:10}),n.web.newCreative.referenceOnly]}),s.jsx($,{size:"sm",variant:"ghost",loading:o===f,"aria-label":`${a.saveToAssets}: ${x}`,onClick:()=>{h(f)},children:a.saveToAssets})]},f):s.jsx(tn,{children:x},f)})})}function AR({project:e,detail:t,presets:n,disabled:a,readOnly:r,formatLabel:l,onChanged:o}){const c=V(),d=c.web.canvas.brief,m=rs(),[u,h]=i.useState(!1),f=t.creative.brief;if(u&&r===null)return s.jsxs("div",{className:"ms-cv-tabbody ms-cv-brief-edit",children:[s.jsxs($,{size:"sm",variant:"ghost",className:"ms-cv-brief-back",onClick:()=>h(!1),children:[s.jsx(F,{name:"back",size:13}),d.back]}),s.jsx(SE,{slug:e,detail:t,presets:n,disabled:a,onChanged:()=>{h(!1),o()},onRefresh:o})]});const x=(p,g)=>s.jsxs("div",{className:"ms-cv-brief-row",children:[s.jsx("span",{className:"ms-cap",children:p}),s.jsx("div",{className:"ms-cv-brief-value",children:g})]});return s.jsxs("div",{className:"ms-cv-tabbody ms-cv-brief",children:[x(d.goal,f.goal||d.none),x(d.message,f.message||d.none),x(d.length,f.durationSec?c.web.canvas.seconds({n:Vs(m,f.durationSec)}):d.none),x(d.formats,s.jsx("span",{className:"ms-cv-brief-tags",children:f.formats.map(p=>s.jsx(tn,{children:l(p)},p))})),f.assets.length?x(d.assets,s.jsx(PR,{project:e,assets:f.assets})):null,f.notes?x(d.notes,f.notes):null,x(d.services,bv(f.services,c)),s.jsx(FR,{project:e,creative:t.slug,versions:t.versions,refresh:`${t.versions.map(p=>`${p.n}:${p.status}`).join(",")}|${t.creative.status}|${t.creative.updatedAt}`}),r!==null?s.jsx("p",{className:"ms-cv-note",role:"note",children:r}):null,s.jsxs($,{variant:"outline",className:"ms-cv-brief-edit-btn",disabled:r!==null,onClick:()=>h(!0),children:[s.jsx(F,{name:"edit",size:13}),d.edit]})]})}const ob=(e,t)=>e==="stale"?t.flagStale:e==="overflow"?t.flagOverflow:e==="notTranslated"?t.flagNotTranslated:e==="voice"?t.flagVoice:t.flagAsset;function cb({brief:e,preview:t,className:n}){const r=V().web.languages,l=rs(),o=Ht(e);if(!o||o.extra.length===0)return null;const c=t.locale??"source";return s.jsxs("div",{className:le("ms-loc",n),children:[s.jsx(it,{label:r.previewLanguage,value:c,onChange:d=>t.select(d==="source"?null:d),options:[{value:"source",label:r.previewOriginal({language:Js(o.primary,l)})},...o.extra.map(d=>{const m=t.available.includes(d);return{value:d,label:Js(d,l),disabled:!m,...m?{}:{title:r.statusNone}}})]}),t.state==="loading"?s.jsx("span",{className:"ms-loc-state",role:"status",children:r.previewLoading}):null,t.error?s.jsx("span",{className:"ms-loc-error",role:"alert",children:r.previewFailed({detail:t.error})}):null,t.flagged.length?s.jsx("ul",{className:"ms-loc-flags","aria-label":r.flaggedLabel,children:t.flagged.map(d=>s.jsx("li",{children:s.jsxs("button",{type:"button",className:le("ms-loc-flag",t.focus===d.clipId&&"ms-on"),"aria-pressed":t.focus===d.clipId,title:d.messages.join(" · ")||void 0,onClick:()=>t.setFocus(d.clipId),onMouseEnter:()=>t.setFocus(d.clipId),onFocus:()=>t.setFocus(d.clipId),children:[s.jsx("span",{className:"ms-loc-flag-name",children:d.label}),s.jsx(Qs,{tone:"warn",children:ob(d.kind,r)})]})},d.clipId))}):null]})}function db({player:e,preview:t}){const n=V().web.languages,[a,r]=i.useState(()=>e?.clipBounds??null);i.useEffect(()=>{if(!e){r(null);return}const c=()=>r(e.clipBounds?{...e.clipBounds}:null);return e.addEventListener("clipbounds",c),c(),()=>e.removeEventListener("clipbounds",c)},[e]);const l=t.flagged.find(c=>c.clipId===t.focus),o=l&&a&&a.clipId===l.clipId?a.bounds:null;return!l||!o?null:s.jsx("div",{className:"ms-loc-outline-layer","aria-hidden":"true",children:s.jsx("span",{className:le("ms-loc-outline",`ms-${l.kind}`),"data-clip":l.clipId,style:{left:o.x,top:o.y,width:o.width,height:o.height},children:s.jsx("span",{className:"ms-loc-outline-label",children:ob(l.kind,n)})})})}function ub(e,t,n){const a=t.localizations??[];if(a.some(l=>l.instanceId===n))return{n:t.n,rows:a};const r=t.compositions?.find(l=>l.format===n)?.hash;if(r)for(const l of[...e].filter(o=>o.n>t.n).sort((o,c)=>c.n-o.n)){if(l.compositions?.find(c=>c.format===n)?.hash!==r)continue;const o=l.localizations??[];if(o.some(c=>c.instanceId===n))return{n:l.n,rows:o}}return{n:t.n,rows:a}}function mb(e){const{slug:t,creative:n,n:a,format:r,rows:l,player:o,token:c}=e,[d,m]=i.useState(null),[u,h]=i.useState("idle"),[f,x]=i.useState(null),[p,g]=i.useState(null),[b,v]=i.useState(null),y=i.useRef(e.original);y.current=e.original;const w=i.useMemo(()=>[...new Set(l.filter(C=>C.instanceId===r).map(C=>C.locale))],[l,r]),j=l.find(C=>C.locale===d&&C.instanceId===r)?.hash??null;i.useEffect(()=>{m(null),g(null),x(null),h("idle"),v(null)},[t,n,a,r]),i.useEffect(()=>{if(d===null||a===null||!o||!c)return;let C=!0;return h("loading"),x(null),Promise.resolve().then(()=>q.getLocalizedComposition(t,n,a,r,d)).then(async R=>(await q.attachLocalePreview(t,n,a,d,r,c),R)).then(R=>{C&&(o.setComposition(R.composition),g(R),h("ready"))}).catch(R=>{C&&(h("failed"),x(pe(R)))}),()=>{C=!1}},[d,t,n,a,r,o,c,j]);const S=i.useCallback(C=>{if(m(C),v(null),C!==null)return;g(null),h("idle"),x(null),o?.select(null);const R=y.current?.()??null;if(R&&o){o.setComposition(R);return}o&&a!==null&&Promise.resolve().then(()=>q.getEditorComposition(t,n,a,r)).then(P=>{o.setComposition(P.composition)}).catch(P=>x(pe(P)))},[o,t,n,a,r]),k=i.useMemo(()=>{if(!p)return[];const C=p.composition.tracks.flatMap(R=>R.clips.map(P=>({clipId:P.id,...P.name!==void 0?{name:P.name}:{}})));return LN({stale:p.localization.stale,problems:p.localization.problems,...p.localization.issues?{issues:p.localization.issues}:{},clips:C})},[p]),E=k[0]?.clipId??null,N=b!==null&&k.some(C=>C.clipId===b)?b:E;return i.useEffect(()=>{o&&d!==null&&o.select(N)},[o,d,N]),i.useEffect(()=>()=>{o?.select(null)},[o]),{locale:d,select:S,state:u,error:f,available:w,flagged:k,focus:N,setFocus:v}}const hb=e=>e.origin==="speech"&&!e.timing.locale,LR=(e,t)=>!hb(e)||!t.some(n=>n.origin==="translation"&&n.sourceLang===e.lang);function Xm(e,t){return e?.length?(e.find(hb)??e.find(n=>n.lang===t)??e[0]).lang:null}const fb=new Map,pb=new Map,Zm=(e,t,n)=>`${e}/${t}/${n}`;function IR(e,t,n){const a=Date.now();for(const r of n)fb.set(Zm(e,t,r.lang),a)}function zR(e,t,n,a){pb.set(Zm(e,t,n),a)}function OR(e,t,n,a){const r=Zm(t,n,a),l=fb.get(r)??Number.NEGATIVE_INFINITY,o=pb.get(r),c=d=>(d.key.startsWith("subtitles-translate:")&&d.key.endsWith(`:${t}:${n}:${a}`)||d.id===o&&d.key.startsWith("subtitles:")&&d.key.endsWith(`:${t}:${n}`))&&Date.parse(d.createdAt)>l;return Object.values(e).filter(c).sort((d,m)=>d.createdAt.localeCompare(m.createdAt)).at(-1)??null}function xb(e,t){try{return new Intl.DisplayNames([t],{type:"language"}).of(e)??e}catch{return e}}function gb({slug:e,creative:t,lang:n,sets:a,brief:r,edited:l,onSwitch:o,onLeave:c}){const d=V().subtitles,m=rs(),h=(a.some(x=>x.lang===n)?a:[...a,null]).map(x=>({value:x?.lang??n,label:Js(x?.lang??n,m)})),f=a.find(x=>x.lang===n);return s.jsxs("span",{className:"ms-subs-langs",children:[s.jsx(it,{label:d.languages,options:h,value:n,onChange:x=>{o(x)},className:"ms-subs-lang-seg"}),s.jsx(DR,{slug:e,creative:t,sets:a,brief:r,onAdded:o}),f&&LR(f,a)?s.jsx(BR,{slug:e,creative:t,lang:n,edited:l,onDeleted:()=>c(Xm(a.filter(x=>x.lang!==n),Ht(r??{})?.primary))}):null]})}function DR({slug:e,creative:t,sets:n,brief:a,onAdded:r}){const l=V().subtitles,o=rs(),c=i.useRef(null),[d,m]=i.useState(!1),[u,h]=i.useState(null),[f,x]=i.useState(null),p=i.useMemo(()=>{const b=new Set(n.map(w=>w.lang)),v=(Ht(a??{})?.all??[]).filter(w=>!b.has(w)),y=ei.map(w=>w.tag).filter(w=>!b.has(w)&&!v.includes(w)).sort((w,j)=>Js(w,o).localeCompare(Js(j,o),o));return[{title:l.addFromBrief,langs:v},{title:l.addOthers,langs:y}].filter(w=>w.langs.length>0)},[n,a,o,l]),g=async b=>{h(b),x(null);try{const v=await q.addSubtitleLanguage(e,t,b);v.job?.id&&zR(e,t,b,v.job.id)}catch(v){if(!(v instanceof lt&&v.code==="subtitles-lang-exists")){x(l.addFailed({detail:pe(v)})),h(null);return}}h(null),m(!1),await r(b)};return s.jsxs(s.Fragment,{children:[s.jsx($,{ref:c,size:"sm",variant:"ghost","aria-haspopup":"dialog","aria-expanded":d,onClick:()=>{x(null),m(b=>!b)},children:l.addLanguage}),s.jsx(ot,{open:d,onClose:()=>m(!1),anchor:c,placement:"bottom-start",width:260,label:l.addLanguageTitle,children:s.jsxs("div",{className:"ms-subs-addlang",children:[s.jsx("b",{className:"ms-subs-redo-title",children:l.addLanguageTitle}),s.jsx("p",{className:"ms-subs-redo-hint",children:l.addHint}),f?s.jsx("p",{className:"ms-subs-redo-error",role:"alert",children:f}):null,p.map(b=>s.jsxs("div",{className:"ms-subs-addlang-group",role:"group","aria-label":b.title,children:[s.jsx("span",{className:"ms-subs-addlang-title",children:b.title}),b.langs.map(v=>s.jsx($,{size:"sm",variant:"ghost",className:"ms-subs-addlang-item",disabled:u!==null,"aria-busy":u===v||void 0,onClick:()=>{g(v)},children:Js(v,o)},v))]},b.title))]})})]})}function BR({slug:e,creative:t,lang:n,edited:a,onDeleted:r}){const l=V().subtitles,o=rs(),c=i.useRef(null),[d,m]=i.useState(!1),[u,h]=i.useState(!1),[f,x]=i.useState(null),p=xb(n,o),g=l.deleteLanguage({lang:p}),b=async()=>{h(!0),x(null);try{await q.deleteSubtitleLanguage(e,t,n),m(!1),r()}catch(v){x(l.deleteFailed({detail:pe(v)}))}finally{h(!1)}};return s.jsxs(s.Fragment,{children:[s.jsx(pn,{label:g,children:s.jsx($,{ref:c,size:"sm",variant:"ghost",icon:!0,"aria-label":g,disabled:u,"aria-busy":u||void 0,onClick:()=>{x(null),a>0?m(v=>!v):b()},children:s.jsx(F,{name:"trash",size:13})})}),s.jsx(ot,{open:d,onClose:()=>m(!1),anchor:c,placement:"bottom-end",width:280,label:g,children:s.jsxs("div",{className:"ms-subs-redo",children:[s.jsx("b",{className:"ms-subs-redo-title",children:g}),s.jsx("p",{className:"ms-subs-redo-hint",children:l.deleteConfirm({lang:p,count:a})}),f?s.jsx("p",{className:"ms-subs-redo-error",role:"alert",children:f}):null,s.jsxs("span",{className:"ms-subs-confirm",children:[s.jsx($,{size:"sm",variant:"ghost",onClick:()=>m(!1),children:l.deleteNo}),s.jsx($,{size:"sm",variant:"danger",loading:u,onClick:()=>{b()},children:l.deleteYes})]})]})}),f&&!d?s.jsx("span",{className:"ms-subs-head-error",role:"alert",children:f}):null]})}function UR({open:e,title:t,initial:n,adding:a,onSubmit:r,onCancel:l}){const o=V().web.conversation,[c,d]=i.useState(n),m=i.useRef(null);return i.useEffect(()=>{e&&d(n)},[e,n]),i.useEffect(()=>{e&&m.current?.focus({preventScroll:!0})},[e]),s.jsx(rt,{open:e,onClose:l,label:t,width:440,children:s.jsxs("div",{className:"ms-ed-dialog",children:[s.jsx("h2",{children:t}),s.jsx(nn,{ref:m,rows:4,maxLength:2e3,"aria-label":o.noteLabel,value:c,onChange:u=>d(u.target.value),onKeyDown:u=>{dc(u.nativeEvent)&&!u.repeat&&(u.preventDefault(),r(c.trim()))}}),s.jsxs("div",{className:"ms-ed-dialog-foot",children:[s.jsx($,{variant:"ghost",onClick:l,children:o.noteCancel}),s.jsx($,{variant:"ink",onClick:()=>r(c.trim()),children:a?o.noteAdd:o.noteSave})]})]})})}const _R=1,Jm=20,qR=8,VR=3,Kr=e=>Math.round(e*1e6)/1e6,sl=(e,t,n)=>Math.min(Math.max(e,t),Math.max(t,n)),tl=e=>sl(Number.isFinite(e)?e:1,_R,Jm),xu=(e,t,n)=>t>0&&e>0?e*tl(n)/t:0,zn=(e,t)=>e*t,jd=(e,t)=>t>0?e/t:0,vb=e=>Math.ceil(1e6/e)/1e6,La=(e,t)=>Kr(Math.round(e*t)/t),KR=e=>tl(Jm**(sl(e,0,100)/100)),WR=e=>Math.round(Math.log(tl(e))/Math.log(Jm)*100);function HR(e){const t=tl(e.next),n=xu(e.viewportPx,e.duration,e.zoom),a=xu(e.viewportPx,e.duration,t);if(n<=0||a<=0)return{zoom:t,scrollLeft:0};const r=(e.scrollLeft+e.anchorPx)/n,l=Math.max(0,e.duration*a-e.viewportPx);return{zoom:t,scrollLeft:sl(r*a-e.anchorPx,0,l)}}function yd(e,t,n,a){if(!a||n<=0)return{delta:0,snappedTo:null};const r=qR/n;let l=null;for(const o of e){const c=Qj(o,t,r);if(c.snappedTo===null)continue;const d=c.snappedTo-o;(l===null||Math.abs(d)<Math.abs(l.delta)-1e-9)&&(l={delta:d,snappedTo:c.snappedTo})}return l??{delta:0,snappedTo:null}}function pp(e,t,n){const a=t.scene!==void 0?e.scenes.find(o=>o.id===t.scene):void 0,r=a?a.start:0,l=a?a.start+a.duration:e.duration;return{lo:r,hi:n&&a?ic.durationSec:l}}function xp(e,t,n){const a=sl(t,n.lo,n.hi-e.duration);return{start:Kr(a),duration:e.duration}}function GR(e,t){return{start:La(e.start,t),duration:Math.max(La(e.duration,t),vb(t))}}function wd(e,t,n,a,r){const l=vb(r),o=e.start+e.duration;if(t==="start"){const d=sl(n,a.lo,o-l);return{start:Kr(d),duration:Kr(o-d)}}const c=sl(n,e.start+l,a.hi);return{start:e.start,duration:Kr(c-e.start)}}const XR=72,ZR=[.1,.2,.5,1,2,5,10,15,30,60,120,300,600];function JR(e,t,n,a){if(e<=0||a<=n)return{step:1,major:[],frames:[]};const r=ZR.find(d=>d*e>=XR)??600,l=d=>{const m=[];for(let u=Math.max(0,Math.floor(n/d));u*d<=a+1e-9;u+=1)m.push(Kr(u*d));return m},o=l(r),c=e/t>=6?l(1/t).filter(d=>!o.some(m=>Math.abs(m-d)<1e-6)):[];return{step:r,major:o,frames:c}}function YR({marks:e,pps:t}){const n=V().web.conversation,a=rs();return s.jsx(s.Fragment,{children:e.filter(r=>r.pin.range).map(({pin:r,number:l})=>{const o=r.range,{a:c,b:d}=br(a,o);return s.jsx("span",{className:"ms-tl-span",role:"img","aria-label":n.rangeSpan({a:c,b:d,note:r.note??""}),"data-range":`${o.start}-${o.end}`,style:{left:zn(o.start,t),width:Math.max(2,zn(o.end-o.start,t))}},l)})})}function QR(e,t){const n=Math.max(0,Math.min(e,Math.max(0,t-Zl)));return{start:n,end:Math.min(t,n+1)}}function bb({open:e,playhead:t,duration:n,onSubmit:a,onCancel:r}){const l=V().web.conversation,[o,c]=i.useState(()=>QR(t,n)),d=o.end-o.start>=Zl;return s.jsx(rt,{open:e,onClose:r,label:l.rangeDialogTitle,width:400,children:s.jsxs("div",{className:"ms-ed-dialog",children:[s.jsx("h2",{children:l.rangeDialogTitle}),s.jsxs("div",{className:"ms-range-fields",children:[s.jsx(Tt,{label:l.rangeStart,unit:"s",min:0,max:n,step:.1,decimals:2,value:o.start,onChange:m=>c(u=>({...u,start:m}))}),s.jsx(Tt,{label:l.rangeEnd,unit:"s",min:0,max:n,step:.1,decimals:2,value:o.end,onChange:m=>c(u=>({...u,end:m}))})]}),d?null:s.jsx("p",{role:"alert",className:"ms-cv-note ms-err",children:l.rangeInvalid}),s.jsxs("div",{className:"ms-ed-dialog-foot",children:[s.jsx($,{variant:"ghost",onClick:r,children:l.noteCancel}),s.jsx($,{variant:"ink",disabled:!d,onClick:()=>a(o),children:l.rangeContinue})]})]})})}const eM=.5;function jb({clock:e,video:t,label:n,onPlace:a}){const r=V(),{settled:l}=Jn(e);return s.jsx("button",{type:"button",className:"ms-cv-hit","aria-label":t?r.web.formatView.commentFrame({time:wt(l)}):r.web.canvas.commentOn({label:n}),onClick:a})}function yb({clock:e,video:t,marks:n,open:a,onOpen:r}){const l=V().web.canvas,{time:o}=Jn(e),c=t?n.filter(d=>d.pin.timeSec===null||(d.pin.range?o>=d.pin.range.start-1e-6&&o<=d.pin.range.end+1e-6:Math.abs(d.pin.timeSec-o)<=eM+1e-6)):n;return s.jsx(s.Fragment,{children:c.map(({pin:d,number:m})=>s.jsx("button",{type:"button",className:le("ms-cv-pin",a===m-1&&"ms-on"),style:{left:`${d.x*100}%`,top:`${d.y*100}%`},"aria-label":l.pin.edit({n:m}),title:d.note,onClick:u=>{u.stopPropagation(),r(m)},children:m},m))})}function wb({clock:e,video:t}){const n=V().web.formatView,{settled:a}=Jn(e);return s.jsx("div",{className:"ms-cv-hint ms-fv-hint",role:"status",children:t?n.commentAt({time:wt(a)}):n.commentImage})}function kb(e,t){const n=[...e.scenes].sort((a,r)=>a.start-r.start);return n.length===0?[{id:null,name:t.wholeVideo,start:0,duration:e.duration}]:n.map((a,r)=>({id:a.id,name:a.name??t.scene({n:r+1}),start:a.start,duration:a.duration}))}const sM=1e-6;function Nb(e,t){let n=0;return e.forEach((a,r)=>{a.start<=t+sM&&(n=r)}),n}function gu(e,t){const n=e?.frames??[];return t.id===null?n.find(a=>a.kind==="poster")??n[0]??null:n.find(a=>a.kind==="scene"&&(a.scene===t.id||a.scene===t.name))??null}function vu({frame:e,state:t,width:n,height:a}){const r=a>n,l={aspectRatio:`${n} / ${a}`,...r?{height:64}:{width:64}},o=t==="loading"||t==="busy";return s.jsx("span",{className:le("ms-fv-sb-thumb",!e&&o&&"ms-loading"),style:l,"aria-hidden":"true","data-thumb":e?"frame":o?"loading":"none",children:e?s.jsx("img",{src:e.url,alt:"",draggable:!1}):o?null:s.jsx(F,{name:"image",size:14})})}function Sb({slug:e,creative:t,brief:n,actual:a,edited:r,disabled:l,onChanged:o}){const d=V().web.formatView,m=rs(),u=i.useRef(null),[h,f]=i.useState(!1),[x,p]=i.useState(!1),g=Math.min(600,Math.max(1,Math.round(a))),b=Vs(m,n.durationSec??0,{maximumFractionDigits:1}),v=d.briefOff({n:b}),y=async()=>{p(!0);try{const{storePack:w,...j}=n;await q.updateCreative(e,t,{brief:{...j,durationSec:g}}),f(!1),Pe.show(d.briefOffFixed({n:Vs(m,g)}),{tone:"ok"}),o()}catch(w){Pe.show(d.briefOffFailed({detail:pe(w)}),{tone:"neutral"})}p(!1)};return s.jsxs(s.Fragment,{children:[s.jsxs("button",{ref:u,type:"button",className:"ms-pill ms-warn ms-brief-off","aria-label":v,title:v,"aria-haspopup":"dialog","aria-expanded":h,onClick:()=>f(w=>!w),children:[s.jsx(F,{name:"warn",size:12}),s.jsx("span",{className:"ms-brief-off-text",children:v})]}),s.jsx(ot,{open:h,onClose:()=>f(!1),anchor:u,placement:"bottom-start",width:300,label:v,children:s.jsxs("div",{className:"ms-brief-off-pop",children:[s.jsx("b",{children:v}),s.jsx("p",{children:d.briefOffBody({n:b,actual:Vs(m,a,{maximumFractionDigits:1})})}),r?s.jsx("p",{children:d.briefOffEdited}):null,l!==null?s.jsx("p",{className:"ms-brief-off-why",role:"note",children:l}):null,s.jsx($,{size:"sm",variant:"outline",loading:x,disabled:l!==null,onClick:()=>{y()},children:d.briefOffFix({n:Vs(m,g)})})]})})]})}function Cb({children:e,buttonRef:t}){const n=V().web.shell.moreActions,a=i.useRef(null),r=t??a,[l,o]=i.useState(!1),c=()=>o(!1);return s.jsxs(s.Fragment,{children:[s.jsx($,{ref:r,variant:"ghost",icon:!0,className:"ms-bar-more","aria-label":n,title:n,"aria-haspopup":"menu","aria-expanded":l,onClick:()=>o(d=>!d),children:s.jsx(F,{name:"more",size:16})}),s.jsx(ot,{open:l,onClose:c,anchor:r,placement:"bottom-end",width:280,children:s.jsx("div",{role:"menu","aria-label":n,children:e(c)})})]})}function Go({icon:e,close:t,run:n,disabled:a=null,hint:r,children:l}){const o=i.useId(),c=a!==null;return s.jsxs(s.Fragment,{children:[s.jsx(dn,{"data-row":"",role:"menuitem",icon:e,title:r,"aria-disabled":c||void 0,"aria-describedby":c?o:void 0,onClick:c?void 0:()=>{t(),n()},children:l}),c?s.jsx("p",{id:o,className:"ms-bar-menu-why",role:"note",children:a}):null]})}const gp=e=>/\.(png|svg)$/i.test(e.path),vp=160,tM=256,nM=3;function Eb({slug:e,creative:t,n,set:a,kind:r}){const l=V().web.identity,[o,c]=i.useState(!1),d=x=>Da(e,t,n,`${a.dir}/${x}`),m=x=>a.files.some(p=>p.path===x),u=a.files.filter(gp),h=a.files.filter(x=>!gp(x)),f=x=>{const p=x.width??vp;return Math.min(o?tM:vp,Math.round(p*(o?nM:1)))};return s.jsxs("div",{className:"ms-idn-sizes",children:[s.jsxs("div",{className:"ms-idn-head",children:[s.jsx("h3",{children:l.sizesTitle}),s.jsxs("span",{className:"ms-idn-zoom",children:[s.jsx(Un,{size:"sm",on:o,onChange:c,label:l.zoomed}),s.jsx("span",{"aria-hidden":"true",children:l.zoomed})]})]}),s.jsx("p",{className:"ms-idn-intro",children:l.sizesIntro}),a.warnings.length>0?s.jsxs("div",{className:"ms-idn-warn",role:"note",children:[s.jsxs("b",{children:[s.jsx(F,{name:"warn",size:13}),l.warnings]}),s.jsx("ul",{children:a.warnings.map(x=>s.jsx("li",{children:x},x))})]}):null,s.jsx("ul",{className:"ms-idn-grid","aria-label":l.sizesTitle,children:u.map(x=>{const p=x.path.split("/").pop()??x.path,g=f(x);return s.jsxs("li",{className:"ms-idn-tile",children:[s.jsx("span",{className:"ms-idn-pic",style:{width:g,height:x.width&&x.height?Math.round(g*x.height/x.width):g},children:s.jsx("img",{src:d(x.path),alt:x.width&&x.height?l.fileSize({name:x.path,w:x.width,h:x.height}):x.path,draggable:!1})}),s.jsxs("span",{className:"ms-idn-cap",children:[s.jsx("b",{title:x.path,children:p}),s.jsxs("span",{children:[x.width&&x.height?`${x.width}×${x.height} px`:"—",o?"":` · ${l.oneToOne}`]})]})]},x.path)})}),h.length>0?s.jsx("p",{className:"ms-idn-others",children:h.map(x=>x.path).join(" · ")}):null,r!=="logo"?s.jsxs(s.Fragment,{children:[s.jsx("h3",{className:"ms-idn-sub",children:l.contexts}),s.jsxs("div",{className:"ms-idn-ctx",children:[r==="favicon"&&m("favicon.svg")?s.jsxs("figure",{className:"ms-idn-fig",children:[s.jsxs("div",{className:"ms-idn-tab","aria-hidden":"true",children:[s.jsx("img",{src:d("favicon.svg"),width:16,height:16,alt:"",draggable:!1}),s.jsx("span",{className:"ms-idn-tabtitle"}),s.jsx("img",{src:d("favicon.svg"),width:32,height:32,alt:"",draggable:!1,className:"ms-idn-tab32"})]}),s.jsxs("figcaption",{children:[l.browserTab," · 16 / 32 px"]})]}):null,r==="favicon"&&m("apple-touch-icon.png")?s.jsxs("figure",{className:"ms-idn-fig",children:[s.jsx("span",{className:"ms-idn-mask ms-idn-ios","aria-hidden":"true",children:s.jsx("img",{src:d("apple-touch-icon.png"),alt:"",draggable:!1})}),s.jsxs("figcaption",{children:[l.iosIcon," · 180 px"]})]}):null,r==="favicon"&&m("icon-512-maskable.png")?s.jsxs("figure",{className:"ms-idn-fig",children:[s.jsxs("span",{className:"ms-idn-mask ms-idn-circle","aria-hidden":"true",children:[s.jsx("img",{src:d("icon-512-maskable.png"),alt:"",draggable:!1}),s.jsx("span",{className:"ms-idn-safe",style:{inset:`${(1-.8)/2*100}%`}})]}),s.jsxs("figcaption",{children:[l.maskableIcon," · ",l.safeZone," 80%"]}),s.jsx("p",{className:"ms-idn-safenote",children:l.safeZoneNote({pct:80})})]}):null,r==="app-icon"&&m("AppIcon-1024.png")?s.jsxs("figure",{className:"ms-idn-fig",children:[s.jsx("span",{className:"ms-idn-mask ms-idn-ios","aria-hidden":"true",children:s.jsx("img",{src:d("AppIcon-1024.png"),alt:"",draggable:!1})}),s.jsx("figcaption",{children:l.iosIcon})]}):null,r==="app-icon"&&m("ic_launcher_foreground.png")?s.jsxs("figure",{className:"ms-idn-fig",children:[s.jsxs("span",{className:"ms-idn-mask ms-idn-circle","aria-hidden":"true",children:[m("ic_launcher_background.png")?s.jsx("img",{className:"ms-idn-layer",src:d("ic_launcher_background.png"),alt:"",draggable:!1}):null,s.jsx("img",{className:"ms-idn-layer",src:d("ic_launcher_foreground.png"),alt:"",draggable:!1}),s.jsx("span",{className:"ms-idn-safe",style:{inset:`${(1-xh)/2*100}%`}})]}),s.jsxs("figcaption",{children:[l.androidIcon," · ",l.safeZone," 66/108"]}),s.jsx("p",{className:"ms-idn-safenote",children:l.safeZoneNote({pct:Math.round(xh*100)})})]}):null]})]}):null]})}function Tb({slug:e,creative:t,n,format:a,label:r,kind:l,disabled:o,hasDark:c}){const d=V(),m=d.web.identity,[u,h]=i.useState(!1),[f,x]=i.useState(l==="logo"?"primary":"icon"),[p,g]=i.useState(!1),[b,v]=i.useState(null),y=async()=>{g(!0),v(null);try{const w=await q.useAsBrandLogo(e,t,n,a,f);h(!1),Pe.show(w.committed===!1?m.useAsLogoNotCommitted:m.useAsLogoDone,{tone:"ok",action:{label:m.useAsLogoOpen,run:()=>Bs(es.project(e,"brand"))}})}catch(w){v(m.useAsLogoFailed({detail:pe(w)}))}finally{g(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs($,{size:"sm",variant:"outline",disabled:o,"aria-label":m.useAsLogoOf({label:r}),onClick:()=>{v(null),h(!0)},children:[s.jsx(F,{name:"star",size:13}),m.useAsLogo]}),s.jsx(rt,{open:u,onClose:()=>{p||h(!1)},label:m.useAsLogoTitle,width:440,dismissible:!p,children:s.jsxs("div",{className:"ms-brief-confirm",children:[s.jsx("h3",{children:m.useAsLogoTitle}),s.jsx("p",{children:m.useAsLogoBody}),c?s.jsx("p",{children:m.useAsLogoDarkNote}):null,s.jsx(it,{label:m.useAsLogoAs,value:f,onChange:x,disabled:p,options:[{value:"primary",label:m.variantPrimary},{value:"icon",label:m.variantIcon}]}),b?s.jsx("p",{role:"alert",className:"ms-brief-error",children:b}):null,s.jsxs("div",{className:"ms-brief-actions",children:[s.jsx($,{variant:"ink",loading:p,onClick:()=>{y()},children:m.useAsLogoConfirm}),s.jsx($,{variant:"outline",disabled:p,onClick:()=>h(!1),children:d.common.cancel})]})]})})]})}const $r=[.1,.25,.33,.5,.67,.75,1,1.25,1.5,2,3,4],aM=400;function rM({slug:e,creative:t,format:n,live:a,exportNamePattern:r,onSettings:l,viewing:o,onViewing:c,origin:d}){const m=V(),u=ul(e,a),h=m.web.formatView,f=m.web.canvas,x=rs(),p=i.useContext(Mn),g=i.useRef(null),b=i.useRef(null),{detail:v,conversation:y,error:w,reload:j}=Mm(e,t,Hm(a.creativeTicks,e,t)),S=Gm(a,e,t,v),k=Zn({name:"format",slug:e,creative:t,format:n}),E=!p||Zn(p.route)===k,N=i.useRef(()=>{}),C=v?.variants&&!v.variants.orphan?v.variants.letter.toUpperCase():null,R=Tc(k,E,{title:v?.creative.title??null,variant:C,open:()=>N.current()}),[P]=i.useState(()=>d!==void 0?d:zo(`format:${e}/${t}/${n}`)),[z]=i.useState(()=>performance.now()),[O,T]=i.useState([]),[W,Z]=i.useState(!1),[A,L]=i.useState(null);i.useEffect(()=>{let ie=!0;return Promise.resolve().then(()=>q.getFormats()).then(ke=>{ie&&(T(ke.presets),Z(!0))}).catch(ke=>{ie&&(L(pe(ke)),Z(!0))}),()=>{ie=!1}},[]);const _=i.useMemo(()=>v?.versions??[],[v]),X=i.useMemo(()=>Ul(v?.subtitles),[v]),ae=_.at(-1)??null,K=i.useMemo(()=>v?Al(v,O):{},[v,O]),[I,H]=i.useState(()=>o?{}:Gu(`${e}/${t}`)),de=o??I,J=c??H,se=ga(K,n,de),U=se.n!==null?_.find(ie=>ie.n===se.n)??null:null,te=i.useCallback((ie,ke)=>J(cs=>{const Ps={...cs};return ke===K[ie]?.star.version?delete Ps[ie]:Ps[ie]=ke,Ps}),[K]),G=i.useRef(null),re=i.useRef(null),[oe,Ne]=i.useState(!1);Wm(!!v,ae?.n??null,E,G);const[Q,Re]=i.useState(null),Ue=i.useMemo(()=>Object.values(a.approvals).filter(S.shows),[a.approvals,S]),is=i.useMemo(()=>{if(!v)return;const ie=Object.values(a.jobs).filter(ke=>ke.key===v.jobKey);return ie.find(ke=>ke.state==="queued"||ke.state==="running")??ie.sort((ke,cs)=>cs.createdAt.localeCompare(ke.createdAt))[0]},[a.jobs,v]),Qe=is?.state==="queued"||is?.state==="running",gs=mo(lu(is,K),n),As=is&&Qe?is.state==="queued"?m.web.creatives.queued:Xr(a.events[is.id])??m.web.creatives.working:null,hs=!v||!W,Oe=pt(O,n)??(W?null:pt(Tu,n)),be=v?.creative.brief.formatLabels,Fe=U?.outputs.find(ie=>ie.format===se.format)??null,je=Oe?.identity??null,he=je&&Fe?.identitySet?Fe.identitySet:null,Ke=je==="logo"&&he?he.files.find(ie=>ie.path==="logo-dark.png")??null:null,[we,ze]=i.useState("image");i.useEffect(()=>{ze("image")},[n]);const We=he!==null&&we==="sizes",Rs=!!(v&&(v.creative.brief.formats.includes(n)||_.some(ie=>ie.outputs.some(ke=>ke.format===n)))),us=Bn(U,se.format),fs=el({slug:e,creative:t,n:U?.n??null,format:se.format,enabled:us!==null}),fe=us!==null&&fs.state.kind!=="legacy",{storyboard:Ge,state:De}=ci({slug:e,creative:t,n:U?.n??null,format:se.format,hash:us?.hash??null,enabled:us!==null}),os=Rc(Ge),Ze=fe?Oe?.kind!=="image":Fe?tr(Fe.file):Oe?.kind==="video",vs=Oe?.width??Fe?.width??(P?.width?Math.round(P.width):1080),Le=Oe?.height??Fe?.height??(P?.height?Math.round(P.height):1080),ne=nr({id:n,preset:Oe,labels:be},x),Ee=Fe&&U?Da(e,t,U.n,Fe.file):null,Ce=Ke&&he&&U?Da(e,t,U.n,`${he.dir}/${Ke.path}`):null,Xe=Fe?.preview&&U?Da(e,t,U.n,Fe.preview):void 0,ue=v?v.creative.resumeFrom?.version??ae?.n??null:null,xe=U!==null&&(!!Fe||us!==null)&&ja(_,K[se.format],ue)===U.n,{stored:Be,setStored:_e,others:ge,drop:qe}=Um(e,t,S.pinScope),Ye=i.useMemo(()=>Be.flatMap((ie,ke)=>ie.version===ue?[{pin:ie.pin,at:ke}]:[]),[Be,ue]),Ls=i.useMemo(()=>Ye.map(ie=>ie.pin),[Ye]),et=i.useMemo(()=>Ls.map((ie,ke)=>({pin:ie,number:ke+1})).filter(ie=>ie.pin.format===n),[Ls,n]),[bs,Us]=i.useState(null),[Me,ss]=i.useState(!1);i.useEffect(()=>{xe||Us(null)},[xe]),i.useEffect(()=>{Us(null)},[ue]);const Ie=fe&&U?U.n:null,ys=Ie===null?null:`${e}/${t}/${Ie}/${se.format}`,[ns,Ys]=i.useState(null);i.useEffect(()=>{if(Ie===null||ys===null)return;let ie=!0;return Promise.resolve().then(()=>q.getEditorComposition(e,t,Ie,se.format)).then(ke=>{ie&&Ys({key:ys,comp:ke.composition})},()=>{ie&&Ys({key:ys,comp:"failed"})}),()=>{ie=!1}},[e,t,Ie,se.format,ys]);const mt=ns&&ns.key===ys?ns.comp:null,ct=xe?mt==="failed"?null:mt:null,[ls]=i.useState(Lm),Is=i.useRef(null),[Hs,ee]=i.useState(null),[as,ds]=i.useState(!1),Ks=i.useMemo(()=>U?ub(_,U,se.format):null,[_,U,se.format]),tt=mb({slug:e,creative:t,n:fe&&Ks?Ks.n:null,format:se.format,rows:Ks?.rows??[],player:Hs,token:fs.state.kind==="ready"?fs.state.session.token:null,original:()=>ct}),[js,Ds]=i.useState(!1),[ht,un]=i.useState(null),Os=ht??Fe?.durationSec??0,[gt,mn]=i.useState(!1),[Wt,$n]=i.useState(0),[gn,zt]=i.useState(!1),[Mt,Yn]=i.useState("1"),vt=i.useCallback(ie=>{ie&&(ie.defaultPlaybackRate=Number(Mt),ie.playbackRate=Number(Mt))},[Mt]);i.useEffect(()=>{vt(Is.current)},[vt,Ee,Wt,Hs]);const St=i.useRef(null),an=fe&&U?`${U.n}/${se.format}`:null;i.useEffect(()=>{mn(!1),Ds(!1),ls.set(0,!0),un(null),ds(!1)},[Ee,an,ls]),i.useEffect(()=>{if(!Hs)return;Is.current=Hs;const ie=[],ke=(Ps,ft)=>{Hs.addEventListener(Ps,ft),ie.push(()=>Hs.removeEventListener(Ps,ft))};ke("timeupdate",()=>ls.set(Hs.currentTime,!0));const cs=()=>{vt(Hs),ds(!0),mn(!1),Number.isFinite(Hs.duration)&&Hs.duration>0&&un(Hs.duration),St.current!==null&&(Hs.currentTime=St.current,ls.set(St.current,!0),St.current=null)};return ke("loadedmetadata",cs),Number.isFinite(Hs.duration)&&(cs(),ls.set(Hs.currentTime,!0)),ke("play",()=>Ds(!0)),ke("pause",()=>Ds(!1)),ke("ended",()=>Ds(!1)),ke("error",()=>{mn(!0),Ds(!1)}),()=>{for(const Ps of ie)Ps();Is.current===Hs&&(Is.current=null)}},[Hs,ls,vt]),i.useEffect(()=>{Hs&&(Hs.loop=gn)},[Hs,gn]);const Zt=i.useCallback(ie=>{const ke=Is.current;if(!ke)return;const cs=ht??Fe?.durationSec??0,Ps=Math.max(0,cs?Math.min(cs,ie):ie);ke.currentTime=Ps,ls.set(Ps,!0)},[ls,ht,Fe?.durationSec]),$t=i.useCallback(()=>{const ie=Is.current;ie?.pause(),Ds(!1),ie&&ls.set(ie.currentTime,!0)},[ls]),rn=i.useCallback(()=>{const ie=Is.current;if(!ie||gt)return;Os&&ie.currentTime>=Os-1/El/2&&Zt(0),Us(cs=>cs&&cs.text.trim()?cs:null),Ds(!0);const ke=ie.play();ke&&typeof ke.catch=="function"&&ke.catch(()=>Ds(!1))},[Os,gt,Zt]),Jt=()=>{js?$t():rn()},hn=ie=>{const ke=Is.current;ke&&(js&&$t(),Zt(Math.round((ke.currentTime+ie/El)*El)/El))};i.useEffect(()=>{if(!js)return;let ie=0;const ke=()=>{const cs=Is.current;cs&&ls.set(cs.currentTime,!1),ie=requestAnimationFrame(ke)};return ie=requestAnimationFrame(ke),()=>cancelAnimationFrame(ie)},[js,ls]),i.useEffect(()=>{E||$t()},[E,$t]);const D=ie=>ui(ie)&&!ie.shiftKey&&!jr(ie)&&!pr(ie)&&!za(ie,Wo)&&Ze&&(fe?as:!!Fe)&&!gt;qt(g,ie=>(ie.key===" "||ie.code==="Space")&&D(ie),Jt),qt(g,ie=>(ie.key==="ArrowLeft"||ie.key==="ArrowRight")&&D(ie),ie=>hn(ie.key==="ArrowRight"?1:-1));const[Ae,ts]=i.useState(!1),ps=i.useRef(()=>{});qt(g,ie=>ie.key.toLowerCase()==="r"&&D(ie)&&xe&&!bs&&Os>0&&!js,()=>ts(!0)),qt(g,ie=>ie.key.toLowerCase()==="c"&&D(ie)&&xe&&!bs&&ct!==null&&!js,()=>ps.current());const[Cs,ks]=i.useState("fit"),[Ms,Bt]=i.useState(0);i.useLayoutEffect(()=>{const ie=b.current;if(!ie||Ze||Cs!=="fit")return;const ke=()=>Bt(ie.offsetWidth/vs);if(ke(),typeof ResizeObserver>"u")return;const cs=new ResizeObserver(ke);return cs.observe(ie),()=>cs.disconnect()},[Ze,Cs,vs,hs]);const bt=Cs==="fit"?Ms:Cs,nt=ie=>{const ke=bt||1,cs=ie>0?$r.find(Ps=>Ps>ke+.001):[...$r].reverse().find(Ps=>Ps<ke-.001);ks(cs??(ie>0?$r.at(-1):$r[0]))},[fn,Nn]=i.useState(!1),Vn=!(w&&!v)&&!(!hs&&!Rs),jt=i.useRef(!1);i.useLayoutEffect(()=>{if(jt.current||!Vn||!g.current)return;jt.current=!0;const ie=P&&performance.now()-z<=aM?P:null;ie&&Eo(b.current,ie,qs.l),g.current.querySelectorAll("[data-part]").forEach(ke=>{const cs=ke.dataset.part;Gs(ke,{x:cs==="l"?-16:cs==="r"?16:0,y:cs==="b"?24:0,delay:ie?160:0})})},[Vn]);const ha=`${e}/${t}`,Ct=ie=>Hu(ha,ie),vn=()=>{$t(),b.current&&Hl(`canvas:${e}/${t}/${n}`,b.current.getBoundingClientRect()),Ct(de),Bs(es.creative(e,t))};N.current=vn;const[ln,Kn]=i.useState(!1),Qn=async()=>{if(!(!U||ln)){Kn(!0),Re(null);try{const ie=await q.duplicateFormat(e,t,U.n,{instanceId:n});$t(),Ct({}),j(),Pe.show(m.web.instances.duplicated({label:xn(Oe,ie.instanceId,x,be)}),{tone:"ok"}),Bs(es.format(e,t,ie.instanceId))}catch(ie){Re(m.web.instances.duplicateFailed({detail:pe(ie)}))}Kn(!1)}},Ut=ie=>{ie.stopPropagation();const ke=xm(ie.currentTarget.getBoundingClientRect(),ie),cs=Ze?Za(Is.current?.currentTime??ls.get().time):null;Us(Ps=>({format:n,x:ke.x,y:ke.y,text:Ps&&Ps.index===null?Ps.text:"",index:null,timeSec:cs}))},fa=ie=>{const ke=ct?ru(ct,Za(Is.current?.currentTime??ls.get().time)).find(ft=>ft.id===ie):null;if(!ct||!ke)return;js&&$t();const cs=Za(Is.current?.currentTime??ls.get().time),Ps=uo({format:n,comp:ct,clip:ke,time:cs});Us({format:n,x:Ps.x,y:Ps.y,text:"",index:null,timeSec:cs,clip:{id:ke.id,name:km(ke)}})},Sn=ie=>{const ke=hv({format:n,start:ie.start,end:ie.end,duration:Os});ke&&(js&&$t(),Us({format:n,x:ke.x,y:ke.y,text:"",index:null,timeSec:ke.timeSec,range:ke.range}))},pa=()=>{if(!ct)return;const ie=ru(ct,Za(Is.current?.currentTime??ls.get().time)),ke=ie.filter(cs=>cs.type!=="audio").at(-1)??ie.at(-1);ke&&fa(ke.id)};ps.current=pa;const Fn=ie=>{const ke=Ls[ie-1];if(!ke)return;if(ke.format!==n){const Ps=ga(K,ke.format,{}).format,ft=ja(_,K[Ps],ue),Tn={...de};ft!==null&&ft!==K[Ps]?.star.version?Tn[Ps]=ft:delete Tn[Ps],Ct(Tn),Bs(es.format(e,t,ke.format));return}const cs={format:n,x:ke.x,y:ke.y,text:ke.note??"",index:ie-1,timeSec:ke.timeSec,...ke.clipId?{clip:{id:ke.clipId,name:ke.clipName??ke.clipId}}:{},...ke.range?{range:ke.range}:{}};if(!xe){const Ps=ja(_,K[se.format],ue);if(Ps===null)return;te(se.format,Ps),Ze&&ke.timeSec!==null&&(St.current=ke.timeSec),Us(cs);return}Ze&&(js&&$t(),ke.timeSec!==null&&Math.abs(ke.timeSec-ls.get().time)>.001&&Zt(ke.timeSec)),Us(cs)},_t=i.useRef(Fn);_t.current=Fn;const ea=()=>{if(!bs)return;const ie=bs.text.trim();if(ie){if(bs.index===null){const ke={format:n,x:bs.x,y:bs.y,timeSec:Ze?bs.timeSec??0:null,note:ie,...bs.clip?{clipId:bs.clip.id,clipName:wo(bs.clip.name)}:{},...bs.range?{range:bs.range}:{}};ue!==null&&_e(cs=>[...cs,{pin:ke,version:ue}])}else{const ke=Ye[bs.index]?.at;_e(cs=>cs.map((Ps,ft)=>ft===ke?{...Ps,pin:{...Ps.pin,note:ie}}:Ps))}Us(null)}},Wn=i.useCallback(ie=>{const ke=Ye[ie]?.at;_e(cs=>cs.filter((Ps,ft)=>ft!==ke)),Us(cs=>cs&&cs.index!==null?cs.index===ie?null:cs.index>ie?{...cs,index:cs.index-1}:cs:cs)},[Ye,_e]),Fa=i.useCallback(ie=>_t.current(ie+1),[]),dt=i.useCallback(ie=>nr({id:ie,preset:pt(O,ie),labels:be},x),[O,x,be]),ya=i.useCallback(({pins:ie})=>{qe(ie),J({}),j()},[qe,j]),Hn=i.useCallback(ie=>{const ke=ja(_,K[se.format],ie);ke!==null&&te(se.format,ke)},[_,K,se.format,te]),Cn=v?.variants,Pn=Cn&&!Cn.orphan?Cn:null,Lt=gm(Cn).discarded?m.web.variantGroup.discardedReadOnly:null,Es=_m({slug:e,creative:t,states:K,labelOf:dt,resumeFrom:v?.creative.resumeFrom?.version??null,onChanged:j,onError:Re,...Pn?{groupPick:(ie,ke)=>q.setVariantPick(e,Pn.host,ie,ke===null?null:{slug:t,version:ke})}:{}}),st=(v?.creative.brief.formats??[]).filter(ie=>K[ie]&&!K[ie].follows),sa=i.useMemo(()=>_.length&&st.length>1?{primaries:st.map(ie=>({id:ie,label:dt(ie),followers:Vo(K,ie).map(dt)})),followerOf:ie=>K[ie]?.follows??null,fallback:st.includes(se.format)?[se.format]:null,groups:mm(st,O,v?.creative.brief??{},x,m.web.formatUi.other)}:void 0,[_.length,st.join(","),K,dt,se.format,O,v?.creative.brief,x,m]),Yt=S.single?S.groupJob:is,An=i.useMemo(()=>Yt?a.events[Yt.id]??[]:[],[Yt,a.events]),[wa,ut]=i.useState(null),Gn=()=>{const ie=K[se.format],ke=Nc(ie,de[se.format]);if(!ie||ke===null||ie.history.length<2)return;const cs=ie.history.indexOf(ke),Ps=ie.history[cs-1]??ie.history[cs+1];ut({open:!0,init:Ps<ke?[Ps,ke]:[ke,Ps]})},[Qt,En]=i.useState(null);if(w&&!v)return s.jsx("div",{className:"ms-cv-state",children:s.jsx(Rt,{icon:"warn",title:f.tryAgain,sub:s.jsx("span",{role:"alert",children:f.loadFailed({detail:w})}),action:s.jsxs($,{variant:"ink",onClick:j,children:[s.jsx(F,{name:"refresh",size:13}),f.tryAgain]})})});if(!hs&&!Rs)return s.jsx("div",{ref:g,className:"ms-cv-state",children:s.jsx(Rt,{icon:"grid",title:h.unknownTitle({id:n}),sub:h.unknownSub,action:s.jsxs($,{variant:"ink",onClick:vn,children:[s.jsx(F,{name:"back",size:13}),m.web.shell.backAllFormats]})})});const at=v?.creative??null,Xs=U?.n??null,xa=at?.brief.durationSec??null,ta=Ze&&Os>0&&xa!==null&&hx(Os,xa),bn=[`${vs}×${Le}`,pm({width:vs,height:Le}),Ze&&Os?f.seconds({n:Vs(x,Os,{maximumFractionDigits:1})}):null].filter(Boolean).join(" · "),ka=Cs==="fit"||Ze?{width:`min(100cqw, calc(100cqh * ${vs/Le}))`,aspectRatio:`${vs} / ${Le}`}:{width:Math.round(vs*Cs),aspectRatio:`${vs} / ${Le}`},lr=!hs&&!xe&&U&&(Fe||us)&&ue!==null,Ot=K[n],na=Ot?.follows?dt(Ot.follows):null,Na=Ot?.follows?K[Ot.follows]?.star.version??null:null,Ws=!hs&&(fe?as:!!Fe)&&!gt,Et=ie=>{if(ie.range)return m.web.conversation.noteTitleRange(br(x,ie.range));const ke=Ze&&ie.timeSec!==null?h.pinAt({time:wt(ie.timeSec)}):void 0;return ie.clip?[m.web.conversation.noteTitleClip({name:ie.clip.name}),ke].filter(Boolean).join(" · "):ke};return s.jsxs("div",{ref:g,className:le("ms-fv",Ze?"ms-fv-video":"ms-fv-image"),"aria-busy":hs||void 0,children:[R?.title?ma.createPortal(s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"ms-crumb ms-last ms-fv-crumb",children:[s.jsx("span",{className:"ms-crumb-sep","aria-hidden":"true",children:"/"}),Oe?s.jsx(en,{channel:da(Oe.channel)}):null,s.jsx("b",{"aria-current":"page",title:[Oe?Dn(Oe.channel,x):null,bn].filter(Boolean).join(" · "),children:xn(Oe,n,x,be)})]}),s.jsx("span",{className:"ms-fv-meta",title:bn,children:bn}),ta&&at?s.jsx(Sb,{slug:e,creative:t,brief:at.brief,actual:Os,edited:U?.origin==="editor",disabled:Lt??(Qe?m.web.editor.busyAgent:null),onChanged:j}):null,Fe&&!Fe.verified?s.jsx(Qs,{tone:"warn",className:"ms-cv-state-pill",children:m.web.formatUi.unverified}):null]}),R.title):null,R?.end?ma.createPortal(s.jsxs(s.Fragment,{children:[Ot&&at&&Ot.follows&&na?s.jsxs("span",{className:"ms-fv-badge",children:[s.jsx(Vm,{label:ne,primary:na,primaryStar:Na,follower:n,actions:Es,busy:Qe}),s.jsx("span",{className:"ms-fv-follows",children:Na!==null?m.web.formatVersions.followsStar({primary:na,n:Na}):m.web.formatVersions.follows({primary:na})})]}):Ot&&at?s.jsx("span",{className:"ms-fv-badge",children:s.jsx(qm,{bar:!0,buttonRef:G,slug:e,creative:t,label:ne,state:Pn?{...Ot,star:{...Ot.star,version:Pn.group.picks[se.format]?.slug===t?Pn.group.picks[se.format].version:null,manual:Pn.group.picks[se.format]?.slug===t,newer:null}}:Ot,versions:_,shown:se.n,resumeFrom:at.resumeFrom?.version??null,labelOf:dt,actions:Es,busy:Qe,onView:ie=>te(n,ie),onCompare:Gn,subtitleHashes:X})}):null,s.jsx(Bm,{slug:e,creative:t,detail:v,version:U??ae,presets:O,live:a,onChanged:j,readOnly:Lt}),s.jsx(Dm,{jobs:Object.values(a.jobs),jobKey:v?.jobKey??null,scope:{version:U,format:se.format},disabled:!ae,onClick:()=>{ae&&En({open:!0,snapshot:{versions:_,states:K}})}}),us!==null&&!Qe||_.length&&at?s.jsx(Cb,{buttonRef:re,children:ie=>s.jsxs(s.Fragment,{children:[us!==null&&!Qe?s.jsx(Go,{icon:"copy",close:ie,run:()=>{Qn()},hint:m.web.instances.duplicateHint({label:ne}),disabled:Lt??(ln?m.web.instances.duplicate:null),children:m.web.instances.duplicate}):null,_.length&&at?s.jsx(Go,{icon:"clock",close:ie,run:()=>Ne(!0),children:C?m.web.canvas.versions.historyItemVariant({letter:C}):m.web.canvas.versions.historyItem}):null]})}):null,_.length&&at?s.jsx(Km,{slug:e,creative:t,versions:_,resumeFrom:at.resumeFrom?.version??null,actions:Es,open:oe,onClose:()=>Ne(!1),anchor:re}):null]}),R.end):null,Ze?s.jsxs("aside",{className:"ms-fv-side ms-fv-scenes","aria-label":h.scenes,"data-part":"l",children:[s.jsxs("div",{className:"ms-fv-side-head",children:[s.jsx("b",{children:h.scenes}),Os?s.jsx("span",{children:f.seconds({n:Vs(x,Os,{maximumFractionDigits:1})})}):null]}),fe?s.jsx(iM,{comp:mt,storyboard:Ge,state:De,clock:ls,onSeek:ie=>{js&&$t(),Zt(ie)},disabled:!Ws}):s.jsxs("div",{className:"ms-fv-soon",children:[s.jsx("span",{className:"ms-fv-soon-icon","aria-hidden":"true",children:s.jsx(F,{name:"clock",size:14})}),s.jsx("p",{children:h.scenesSoon})]})]}):null,s.jsxs("main",{className:"ms-fv-main","aria-label":ne,children:[s.jsxs("div",{className:"ms-fv-notes",children:[u.state?s.jsx(vr,{slug:e,state:u.state,reload:u.reload}):null,A?s.jsx("p",{role:"alert",className:"ms-cv-note ms-err",children:m.web.creative.formatsLoadFailed({detail:A})}):null,at?.resumeFrom?s.jsx("p",{className:"ms-cv-note ms-info",children:m.web.creative.resumeNote({n:at.resumeFrom.version})}):null,at&&(at.status==="error"||at.status==="interrupted")&&at.error&&!Qe?s.jsx("p",{role:"alert",className:"ms-cv-note ms-err",children:at.error}):null,Q?s.jsx("p",{role:"alert",className:"ms-cv-note ms-err",children:Q}):null,he&&je&&Xs!==null?s.jsxs("div",{className:"ms-idn-bar",children:[s.jsx(it,{label:m.web.identity.view,value:we,onChange:ze,options:[{value:"image",label:m.web.identity.viewImage,icon:"image"},{value:"sizes",label:m.web.identity.viewSizes,icon:"grid"}]}),he.files.some(ie=>ie.role==="vector")?s.jsx(Tb,{slug:e,creative:t,n:Xs,format:se.format,label:ne,kind:je,disabled:Qe,hasDark:Ke!==null}):null,je==="logo"&&Ke===null?s.jsxs("span",{className:"ms-idn-nodark",role:"note",title:m.web.identity.noDarkLogoTip,children:[s.jsx(F,{name:"refresh",size:13}),m.web.identity.noDarkLogo]}):null]}):null,Qe&&As?s.jsxs("div",{className:"ms-cv-note ms-info ms-fv-gen",children:[s.jsx("div",{className:"ms-progress ms-indet",role:"progressbar","aria-label":m.web.ui.progress,children:s.jsx("i",{})}),s.jsx("span",{className:"ms-cv-gen-step",children:As})]}):null]}),We&&he&&je&&Xs!==null?s.jsx("section",{className:"ms-fv-stage ms-idn-stage","aria-label":m.web.identity.sizesTitle,children:s.jsx(Eb,{slug:e,creative:t,n:Xs,set:he,kind:je})}):s.jsx("section",{className:"ms-fv-stage","aria-label":h.stage({label:ne}),children:s.jsxs("div",{ref:b,className:"ms-fv-frame",style:ka,children:[s.jsxs("div",{className:le("ms-fv-media",!hs&&!Fe&&!fe&&"ms-empty-frame"),onClick:()=>{Ze&&(Fe||fe)&&!xe?Jt():Ze&&js&&$t()},children:[hs?s.jsx("span",{className:"ms-cv-frame-note",children:s.jsx(Ts,{size:16,label:f.loading})}):fe&&Xs!==null?s.jsxs(s.Fragment,{children:[os&&!as?s.jsx("img",{className:"ms-fv-poster",src:os.url,alt:"",draggable:!1}):null,fs.state.kind==="ready"?s.jsx(di,{session:fs.state.session,title:m.web.render.playerFrame({label:`${ne} v${Xs}`}),onMedia:ee,onStall:fs.stalled,onShowing:fs.showing},Wt):null,s.jsx(db,{player:Hs,preview:tt}),fs.state.kind==="loading"||fs.state.kind==="busy"||fs.state.kind==="idle"?s.jsx("span",{className:"ms-cplayer-state",role:"status",children:fs.state.kind==="busy"?m.web.render.busy:m.web.render.loading}):null,fs.state.kind==="failed"?s.jsxs("span",{className:"ms-fv-failed",role:"alert",children:[s.jsx("span",{children:m.web.render.failed({detail:fs.state.message})}),s.jsxs($,{size:"sm",variant:"outline",onClick:ie=>{ie.stopPropagation(),fs.retry()},children:[s.jsx(F,{name:"refresh",size:12}),m.web.render.retry]})]}):null]}):Ee&&Xs!==null&&Ze?s.jsx("video",{ref:ie=>{Is.current=ie},src:Ee,poster:Xe,preload:"auto",playsInline:!0,loop:gn,"aria-label":`${ne} v${Xs}`,onTimeUpdate:ie=>ls.set(ie.currentTarget.currentTime,!0),onLoadedMetadata:ie=>{const ke=ie.currentTarget;vt(ke),Number.isFinite(ke.duration)&&ke.duration>0&&un(ke.duration),St.current!==null&&(ke.currentTime=St.current,ls.set(St.current,!0),St.current=null)},onDurationChange:ie=>{Number.isFinite(ie.currentTarget.duration)&&ie.currentTarget.duration>0&&un(ie.currentTarget.duration)},onPlay:()=>Ds(!0),onPause:()=>Ds(!1),onEnded:()=>Ds(!1),onError:()=>{mn(!0),Ds(!1)}},`${Ee}#${Wt}`):Ee&&Xs!==null?je==="logo"?s.jsxs("div",{className:"ms-idn-split",role:"img","aria-label":m.web.identity.logoSides({label:`${ne} v${Xs}`}),children:[s.jsxs("span",{className:"ms-idn-side ms-idn-light",children:[s.jsx("img",{src:Ee,alt:"",draggable:!1},Ee),s.jsx("span",{className:"ms-idn-sidelbl",children:m.web.identity.onLight})]}),s.jsxs("span",{className:"ms-idn-side ms-idn-dark",children:[s.jsx("img",{src:Ce??Ee,alt:"",draggable:!1},Ce??Ee),s.jsx("span",{className:"ms-idn-sidelbl",children:m.web.identity.onDark})]})]}):s.jsx("img",{src:Ee,alt:`${ne} v${Xs}`,draggable:!1},Ee):s.jsx("span",{className:"ms-cv-frame-note",children:Xs!==null?m.web.formatUi.missingIn({n:Xs}):ae?m.web.formatUi.missingIn({n:ae.n}):f.notGenerated}),gs?s.jsx("span",{className:"ms-shimmer","aria-hidden":"true"}):null,fn&&Oe?s.jsx(Jv,{preset:Oe}):null,gt?s.jsxs("span",{className:"ms-fv-failed",role:"alert",children:[s.jsx("span",{children:h.videoFailed}),s.jsxs($,{size:"sm",variant:"outline",onClick:ie=>{ie.stopPropagation(),$n(ke=>ke+1),mn(!1)},children:[s.jsx(F,{name:"refresh",size:12}),f.tryAgain]})]}):null,Ze&&Ws&&!js&&!xe?s.jsx("span",{className:"ms-fv-bigplay","aria-hidden":"true",children:s.jsx(F,{name:"play",size:22,fill:!0})}):null,xe&&Ws&&(!Ze||!js)?s.jsx(jb,{clock:ls,video:Ze,label:ne,onPlace:Ut}):null]}),xe&&Ws?s.jsx(yb,{clock:ls,video:Ze,marks:et,open:bs?.index??null,onOpen:Fn}):null,bs&&xe?s.jsx(Yv,{draft:bs,number:bs.index===null?Ls.length+1:bs.index+1,video:Ze,time:Et(bs),onText:ie=>Us(ke=>ke&&{...ke,text:ie}),onCommit:ea,onCancel:()=>Us(null),onDelete:()=>{bs.index!==null&&Wn(bs.index)}}):null]})}),xe&&Ws&&!We&&!bs&&!Me&&(!Ze||!js)?s.jsx(wb,{clock:ls,video:Ze}):null,Ae?s.jsx(bb,{open:!0,playhead:Is.current?.currentTime??ls.get().time,duration:Os,onSubmit:ie=>{ts(!1),Sn(ie)},onCancel:()=>ts(!1)}):null,lr?s.jsx("div",{className:"ms-cv-hint ms-lock ms-fv-hint",id:"ms-fv-comment-lock",role:"status",children:f.versions.commentsOn({n:ue})}):null,Oe?.safeZone&&(Fe||fe)&&!We?s.jsxs("span",{className:"ms-fv-safe-toggle",children:[s.jsx(Un,{size:"sm",on:fn,onChange:Nn,label:f.safeZones}),s.jsx("span",{"aria-hidden":"true",children:f.safeZones})]}):null,!Ze&&(Fe||fe)&&!We?s.jsxs("div",{className:"ms-cv-toolbar ms-fv-zoom",role:"toolbar","aria-label":h.zoom,children:[s.jsx("button",{type:"button",className:"ms-cv-tool ms-sm","aria-label":f.zoomOut,disabled:bt>0&&bt<=$r[0]+.001,onClick:()=>nt(-1),children:s.jsx(F,{name:"minus",size:13})}),s.jsx("span",{className:"ms-fv-zoom-pct",role:"status",children:bt?`${Vs(x,Math.round(bt*100))}%`:"—"}),s.jsx("button",{type:"button",className:"ms-cv-tool ms-sm","aria-label":f.zoomIn,disabled:bt>=$r.at(-1)-.001,onClick:()=>nt(1),children:s.jsx(F,{name:"plus",size:13})}),s.jsx("span",{className:"ms-cv-tool-sep","aria-hidden":"true"}),s.jsx("button",{type:"button",className:le("ms-fv-zoom-btn",Cs==="fit"&&"ms-on"),"aria-pressed":Cs==="fit",onClick:()=>ks("fit"),children:h.fit}),s.jsx("button",{type:"button",className:le("ms-fv-zoom-btn",Cs===1&&"ms-on"),"aria-pressed":Cs===1,"aria-label":h.actual,onClick:()=>ks(1),children:"100%"})]}):null,fe&&at?s.jsx(cb,{brief:at.brief,preview:tt,className:"ms-fv-locales"}):null,Ze?s.jsx(sb,{clock:ls,duration:Os,playing:js,disabled:!Ws,marks:xe?et:[],onRange:xe?Sn:void 0,onBand:ss,blocked:Ae||bs!==null,hint:xe?h.keys:h.keysLocked,extra:xe&&Ws?s.jsxs(s.Fragment,{children:[ct?s.jsx(lM,{clock:ls,comp:ct,onPick:fa}):null,Os>0?s.jsx($,{size:"sm",variant:"outline",icon:!0,className:"ms-fv-rangebtn","aria-label":m.web.conversation.rangeComment,title:m.web.conversation.rangeTip({keys:"R"}),"aria-keyshortcuts":"R",disabled:bs!==null,onClick:()=>{js&&$t(),ts(!0)},children:s.jsx(F,{name:"comment",size:13})}):null]}):void 0,onToggle:Jt,onStep:hn,onSeek:Zt,onPause:$t,onResume:rn,loop:gn,onLoop:zt,speed:Mt,onSpeed:Yn}):null]}),s.jsx("aside",{className:"ms-fv-side ms-fv-panel ms-chat-col","aria-label":f.panel,"data-part":"r",children:s.jsxs("div",{className:"ms-chat-card",children:[s.jsx("div",{className:"ms-tabs ms-panel ms-fv-tabs",children:s.jsx("span",{className:"ms-tab ms-on",children:h.chat})}),v?s.jsx(Ec,{slug:e,creative:t,entries:y,approvals:Ue,job:Yt,live:An,self:S.self,memberJobs:S.memberJobs,single:S.single,otherPins:ge,onRemoveOtherPin:ie=>qe([ie]),pins:Ls,onRemovePin:Wn,onEditPin:Fa,formatName:dt,canGenerate:_.length===0,onSent:ya,onSelectVersion:Hn,snapshots:a.snapshots,appliesTo:sa,brief:v.creative.brief,onBriefSaved:j,queued:v.creative.queued,onQueueChanged:j,versionSummary:ie=>{const ke=_.find(cs=>cs.n===ie);return ke?.origin==="editor"&&ke.request?ke.request:null}}):s.jsx("div",{className:"ms-cv-state",children:s.jsx(Ts,{size:16,label:f.loading})})]})}),wa?s.jsx(Im,{open:wa.open,onClose:()=>ut(ie=>ie&&{...ie,open:!1}),slug:e,creative:t,versions:_,presets:O,labels:at?.brief.formatLabels,states:K,format:se.format,initial:wa.init,actions:Es}):null,s.jsx(Ho,{open:!!Qt?.open,onClose:()=>En(ie=>ie&&{...ie,open:!1}),slug:e,creative:t,title:at?.title??"",snapshot:Qt?.snapshot??null,presets:O,labels:at?.brief.formatLabels,pattern:r??So,onSettings:l,jobs:a.jobs,...at&&Ht(at.brief)?{locales:Ht(at.brief)}:{},...v?.subtitles?.length?{subtitles:v.subtitles}:{}})]})}function lM({clock:e,comp:t,onPick:n}){const a=V().web.conversation,{settled:r}=Jn(e),l=ru(t,r);return s.jsx("span",{className:"ms-fv-clippick","data-part":"clip-picker",children:s.jsx(At,{variant:"pill",icon:"comment",label:a.clipPick,value:"",display:l.length?a.clipPick:a.clipPickNone,disabled:l.length===0,options:[{value:"",label:a.clipPick,disabled:!0},...[...l].reverse().map(o=>({value:o.id,label:km(o)}))],onChange:o=>{o&&n(o)}})})}function iM({comp:e,storyboard:t,state:n,clock:a,onSeek:r,disabled:l}){const o=V(),c=o.web.render,d=rs(),{time:m}=Jn(a),u=i.useMemo(()=>e&&e!=="failed"?kb(e,c):[],[e,c]);if(e===null)return s.jsx("p",{className:"ms-fv-sb-note",role:"status",children:c.scenesLoading});if(e==="failed")return s.jsx("p",{className:"ms-fv-sb-note",role:"status",children:c.scenesUnavailable});const h=Nb(u,m),f=n==="loading"||n==="busy";return s.jsxs(s.Fragment,{children:[s.jsx("ol",{className:"ms-fv-sb","aria-label":c.storyboard,children:u.map((x,p)=>s.jsx("li",{children:s.jsxs("button",{type:"button",className:le("ms-fv-sb-item",p===h&&"ms-on"),"aria-current":p===h||void 0,disabled:l,"aria-label":c.sceneAt({name:x.name,time:wt(x.start)}),onClick:()=>r(x.start),children:[s.jsx(vu,{frame:gu(t,x),state:n,width:e.width,height:e.height}),s.jsxs("span",{className:"ms-fv-sb-text",children:[s.jsx("b",{children:x.name}),s.jsxs("span",{children:[wt(x.start)," · ",o.web.editor.sceneLength({seconds:Vs(d,x.duration,{maximumFractionDigits:2})})]})]})]})},x.id??"whole"))}),s.jsx("span",{className:"ms-sr",role:"status","aria-live":"polite",children:f?c.storyboardLoading:""})]})}function oM(e){const t=new Map,n=[];for(const a of e){let r;switch(a.kind){case"clipProps":case"clipMedia":case"clipFlags":r=`${a.kind}:${a.clipId}`;break;case"trackFlags":r=`trackFlags:${a.trackId}`;break;case"clipTiming":r=`clipTiming:${a.clipId}`;break;case"sceneDuration":r=`sceneDuration:${a.sceneId}`;break;case"sceneOrder":r="sceneOrder";break;case"animationPreset":r=`animationPreset:${a.clipId}:${a.slot}`;break;case"htmlParam":r=`htmlParam:${a.clipId}:${a.key}`;break;case"addFont":r=`addFont:${a.font.family}`;break;case"svgContent":r=`svgContent:${a.clipId}`;break}const l=t.get(r);if(l===void 0){t.set(r,n.length),n.push(a);continue}const o=n[l];o.kind==="clipProps"&&a.kind==="clipProps"?n[l]={...o,props:{...o.props,...a.props}}:o.kind==="clipMedia"&&a.kind==="clipMedia"?n[l]={...o,...a}:o.kind==="clipFlags"&&a.kind==="clipFlags"?n[l]={...o,...a}:o.kind==="trackFlags"&&a.kind==="trackFlags"?n[l]={...o,...a}:o.kind==="svgContent"&&a.kind==="svgContent"?n[l]={...o,colors:o.colors+a.colors,texts:o.texts+a.texts,hidden:o.hidden+a.hidden}:n[l]=a}return n}const cM=1800;function dM({edits:e,nextN:t,blocked:n,saving:a,saved:r,onSave:l,onDiscard:o}){const c=V().web.editor,d=i.useRef(null),[m,u]=i.useState(!1);return i.useLayoutEffect(()=>{Gs(d.current,{y:-10})},[]),i.useLayoutEffect(()=>{r&&d.current&&qn(d.current,[{transform:"scale(1.04)"},{transform:"scale(1)"}],qs.m,Vt.spring)},[r]),s.jsxs("div",{ref:d,className:"ms-ed-pill",role:"group","aria-label":c.draft({n:e}),"data-saved":r?"":void 0,children:[r?s.jsxs("b",{className:"ms-ed-pill-ok",role:"status",children:[s.jsx(F,{name:"check",size:13,strokeWidth:2}),c.saved(r)]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-ed-dot","aria-hidden":"true"}),s.jsx("span",{className:"ms-ed-pill-text",role:"status",children:c.draft({n:e})}),s.jsx($,{size:"sm",variant:"ink",disabled:n!==null||a,loading:a,"aria-describedby":n!==null?"ms-ed-save-why":void 0,title:n??void 0,onClick:l,children:a?c.saving:c.saveAs({n:t})}),n!==null?s.jsx("span",{id:"ms-ed-save-why",className:"ms-sr",children:n}):null,s.jsx($,{size:"sm",variant:"ghost",disabled:a,onClick:()=>u(!0),children:c.discard})]}),s.jsx(rt,{open:m,onClose:()=>u(!1),label:c.discardTitle,width:440,children:s.jsxs("div",{className:"ms-ed-dialog",children:[s.jsx("h2",{children:c.discardTitle}),s.jsx("p",{children:c.discardBody({n:e})}),s.jsxs("div",{className:"ms-ed-dialog-foot",children:[s.jsx($,{variant:"ghost",onClick:()=>u(!1),children:c.keepEditing}),s.jsx($,{variant:"danger",onClick:()=>{u(!1),o()},children:c.discardConfirm})]})]})})]})}const Jl=200,uM=500,mM=(e,t,n)=>`${e}/${t}/${n}`,Kt=new Map,er=new Map,bu=new Set,Rb=e=>(bu.add(e),()=>{bu.delete(e)}),hM=()=>{for(const e of bu)e()};let ju=0,fM=0;const _a=()=>{ju+=1,hM()};function pM(e){const t=e.composition;return{id:e.primaryFormat,kind:t.duration===0?"image":"video",width:t.width,height:t.height}}function mi(e,t,n){const a=ey(e);return[...a?[a]:[],...sy(e,{format:n,files:t}).problems]}const xM=e=>new Map(e.files.map(t=>[t.path,{size:t.size}])),Ym=e=>e.ops.length>0||e.svgPending.size>0;function gM(e){const t=new Map;for(const n of e?.staged??[]){const a=e?.svgTexts.get(n.path);n.svgEdit&&a!==void 0&&t.set(n.path,a)}return t}function vM(e,t,n=pM(t)){const a=Kt.get(e);if(a&&Ym(a))return;const r=xM(t);for(const o of a?.staged??[])r.set(o.path,{size:o.size});const l=structuredClone(t.composition);Kt.set(e,{key:e,base:{n:t.n,format:t.primaryFormat,hash:t.hash},baseComposition:t.composition,composition:l,files:r,staged:a?.staged??[],stagedIn:a?.stagedIn??null,svgTexts:gM(a),svgPending:new Set,gen:++fM,ops:[],past:[],future:[],problems:mi(l,r,n),primaryFormat:t.primaryFormat,format:t.format,fonts:t.fonts,preset:n}),er.delete(e),_a()}function bM(e,t,n){const a=Kt.get(e);if(!a)return{ok:!1,problem:si("editor.badOp")};const r=fx(a.composition,t,{files:new Set(a.files.keys())});if(!r.ok)return r;const l=Date.now(),o=er.get(e),c=n?.coalesce!==void 0&&o?.key===n.coalesce&&(n.hold===!0||l-o.at<=uM)&&a.past.length>0;let d=a.past,m=a.ops;return c?m=[...a.ops.slice(0,-1),t]:(d=[...a.past,{composition:a.composition,ops:a.ops}],d.length>Jl&&(d=d.slice(d.length-Jl)),m=[...a.ops,t]),n?.coalesce!==void 0?er.set(e,{key:n.coalesce,at:l}):er.delete(e),Kt.set(e,{...a,composition:r.composition,ops:m,past:d,future:[],problems:mi(r.composition,a.files,a.preset)}),_a(),r}function jM(e,t){const n=Kt.get(e);if(!n||t.length===0)return{ok:!1,problem:si("editor.badOp")};let a=n.composition,r={ok:!0,composition:a};for(const o of t){if(r=fx(a,o,{files:new Set(n.files.keys())}),!r.ok)return r;a=r.composition}er.delete(e);let l=[...n.past,{composition:n.composition,ops:n.ops}];return l.length>Jl&&(l=l.slice(l.length-Jl)),Kt.set(e,{...n,composition:a,ops:[...n.ops,...t],past:l,future:[],problems:mi(a,n.files,n.preset)}),_a(),r}function yM(e,t,n){const a=Kt.get(e);!a||a.svgTexts.get(t)===n||(Kt.set(e,{...a,svgTexts:new Map(a.svgTexts).set(t,n)}),_a())}function wM(e,t,n){const a=Kt.get(e);if(!a||a.svgPending.has(t)===n)return;const r=new Set(a.svgPending);n?r.add(t):r.delete(t),Kt.set(e,{...a,svgPending:r}),_a()}function bp(e,t){const n=Kt.get(e);if(!n)return;const r=(t==="undo"?n.past:n.future).at(-1);if(!r)return;const l={composition:n.composition,ops:n.ops};er.delete(e),Kt.set(e,{...n,composition:r.composition,ops:r.ops,past:t==="undo"?n.past.slice(0,-1):[...n.past,l].slice(-Jl),future:t==="undo"?[...n.future,l]:n.future.slice(0,-1),problems:mi(r.composition,n.files,n.preset)}),_a()}function kM(e,t,n={}){const a=Kt.get(e);if(!a)return;const r=new Map(a.files).set(t.path,{size:t.size}),l=a.staged.find(m=>m.path===t.path),o=n.from??l?.from,c={...t,...o?{from:o}:{}},d=l?a.staged.map(m=>m.path===t.path?c:m):[...a.staged,c];Kt.set(e,{...a,files:r,staged:d,stagedIn:n.token??a.stagedIn,problems:mi(a.composition,r,a.preset)}),_a()}function NM(e,t){const n=Kt.get(e);!n||n.stagedIn===t||(Kt.set(e,{...n,stagedIn:t}),_a())}function SM(e){er.delete(e),Kt.delete(e)&&_a()}const CM=e=>({open:(t,n)=>vM(e,t,n),apply:(t,n)=>bM(e,t,n),applyAll:t=>jM(e,t),svgText:(t,n)=>yM(e,t,n),svgPending:(t,n)=>wM(e,t,n),undo:()=>bp(e,"undo"),redo:()=>bp(e,"redo"),discard:()=>SM(e),stage:(t,n)=>kM(e,t,n),stagedIn:t=>NM(e,t),endRun:()=>{er.delete(e)}});function jp(e){const t=i.useSyncExternalStore(Rb,()=>Kt.get(e)??null,()=>Kt.get(e)??null),n=i.useMemo(()=>CM(e),[e]);return[t,n]}const va=e=>Kt.get(e)??null;function EM(){let e=0;for(const t of Kt.values())Ym(t)&&(e+=1);return e}function TM(){return i.useSyncExternalStore(Rb,()=>ju,()=>ju),EM()}const Wi=Ym,Mb=i.createContext(null);function Xt(){const e=i.useContext(Mb);if(!e)throw new Error("useEditor outside the editor");return e}const yu=new Set;function RM(e){return yu.add(e),()=>{yu.delete(e)}}function MM(e){for(const t of yu)if(t.blocks(e))return t.ask(e),!0;return!1}const Xo=1e-6;function $M(e,t){return e.flatMap(n=>n.clips).filter(n=>n.start<t.start+t.duration-Xo&&n.start+n.duration>t.start+Xo)}function FM(e,t){return e[Nb(e,t)]}function PM(){const e=V(),t=e.web.editor,n=e.web.render,a=rs(),{slug:r,creative:l,primary:o,draft:c,actions:d,controls:m,selection:u,select:h,readOnly:f}=Xt(),x=c.composition,p=i.useMemo(()=>[...x.scenes].sort((K,I)=>K.start-I.start),[x.scenes]),{time:g}=Jn(m.clock),b=FM(p,g),v=i.useMemo(()=>ty(x),[x]),y=v.ok?null:x.tracks.flatMap(K=>K.clips).find(K=>K.id===v.clipId),w=v.ok?null:rl(si("editor.sceneOrderBlocked",{clip:y?.name??v.clipId}),a),{storyboard:j,state:S}=ci({slug:r,creative:l,n:c.base.n,format:o,hash:c.base.hash,enabled:!0}),k=S==="loading"||S==="busy",E=i.useMemo(()=>kb(x,n),[x,n]),N=K=>E.find(I=>I.id===K.id)?.name??K.id,[C,R]=i.useState(""),[P,z]=i.useState(null),O=i.useRef(null),T=(K,I)=>{if(!v.ok||K===I||I<0||I>=p.length)return!1;const H=p.map(se=>se.id),[de]=H.splice(K,1);H.splice(I,0,de);const J=d.apply({kind:"sceneOrder",order:H});return J.ok&&R(t.reorderedTo({name:N(p[K]),n:I+1,total:p.length})),J.ok},W=i.useRef(null),Z=i.useRef(()=>{});i.useEffect(()=>()=>Z.current(),[]);const A=(K,I)=>{let H=0;return[...O.current?.children??[]].forEach((de,J)=>{if(J===I)return;const se=de.getBoundingClientRect();K>=se.top+se.height/2&&(H+=1)}),H},L=K=>I=>{if(!v.ok||I.button!==0)return;I.preventDefault();try{I.currentTarget.setPointerCapture?.(I.pointerId)}catch{}W.current={from:K,to:K},z(K);const H=J=>{W.current&&(W.current.to=A(J.clientY,W.current.from),z(W.current.to))},de=J=>{const se=W.current;Z.current(),se&&J.type==="pointerup"&&T(se.from,A(J.clientY,se.from))};Z.current=()=>{window.removeEventListener("pointermove",H),window.removeEventListener("pointerup",de),window.removeEventListener("pointercancel",de),W.current=null,z(null),Z.current=()=>{}},window.addEventListener("pointermove",H),window.addEventListener("pointerup",de),window.addEventListener("pointercancel",de)},_=K=>I=>{if(I.key!=="ArrowUp"&&I.key!=="ArrowDown")return;I.preventDefault(),I.stopPropagation(),T(K,K+(I.key==="ArrowUp"?-1:1));const H=p[K].id;requestAnimationFrame(()=>O.current?.querySelector(`[data-scene="${CSS.escape(H)}"] .ms-sc-grip`)?.focus())},X=b?$M(x.tracks,b):[],ae=K=>{(g<K.start-Xo||g>=K.start+K.duration-Xo)&&m.seek(K.start)};return s.jsxs("div",{className:"ms-sc",children:[p.length===0?s.jsx("ol",{className:"ms-fv-sb ms-sc-list","aria-label":t.scenesAria,children:s.jsx("li",{className:"ms-sc-card ms-on","data-scene":"",children:s.jsxs("button",{type:"button",className:"ms-fv-sb-item ms-on","aria-current":!0,disabled:!m.ready,"aria-label":n.sceneAt({name:n.wholeVideo,time:wt(0)}),onClick:()=>m.seek(0),children:[s.jsx(vu,{frame:gu(j,{id:null,name:n.wholeVideo}),state:S,width:x.width,height:x.height}),s.jsxs("span",{className:"ms-fv-sb-text",children:[s.jsx("b",{children:n.wholeVideo}),s.jsxs("span",{children:[wt(0)," · ",t.sceneLength({seconds:Vs(a,x.duration,{maximumFractionDigits:2})})]})]})]})})}):s.jsx("ol",{ref:O,className:"ms-fv-sb ms-sc-list","aria-label":t.scenesAria,children:p.map((K,I)=>{const H=N(K);return s.jsxs("li",{className:le("ms-sc-card",P===I&&"ms-over",K.id===b?.id&&"ms-on"),"data-scene":K.id,children:[s.jsxs("button",{type:"button",className:le("ms-fv-sb-item",K.id===b?.id&&"ms-on"),"aria-current":K.id===b?.id||void 0,disabled:!m.ready,"aria-label":n.sceneAt({name:H,time:wt(K.start)}),onClick:()=>m.seek(K.start),children:[s.jsx(vu,{frame:gu(j,{id:K.id,name:H}),state:S,width:x.width,height:x.height}),s.jsxs("span",{className:"ms-fv-sb-text",children:[s.jsx("b",{children:H}),s.jsxs("span",{children:[wt(K.start)," · ",t.sceneLength({seconds:Vs(a,K.duration,{maximumFractionDigits:2})})]})]})]}),s.jsx("span",{className:"ms-sc-grip-wrap",title:w??void 0,children:s.jsx("button",{type:"button",className:"ms-sc-grip",disabled:!v.ok||!!f,"aria-label":t.reorderScene({name:H}),title:f||w||void 0,onPointerDown:L(I),onKeyDown:_(I),children:s.jsx(F,{name:"menu",size:13})})})]},K.id)})}),w?s.jsx("p",{className:"ms-sc-why",role:"note",children:w}):null,s.jsx("span",{className:"ms-sr",role:"status","aria-live":"polite",children:C||(k?n.storyboardLoading:"")}),b?s.jsxs("section",{className:"ms-sc-in","aria-label":t.inThisScene,children:[s.jsx("h3",{children:t.inThisScene}),X.length===0?s.jsx("p",{className:"ms-fv-sb-note",children:t.inSceneNone}):s.jsx("ul",{children:X.map(K=>s.jsx("li",{children:s.jsx("button",{type:"button",className:le("ms-sc-clip",K.id===u&&"ms-on"),"aria-pressed":K.id===u,onClick:()=>{h(K.id),ae(K)},children:s.jsx("b",{children:K.name??K.id})})},K.id))})]}):null]})}const kd=8,yp=15,$b=6,AM={nw:[-1,-1],ne:[1,-1],se:[1,1],sw:[-1,1]},Zo=e=>e*Math.PI/180,LM=e=>e*180/Math.PI,Or=e=>Math.round(e*1e3)/1e3,IM=e=>Math.round(e*100)/100;function go(e,t,n){const a=Math.cos(Zo(n)),r=Math.sin(Zo(n));return{x:e*a-t*r,y:e*r+t*a}}const sr=(e,t)=>t>0?e/t:0;function Fb(e,t){return{x:e?.x??0,y:e?.y??0,width:e?.width??t.width,height:e?.height??t.height,rotation:e?.rotation??0,scale:e?.scale??1}}const Pb=e=>({x:e.x+e.width/2,y:e.y+e.height/2});function Ab(e){const t=Pb(e),n=e.width*e.scale/2,a=e.height*e.scale/2,r=(l,o)=>{const c=go(l*n,o*a,e.rotation);return{x:t.x+c.x,y:t.y+c.y}};return{nw:r(-1,-1),ne:r(1,-1),se:r(1,1),sw:r(-1,1)}}function zM(e){const t=Object.values(Ab(e)),n=t.map(o=>o.x),a=t.map(o=>o.y),r=Math.min(...n),l=Math.min(...a);return{x:r,y:l,width:Math.max(...n)-r,height:Math.max(...a)-l}}function OM(e,t){const n=Math.abs(Math.cos(Zo(t))),a=Math.abs(Math.sin(Zo(t))),r=n*n-a*a;if(Math.abs(r)<.05)return null;const l=(e.width*n-e.height*a)/r,o=(e.height*n-e.width*a)/r;return l>0&&o>0?{width:l,height:o}:null}function Lb(e,t,n,a){return{x:Or(e.x+sr(t,a)),y:Or(e.y+sr(n,a))}}function DM(e,t,n,a,r,l={}){const o=e.scale,[c,d]=AM[t],m=e.width*o,u=e.height*o;if(!(o>0)||!(m>0)||!(u>0)||!(r>0))return{x:e.x,y:e.y,width:e.width,height:e.height};const h=go(sr(n,r),sr(a,r),-e.rotation);let f=m+c*h.x,x=u+d*h.y;if(l.keepAspect){const S=Math.max(1+(c*h.x*m+d*h.y*u)/(m*m+u*u),kd/Math.min(m,u));f=m*S,x=u*S}else f=Math.max(f,kd),x=Math.max(x,kd);const p=Pb(e),g=go(-c*m/2,-d*u/2,e.rotation),b={x:p.x+g.x,y:p.y+g.y},v=go(c*f/2,d*x/2,e.rotation),y={x:b.x+v.x,y:b.y+v.y},w=f/o,j=x/o;return{x:Or(y.x-w/2),y:Or(y.y-j/2),width:Or(w),height:Or(j)}}const wp=(e,t)=>LM(Math.atan2(t.y-e.y,t.x-e.x));function Qm(e){const t=((e+180)%360+360)%360-180;return t===-180?180:t}function BM(e,t,n,a,r={}){let l=e.rotation+(wp(t,a)-wp(t,n));return r.snap&&(l=Math.round(l/yp)*yp),{rotation:IM(Qm(l))}}function UM(e,t,n){const a=[0,e/2,e],r=[0,t/2,t];return n&&(a.push(n.left,e-n.right),r.push(n.top,t-n.bottom)),{x:[...new Set(a)].sort((l,o)=>l-o),y:[...new Set(r)].sort((l,o)=>l-o)}}function Jo(e,t,n){let a=null;for(const r of e)for(const l of t){const o=l-r;Math.abs(o)<=n&&(a===null||Math.abs(o)<Math.abs(a.by))&&(a={by:o,line:l})}return a}function _M(e,t,n,a,r,l=$b){const o={...e,...Lb(e,t,n,a)},c=zM(o),d=sr(l,a),m=Jo([c.x,c.x+c.width/2,c.x+c.width],r.x,d),u=Jo([c.y,c.y+c.height/2,c.y+c.height],r.y,d),h=[];return m&&h.push({axis:"x",at:m.line}),u&&h.push({axis:"y",at:u.line}),{dx:t+(m?m.by*a:0),dy:n+(u?u.by*a:0),guides:h}}function qM(e,t,n,a,r,l,o=$b){if(Math.abs(Qm(e.rotation))>1e-9||!(r>0))return{dx:n,dy:a,guides:[]};const c=Ab(e)[t],d=sr(o,r),m=Jo([c.x+sr(n,r)],l.x,d),u=Jo([c.y+sr(a,r)],l.y,d),h=[];return m&&h.push({axis:"x",at:m.line}),u&&h.push({axis:"y",at:u.line}),{dx:n+(m?m.by*r:0),dy:a+(u?u.by*r:0),guides:h}}const VM=600,KM=e=>Math.round(e*100)/100,WM=["nw","ne","se","sw"],HM=e=>typeof requestAnimationFrame=="function"?requestAnimationFrame(e):window.setTimeout(e,16),GM=e=>{typeof cancelAnimationFrame=="function"?cancelAnimationFrame(e):window.clearTimeout(e)};function Nd(e,t,n){const a=t.x-e.from.x,r=t.y-e.from.y;let l,o=[];if(e.kind.k==="move"){const u=n.snap?_M(e.start,a,r,e.scale,e.lines):{dx:a,dy:r,guides:[]};l=Lb(e.start,u.dx,u.dy,e.scale),o=u.guides}else if(e.kind.k==="resize"){const u=n.snap?qM(e.start,e.kind.corner,a,r,e.scale,e.lines):{dx:a,dy:r,guides:[]};l=DM(e.start,e.kind.corner,u.dx,u.dy,e.scale,{keepAspect:t.shift}),o=u.guides}else l=BM(e.start,e.centre,e.from,{x:t.x,y:t.y},{snap:t.shift});n.onGuides(o);const c={...e.start,rotation:KM(Qm(e.start.rotation))};!(!(e.kind.k==="rotate"&&a===0&&r===0)&&Object.keys(l).some(u=>l[u]!==c[u]))&&e.last===null||(e.last=l,n.actions.apply({kind:"clipProps",clipId:e.clipId,props:l},{coalesce:`drag:${e.clipId}`,hold:!0}))}function XM({clip:e,locked:t,bounds:n,scale:a,origin:r,onGuides:l}){const c=V().web.editor,{draft:d,actions:m,controls:u,snap:h}=Xt(),f=d.composition,x=e.props??{},p=i.useCallback(L=>{if(e.type!=="text")return{width:f.width,height:f.height};const _=x.rotation??0,X=x.scale??1,ae=L&&a>0&&X>0?OM(L,_)??{width:L.width,height:L.height}:null;return ae?{width:ae.width/(a*X),height:ae.height/(a*X)}:{width:0,height:0}},[e.type,f.width,f.height,x.rotation,x.scale,a]),g=Fb(x,p(n)),[b,v]=i.useState(null),y=i.useRef(0),w=i.useRef(null),[j,S]=i.useState(!1),k=n?{x:n.x+n.width/2,y:n.y+n.height/2}:null,E=L=>({x:(g.x+g.width/2)*a+L.x,y:(g.y+g.height/2)*a+L.y}),N=b?E(b):k;i.useEffect(()=>{if(!b||j||!k)return;const L=E(b);Math.abs(L.x-k.x)<1.5&&Math.abs(L.y-k.y)<1.5&&(window.clearTimeout(y.current),v(null))}),i.useEffect(()=>()=>{window.clearTimeout(y.current)},[]);const C=i.useRef({live:g,scale:a,snap:h,comp:f,safe:d.preset.safeZone,actions:m,controls:u,onGuides:l});C.current={live:g,scale:a,snap:h,comp:f,safe:d.preset.safeZone,actions:m,controls:u,onGuides:l};const R=e.id,P=i.useRef(null);if(!P.current){const L=()=>{const X=w.current;return X?(w.current=null,window.removeEventListener("pointermove",_.move),window.removeEventListener("pointerup",_.end),window.removeEventListener("pointercancel",_.end),GM(X.raf),X):null},_={move(X){const ae=w.current;ae&&(ae.pending={x:X.clientX,y:X.clientY,shift:X.shiftKey},!ae.raf&&(ae.raf=HM(()=>{ae.raf=0;const K=ae.pending;K&&w.current===ae&&Nd(ae,K,C.current)})))},end(X){const ae=L();ae&&(X.type==="pointerup"?Nd(ae,{x:X.clientX,y:X.clientY,shift:X.shiftKey},C.current):ae.pending&&Nd(ae,ae.pending,C.current),C.current.actions.endRun(),C.current.onGuides([]),S(!1),ae.last&&(v(ae.off),window.clearTimeout(y.current),y.current=window.setTimeout(()=>v(null),VM)))},stop(){L()&&C.current.actions.endRun()}};P.current=_}i.useEffect(()=>()=>{P.current?.stop()},[]);const z=L=>_=>{if(_.button!==0||!N||(_.stopPropagation(),_.preventDefault(),t))return;const X=C.current,ae=r();if(!ae||!(X.scale>0))return;X.controls.pause(),X.actions.endRun();try{_.currentTarget.setPointerCapture?.(_.pointerId)}catch{}const K=X.live,I={x:(K.x+K.width/2)*X.scale,y:(K.y+K.height/2)*X.scale},H={kind:L,clipId:R,start:K,from:{x:_.clientX,y:_.clientY},scale:X.scale,centre:{x:ae.left+N.x,y:ae.top+N.y},off:{x:N.x-I.x,y:N.y-I.y},lines:UM(X.comp.width,X.comp.height,X.safe),pending:null,last:null,raf:0};window.clearTimeout(y.current),v(null),w.current=H,S(!0),window.addEventListener("pointermove",P.current.move),window.addEventListener("pointerup",P.current.end),window.addEventListener("pointercancel",P.current.end)};if(!N||!(a>0))return null;const O=g.width*g.scale*a,T=g.height*g.scale*a,W=N.y-(T/2+30)*Math.cos(g.rotation*Math.PI/180)<4,Z=c.coords({x:String(Math.round(g.x)),y:String(Math.round(g.y)),w:String(Math.round(g.width)),h:String(Math.round(g.height))}),A={nw:c.resizeNw,ne:c.resizeNe,se:c.resizeSe,sw:c.resizeSw};return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:le("ms-stage-box",t&&"ms-locked",j&&"ms-dragging",W&&"ms-flip"),"data-clip":R,role:"group","aria-label":c.selectionBox({clip:e.name??R}),title:t?c.locked:void 0,"aria-disabled":t||void 0,style:{width:O,height:T,transform:`translate(${N.x-O/2}px, ${N.y-T/2}px) rotate(${g.rotation}deg)`},onPointerDown:z({k:"move"}),children:[s.jsx("span",{className:"ms-stage-move","aria-label":c.moveHandle}),WM.map(L=>s.jsx("span",{className:le("ms-stage-handle",`ms-h-${L}`),"data-handle":L,"aria-hidden":"true","aria-label":A[L],title:t?c.locked:void 0,onPointerDown:z({k:"resize",corner:L})},L)),s.jsx("span",{className:"ms-stage-stem","aria-hidden":"true"}),s.jsx("span",{className:"ms-stage-handle ms-h-rot","data-handle":"rotate","aria-hidden":"true","aria-label":c.rotateHandle,title:t?c.locked:void 0,onPointerDown:z({k:"rotate"}),children:s.jsx(F,{name:"rotate",size:11})})]}),s.jsx("div",{className:le("ms-stage-label",t&&"ms-locked"),role:"status",style:{left:N.x,top:N.y+Math.max(O,T)/2+14},children:t?s.jsxs(s.Fragment,{children:[s.jsx(F,{name:"lock",size:11}),c.locked]}):Z})]})}const kp="http://www.w3.org/2000/svg",ZM=`
|
|
17
|
+
svg.ms-svg-ov { display: block; width: 100%; height: 100%; overflow: hidden; visibility: hidden; pointer-events: none; }
|
|
18
|
+
svg.ms-svg-ov * { pointer-events: painted; }
|
|
19
|
+
[data-ms-hover], [data-ms-hover] * { visibility: visible !important; fill-opacity: 0 !important; stroke: var(--accent, currentColor) !important;
|
|
20
|
+
stroke-opacity: .8 !important; stroke-width: 1.5px !important; stroke-dasharray: 4 3 !important; vector-effect: non-scaling-stroke; }
|
|
21
|
+
[data-ms-picked], [data-ms-picked] * { visibility: visible !important; fill: var(--accent, currentColor) !important; fill-opacity: .14 !important;
|
|
22
|
+
stroke: var(--accent, currentColor) !important; stroke-opacity: 1 !important; stroke-width: 2px !important; stroke-dasharray: none !important; vector-effect: non-scaling-stroke; }
|
|
23
|
+
`,JM=/::?(?:host-context|host|slotted|part)(?![a-z0-9_-])/i,YM={contain:"xMidYMid meet",cover:"xMidYMid slice",fill:"none"};function QM({clip:e,text:t,box:n,picked:a,hover:r,handle:l}){const o=i.useRef(null),c=i.useRef(null),d=i.useMemo(()=>{const u=_l(t);return u.ok?new Set(Ru(u.doc).map(h=>h.path)):new Set},[t]),m=e.props.fit??"cover";return i.useLayoutEffect(()=>{const u=o.current;if(!u)return;const h=u.shadowRoot??u.attachShadow({mode:"open"}),f=document.createElement("style");f.textContent=ZM;const x=_l(t);if(!x.ok){h.replaceChildren(f),c.current=null;return}const p=document.importNode(x.doc.documentElement,!0);if(p.namespaceURI!==kp){h.replaceChildren(f),c.current=null;return}if(!p.hasAttribute("viewBox")){const g=parseFloat(p.getAttribute("width")??""),b=parseFloat(p.getAttribute("height")??"");g>0&&b>0&&p.setAttribute("viewBox",`0 0 ${g} ${b}`)}p.setAttribute("width","100%"),p.setAttribute("height","100%"),p.setAttribute("preserveAspectRatio",YM[m]),p.setAttribute("class","ms-svg-ov"),p.setAttribute("aria-hidden","true");for(const g of[...p.getElementsByTagNameNS(kp,"style")])JM.test(g.textContent??"")&&g.remove();h.replaceChildren(f,p),c.current=p},[t,m]),i.useEffect(()=>{const u=c.current;if(u)for(const[h,f]of[["data-ms-picked",a],["data-ms-hover",r!==a?r:null]]){for(const p of u.querySelectorAll(`[${h}]`))p.removeAttribute(h);const x=f!==null?e$(u,f):null;x&&x.setAttribute(h,"")}},[a,r,t,m]),i.useImperativeHandle(l,()=>({hit(u,h){const f=c.current,x=o.current?.shadowRoot;if(!f||!x?.elementsFromPoint)return null;const p=x.elementsFromPoint(u,h).find(g=>g!==f&&f.contains(g));for(let g=p??null;g&&g!==f;g=g.parentElement){const b=ny(f,g);if(b!==null&&d.has(b))return b}return null}}),[d]),s.jsx("div",{className:"ms-svg-overlay","data-slot":"svg-overlay-box","data-clip":e.id,"aria-hidden":"true",style:{width:n.width,height:n.height,transform:`translate(${n.cx-n.width/2}px, ${n.cy-n.height/2}px) rotate(${n.rotation}deg)`},children:s.jsx("div",{ref:o,className:"ms-svg-host","data-slot":"svg-overlay"})})}function e$(e,t){let n=e;if(t==="")return n;for(const a of t.split("/")){if(!/^\d{1,6}$/.test(a)||!n)return null;n=n.children[Number(a)]??null}return n}const s$=4;function hi(e,t){if(t===null)return null;for(const n of e)for(const a of n.clips)if(a.id===t)return{clip:a,locked:!!(a.locked||n.locked||n.kind==="subtitles")};return null}function t$({className:e}){const{player:t,selection:n,select:a,draft:r,controls:l,svgElement:o,selectSvgElement:c}=Xt(),d=i.useRef(null),[m,u]=i.useState(()=>t?.clipBounds??null),[h,f]=i.useState([]);i.useEffect(()=>{t?.select(n)},[t,n]),i.useEffect(()=>{if(!t){u(null);return}const R=()=>u(t.clipBounds?{...t.clipBounds}:null);return t.addEventListener("clipbounds",R),R(),()=>t.removeEventListener("clipbounds",R)},[t]);const x=hi(r.composition.tracks,n),p=m&&m.clipId===n?m:null,g=i.useCallback(()=>d.current?.getBoundingClientRect()??null,[]),b=p?.scale??0,v=x&&x.clip.type==="svg"?x.clip:null,y=v?r.svgTexts.get(v.src):void 0,w=v&&y!==void 0&&!l.playing&&p?.bounds&&b>0?(()=>{const R=Fb(v.props,{width:r.composition.width,height:r.composition.height}),P=p.bounds;return{width:R.width*R.scale*b,height:R.height*R.scale*b,cx:P.x+P.width/2,cy:P.y+P.height/2,rotation:R.rotation}})():null,j=i.useRef(null),S=i.useRef(null),[k,E]=i.useState(null);i.useEffect(()=>{E(null)},[n,y]);const N=R=>{if(!w||R.buttons!==0)return;const P=j.current?.hit(R.clientX,R.clientY)??null;P!==k&&E(P)},C=R=>{const P=S.current;if(S.current=null,!w||!P||Math.hypot(R.clientX-P.x,R.clientY-P.y)>s$)return;const z=j.current?.hit(R.clientX,R.clientY)??null;z!==null&&c(z)};return s.jsxs("div",{ref:d,className:le("ms-stage-layer",e),"data-slot":"stage-layer",onPointerDown:R=>{R.target===R.currentTarget&&R.button===0&&a(null)},onPointerDownCapture:R=>{S.current=R.button===0?{x:R.clientX,y:R.clientY}:null},onPointerMove:N,onPointerLeave:()=>E(null),onClick:C,children:[v&&w&&y!==void 0?s.jsx(QM,{clip:v,text:y,box:w,picked:o,hover:k,handle:j},v.id):null,x&&x.clip.type!=="audio"?s.jsx(XM,{clip:x.clip,locked:x.locked,bounds:p?.bounds??null,scale:b,origin:g,onGuides:f},x.clip.id):null,h.map(R=>s.jsx("span",{className:le("ms-stage-guide",R.axis==="x"?"ms-gx":"ms-gy"),"aria-hidden":"true",style:R.axis==="x"?{left:R.at*b}:{top:R.at*b}},`${R.axis}${R.at}`))]})}function n$(e,t){const n=hi(e.composition.tracks,t);return!!(n&&n.clip.type!=="audio")}function a$(e,t,n,a,r){const l=hi(e.composition.tracks,n);if(!l||l.clip.type==="audio")return{ok:!1,reason:"none"};if(l.locked)return{ok:!1,reason:"locked"};const o=l.clip.props??{},c=t.apply({kind:"clipProps",clipId:l.clip.id,props:{x:(o.x??0)+a,y:(o.y??0)+r}},{coalesce:`nudge:${l.clip.id}`});return c.ok?{ok:!0}:{ok:!1,reason:"refused",result:c}}function r$({clip:e,left:t,width:n,selected:a,locked:r,hidden:l,label:o,onDrag:c,onKey:d}){const m=u=>h=>{h.stopPropagation(),c(u,h)};return s.jsxs("div",{className:le("ms-tl-clip",`ms-k-${e.type}`,a&&"ms-on",r&&"ms-locked",l&&"ms-dim"),role:"button",tabIndex:0,"aria-pressed":a,"aria-label":o,"aria-keyshortcuts":"ArrowLeft ArrowRight [ ]","data-clip":e.id,style:{left:t,width:n},onPointerDown:u=>c("move",u),onKeyDown:d,children:[s.jsx("span",{className:"ms-tl-edge ms-e-start","data-edge":"start","aria-hidden":"true",onPointerDown:m("start")}),r?s.jsx(F,{name:"lock",size:11}):null,s.jsx("span",{className:"ms-tl-clip-name",children:e.name??e.id}),s.jsx("span",{className:"ms-tl-edge ms-e-end","data-edge":"end","aria-hidden":"true",onPointerDown:m("end")})]})}const l$={visual:"image",video:"video",text:"text",audio:"music",subtitles:"text"};function i$({track:e,name:t,onFlag:n}){const a=V().web.editor,r=!!e.hidden,l=ur(e),o=!!e.muted,c=r?a.showTrack({name:t}):a.hideTrack({name:t}),d=l?a.unlockTrack({name:t}):a.lockTrack({name:t}),m=o?a.unmuteTrack({name:t}):a.muteTrack({name:t});return s.jsxs("div",{className:le("ms-tl-head",r&&"ms-dim"),role:"group","aria-label":t,"data-track-head":e.id,children:[s.jsx(F,{name:l$[e.kind],size:13}),s.jsx("span",{className:"ms-tl-name",title:t,children:t}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":c,title:c,onClick:()=>n("hidden",!r),children:s.jsx(F,{name:r?"eyeOff":"eye",size:13})}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":d,title:d,disabled:e.kind==="subtitles",onClick:()=>n("locked",!l),children:s.jsx(F,{name:l?"lock":"unlock",size:13})}),e.kind==="audio"?s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":m,title:m,onClick:()=>n("muted",!o),children:s.jsx(F,{name:o?"mute":"volume",size:13})}):null]})}const Fr=168,Np=720,o$=120,c$=.0015,d$=6e3,u$={text:"clipText",shape:"clipShape",image:"clipImage",svg:"clipSvg",video:"clipVideo",html:"clipHtml",audio:"clipAudio",subtitles:"clipSubtitles"},m$=i.memo(function({pps:t,fps:n,t0:a,t1:r,seconds:l}){const{major:o,frames:c}=JR(t,n,a,r);return s.jsxs(s.Fragment,{children:[c.map(d=>s.jsx("i",{className:"ms-tl-tick ms-f",style:{left:zn(d,t)}},`f${d}`)),o.map(d=>s.jsx("span",{className:"ms-tl-tick ms-m",style:{left:zn(d,t)},children:s.jsx("b",{children:l(d)})},d))]})});function h$({clock:e}){const{time:t}=Jn(e);return s.jsx(s.Fragment,{children:wt(t)})}function f$({clock:e,duration:t,label:n,disabled:a,width:r,onPointerDown:l,onKeyDown:o,children:c},d){const m=V().web.formatView,{settled:u}=Jn(e);return s.jsx("div",{ref:d,className:"ms-tl-ruler",role:"slider",tabIndex:a?-1:0,"aria-label":n,"aria-disabled":a||void 0,"aria-valuemin":0,"aria-valuemax":Math.round(t*1e3)/1e3,"aria-valuenow":Math.round(u*1e3)/1e3,"aria-valuetext":m.positionText({time:wt(u),total:wt(t)}),style:{width:r},onPointerDown:l,onKeyDown:o,children:c})}const p$=i.forwardRef(f$);function x$({clock:e,pps:t}){const{time:n}=Jn(e);return s.jsx("span",{className:"ms-tl-playhead",style:{left:Fr+zn(n,t)},"aria-hidden":"true"})}function g$({clock:e,pps:t,label:n,onPointerDown:a}){const{time:r}=Jn(e);return s.jsx("span",{className:"ms-tl-grip",style:{left:zn(r,t)},title:n,"aria-hidden":"true",onPointerDown:a})}function v$({loop:e,onLoop:t,speed:n,onSpeed:a,marks:r=[],overlay:l,onRange:o,onCommentClip:c,onCommentRange:d,canCommentClip:m=!0}){const u=V(),h=u.web.editor,f=u.web.formatView,x=u.web.conversation,p=u.web.render,g=rs(),{slug:b,creative:v,primary:y,draft:w,actions:j,controls:S,selection:k,select:E,snap:N,setSnap:C,readOnly:R,loadingVideo:P}=Xt(),z=w.composition,O=z.fps,T=i.useMemo(()=>[...z.scenes].sort((ue,xe)=>ue.start-xe.start),[z.scenes]),W=i.useMemo(()=>[...z.tracks].reverse(),[z.tracks]),[Z,A]=i.useState(1),[L,_]=i.useState(!1),[X,ae]=i.useState(""),[K,I]=i.useState(null),[H,de]=i.useState(Np),[J,se]=i.useState(0),[U,te]=i.useState(null),G=i.useRef(null),re=i.useRef(null),oe=xu(H,z.duration,Z),Ne=Math.ceil(z.duration*oe),Q=i.useRef({snap:N,ripple:L,pps:oe,comp:z,fps:O,controls:S,actions:j,onRange:o});Q.current={snap:N,ripple:L,pps:oe,comp:z,fps:O,controls:S,actions:j,onRange:o},i.useLayoutEffect(()=>{const ue=G.current;if(!ue)return;const xe=()=>{const _e=ue.clientWidth-Fr;de(_e>0?_e:Np)};if(xe(),typeof ResizeObserver>"u")return;const Be=new ResizeObserver(xe);return Be.observe(ue),()=>Be.disconnect()},[]);const Re=i.useRef(null),Ue=i.useRef(Z),is=i.useRef({viewport:H,duration:z.duration});is.current={viewport:H,duration:z.duration};const Qe=i.useCallback((ue,xe)=>{const Be=G.current;if(tl(ue)===Ue.current)return;const _e=HR({zoom:Ue.current,next:ue,scrollLeft:Re.current??Be?.scrollLeft??0,anchorPx:xe,viewportPx:is.current.viewport,duration:is.current.duration});Re.current=_e.scrollLeft,Ue.current=_e.zoom,A(_e.zoom)},[]);i.useLayoutEffect(()=>{Re.current===null||!G.current||(G.current.scrollLeft=Re.current,se(G.current.scrollLeft),Re.current=null)},[Z]);const gs=i.useRef(Qe);gs.current=Qe,i.useEffect(()=>{const ue=G.current;if(!ue)return;const xe=Be=>{if(!(Be.metaKey||Be.ctrlKey))return;Be.preventDefault();const _e=ue.getBoundingClientRect();gs.current(tl(Ue.current*Math.exp(-Be.deltaY*c$)),Be.clientX-_e.left-Fr)};return ue.addEventListener("wheel",xe,{passive:!1}),()=>ue.removeEventListener("wheel",xe)},[]);const{storyboard:As}=ci({slug:b,creative:v,n:w.base.n,format:y,hash:w.base.hash,enabled:!0}),hs=(ue,xe)=>As?.frames.find(Be=>Be.kind==="scene"&&(Be.scene===ue||Be.scene===xe))??null,Oe=ue=>({visual:h.kindVisual,video:h.kindVideo,text:h.kindText,audio:h.kindAudio,subtitles:h.kindSubtitles})[ue],be=ue=>ue.name??h.trackName({kind:Oe(ue.kind),n:z.tracks.filter(xe=>xe.kind===ue.kind).indexOf(ue)+1}),Fe=(ue,xe)=>ue.name??p.scene({n:xe+1});i.useEffect(()=>{if(!X)return;const ue=window.setTimeout(()=>ae(""),d$);return()=>window.clearTimeout(ue)},[X]);const je=i.useCallback(ue=>ae(rl(ue,g)),[g]),he=i.useCallback((ue,xe,Be)=>{const{actions:_e,ripple:ge}=Q.current,qe=_e.apply({kind:"clipTiming",clipId:ue,start:xe.start,duration:xe.duration,ripple:ge},Be?{coalesce:Be,hold:!0}:void 0);return qe.ok?ae(""):je(qe.problem),qe.ok},[je]),Ke=ue=>si("editor.locked",{clip:ue.id}),we=i.useRef(()=>{});i.useEffect(()=>()=>we.current(),[]);const ze=()=>La(Q.current.controls.clock.get().time,Q.current.fps),We=(ue,xe)=>{const{fps:Be,controls:_e}=Q.current,ge=xe===null?null:La(xe,Be),qe=Ye=>Ye>=ue.start-1e-6&&Ye<ue.start+ue.duration-1e-6;if(ge!==null){_e.seek(qe(ge)?ge:ue.start);return}qe(_e.clock.get().time)||_e.seek(ue.start)},Rs=(ue,xe,Be,_e)=>{if(_e.button!==0)return;E(ue.id);const ge=fe(_e.clientX);if(R){We(ue,ge);return}if(ue.locked||ur(xe)){je(Ke(ue)),We(ue,ge);return}if(Q.current.comp.duration===0)return;we.current(),Q.current.actions.endRun();const qe={start:ue.start,duration:ue.duration},Ye=_e.clientX,Ls=Q.current.pps;let et={x:Ye,alt:_e.altKey},bs=!1,Us=0;const Me=()=>{Us=0;const{ripple:ys,snap:ns,comp:Ys,fps:mt}=Q.current,Ns=Ls,ct=pp(Ys,ue,ys),ls=[...new Set([...ay(Ys,ue.id),ze()])].sort((as,ds)=>as-ds),Is=(et.x-Ye)/Ns,Hs=ns&&!et.alt;let ee;if(Be==="move"){const as=yd([qe.start+Is,qe.start+Is+qe.duration],ls,Ns,Hs);ee=xp(qe,qe.start+Is+as.delta,ct),I(as.snappedTo)}else if(Be==="start"){const as=yd([qe.start+Is],ls,Ns,Hs);ee=wd(qe,"start",qe.start+Is+as.delta,ct,mt),I(as.snappedTo)}else{const as=qe.start+qe.duration,ds=yd([as+Is],ls,Ns,Hs);ee=wd(qe,"end",as+Is+ds.delta,ct,mt),I(ds.snappedTo)}he(ue.id,GR(ee,mt),`drag:${ue.id}`)},ss=ys=>{et={x:ys.clientX,alt:ys.altKey},!(!bs&&Math.abs(ys.clientX-Ye)<VR)&&(bs=!0,Us||(Us=requestAnimationFrame(Me)))},Ie=ys=>{ys.type==="pointerup"&&(et={x:ys.clientX,alt:ys.altKey}),Us&&cancelAnimationFrame(Us),Us=0,bs&&(Me(),Q.current.actions.endRun()),we.current(),!bs&&ys.type==="pointerup"&&We(ue,ge)};we.current=()=>{window.removeEventListener("pointermove",ss),window.removeEventListener("pointerup",Ie),window.removeEventListener("pointercancel",Ie),Us&&cancelAnimationFrame(Us),I(null),we.current=()=>{}},window.addEventListener("pointermove",ss),window.addEventListener("pointerup",Ie),window.addEventListener("pointercancel",Ie)},us=(ue,xe)=>Be=>{if(Be.metaKey||Be.ctrlKey||Be.altKey||Be.nativeEvent.isComposing)return;const _e=Be.key==="ArrowLeft"||Be.key==="ArrowRight";if(Be.key==="Enter"||Be.key===" "){Be.preventDefault(),E(ue.id),We(ue,null);return}if(!_e&&Be.key!=="["&&Be.key!=="]")return;if(Be.preventDefault(),E(ue.id),ue.locked||ur(xe)){je(Ke(ue));return}const ge=Q.current.comp,qe=pp(ge,ue,Q.current.ripple),Ye={start:ue.start,duration:ue.duration};if(_e){const bs=Be.shiftKey?1:1/O,Us=La(ue.start+(Be.key==="ArrowRight"?bs:-bs),O);he(ue.id,xp(Ye,Us,qe));return}const Ls=ze(),et=Be.key==="["?"start":"end";he(ue.id,wd(Ye,et,Ls,qe,O))},fs=i.useRef({last:0,sent:null,raf:0,resume:!1,resend:0,seq:0}),fe=ue=>{const xe=re.current?.getBoundingClientRect(),Be=ue-(xe?.left??0);return Math.min(Q.current.comp.duration,Math.max(0,jd(Be,Q.current.pps)))},Ge=ue=>{we.current();const xe=La(fe(ue.clientX),Q.current.fps);let Be=xe;te({a:xe,b:Be});const _e=qe=>{Be=La(fe(qe.clientX),Q.current.fps),te({a:xe,b:Be})},ge=qe=>{qe.type==="pointerup"&&(Be=La(fe(qe.clientX),Q.current.fps)),we.current(),qe.type==="pointerup"&&Math.abs(Be-xe)>=.1&&Q.current.onRange?.({start:Math.min(xe,Be),end:Math.max(xe,Be)})};we.current=()=>{window.removeEventListener("pointermove",_e),window.removeEventListener("pointerup",ge),window.removeEventListener("pointercancel",ge),te(null),we.current=()=>{}},window.addEventListener("pointermove",_e),window.addEventListener("pointerup",ge),window.addEventListener("pointercancel",ge)},De=ue=>Math.min(Q.current.comp.duration,La(fe(ue),Q.current.fps)),os=ue=>{if(ue.button!==0||!S.ready)return;if(ue.shiftKey&&Q.current.onRange){Ge(ue);return}ue.stopPropagation();try{ue.currentTarget.setPointerCapture?.(ue.pointerId)}catch{}we.current();const xe=fs.current;window.clearTimeout(xe.resend),xe.seq+=1,xe.resume=S.playing,S.playing&&S.pause(),xe.last=De(ue.clientX),xe.sent=xe.last,S.seek(xe.last);const Be=()=>{xe.raf=0,xe.sent!==xe.last&&(xe.sent=xe.last,Q.current.controls.seek(xe.last))},_e=qe=>{xe.last=De(qe.clientX),xe.raf||(xe.raf=requestAnimationFrame(Be))},ge=qe=>{qe.type==="pointerup"&&(xe.last=De(qe.clientX)),xe.raf&&cancelAnimationFrame(xe.raf),xe.raf=0,we.current();const Ye=xe.last;xe.sent=Ye,Q.current.controls.seek(Ye);const Ls=++xe.seq;xe.resend=window.setTimeout(()=>{xe.seq===Ls&&!Q.current.controls.playing&&Q.current.controls.seek(Ye)},o$),xe.resume&&Q.current.controls.toggle()};we.current=()=>{window.removeEventListener("pointermove",_e),window.removeEventListener("pointerup",ge),window.removeEventListener("pointercancel",ge),xe.raf&&cancelAnimationFrame(xe.raf),xe.raf=0,we.current=()=>{}},window.addEventListener("pointermove",_e),window.addEventListener("pointerup",ge),window.addEventListener("pointercancel",ge)};i.useEffect(()=>()=>window.clearTimeout(fs.current.resend),[]);const Ze=ue=>{S.ready&&(ue.key==="Home"&&(ue.preventDefault(),S.seek(0)),ue.key==="End"&&(ue.preventDefault(),S.seek(z.duration)),(ue.key==="PageUp"||ue.key==="PageDown")&&(ue.preventDefault(),S.seek(S.clock.get().time+(ue.key==="PageUp"?1:-1))))},vs=ue=>(xe,Be)=>{const _e=j.apply({kind:"trackFlags",trackId:ue.id,[xe]:Be});_e.ok?ae(""):je(_e.problem)},Le=jd(J,oe),ne=jd(J+H,oe),Ee=i.useCallback(ue=>u.web.canvas.seconds({n:Vs(g,ue)}),[u,g]),Ce=!S.ready,Xe=Fr+Ne;return s.jsxs("div",{className:"ms-tl",children:[s.jsxs("div",{className:"ms-tl-bar",children:[s.jsx("button",{type:"button",className:"ms-fv-play","aria-label":S.playing?f.pause:f.play,"aria-keyshortcuts":"Space",disabled:Ce,title:P?h.loadingVideo:void 0,onClick:S.toggle,children:s.jsx(F,{name:S.playing?"pause":"play",size:13,fill:!S.playing,strokeWidth:S.playing?2:1.4})}),s.jsxs("span",{className:"ms-fv-tc",children:[s.jsx(h$,{clock:S.clock}),s.jsxs("span",{className:"ms-faint",children:[" / ",wt(S.duration)]})]}),s.jsx($,{size:"sm",variant:"outline",icon:!0,"aria-label":f.prevFrame,title:f.prevFrame,"aria-keyshortcuts":"ArrowLeft",disabled:Ce,onClick:()=>S.step(-1),children:s.jsx(F,{name:"back",size:13})}),s.jsx($,{size:"sm",variant:"outline",icon:!0,"aria-label":f.nextFrame,title:f.nextFrame,"aria-keyshortcuts":"ArrowRight",disabled:Ce,onClick:()=>S.step(1),children:s.jsx(F,{name:"forward",size:13})}),s.jsx("span",{className:"ms-fv-sep","aria-hidden":"true"}),s.jsx($,{size:"sm",variant:"outline",icon:!0,className:le("ms-fv-loop",e&&"ms-on"),"aria-label":f.loop,title:f.loop,"aria-pressed":e,onClick:()=>t(!e),children:s.jsx(F,{name:"refresh",size:13})}),s.jsx(At,{className:"ms-fv-speed",variant:"pill",label:f.speed,value:n,onChange:a,options:eb.map(ue=>({value:ue,label:f.speedValue({n:Vs(g,Number(ue))})}))}),s.jsx("span",{className:"ms-fv-sep","aria-hidden":"true"}),s.jsx($,{size:"sm",variant:"outline",icon:!0,className:le("ms-tl-toggle",N&&"ms-on"),"aria-label":h.snap,title:h.snap,"aria-pressed":N,onClick:()=>C(!N),children:s.jsx(F,{name:"magnet",size:13})}),s.jsx($,{size:"sm",variant:"outline",icon:!0,className:le("ms-tl-toggle",L&&"ms-on"),"aria-label":h.tlRipple,title:h.tlRipple,"aria-pressed":L,onClick:()=>_(!L),children:s.jsx(F,{name:"link",size:13})}),c?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-fv-sep","aria-hidden":"true"}),s.jsxs($,{size:"sm",variant:"outline",className:"ms-tl-comment","aria-keyshortcuts":"C",title:m?x.rangeHint:x.clipCommentNeeds,disabled:!m,onClick:c,children:[s.jsx(F,{name:"comment",size:13}),x.clipComment]}),d?s.jsxs($,{size:"sm",variant:"outline",className:"ms-tl-comment","aria-keyshortcuts":"R",disabled:Ce,onClick:d,children:[s.jsx(F,{name:"comment",size:13}),x.rangeComment]}):null]}):null,s.jsx("span",{className:"ms-grow"}),X?s.jsx("span",{className:"ms-tl-notice",role:"alert",children:X}):null,s.jsxs("span",{className:"ms-tl-zoom",children:[s.jsx(F,{name:"search",size:13}),s.jsx(cl,{label:h.tlZoom,min:0,max:100,step:1,value:WR(Z),valueText:h.tlZoomValue({n:Vs(g,Z,{maximumFractionDigits:1})}),onChange:ue=>Qe(KR(ue),H/2)})]})]}),s.jsx("div",{ref:G,className:"ms-tl-scroll","data-zoom":Z,onScroll:ue=>se(ue.currentTarget.scrollLeft),children:s.jsxs("div",{className:"ms-tl-inner",style:{width:Xe},children:[s.jsxs("div",{className:"ms-tl-row ms-tl-rulerrow",children:[s.jsx("div",{className:"ms-tl-corner"}),s.jsxs(p$,{ref:re,clock:S.clock,duration:z.duration,label:h.tlRuler,disabled:Ce,width:Ne,onPointerDown:os,onKeyDown:Ze,children:[s.jsx(m$,{pps:oe,fps:O,t0:Le,t1:ne,seconds:Ee}),Ce?null:s.jsx(g$,{clock:S.clock,pps:oe,label:h.tlPlayhead,onPointerDown:os}),U?s.jsx("span",{className:"ms-tl-picking","aria-hidden":"true",style:{left:zn(Math.min(U.a,U.b),oe),width:zn(Math.abs(U.b-U.a),oe)}}):null,r.filter(ue=>ue.pin.timeSec!==null).map(({pin:ue,number:xe})=>s.jsx("button",{type:"button",className:"ms-tl-mark",style:{left:zn(ue.timeSec,oe)},title:ue.note,disabled:Ce,"aria-label":f.marker({n:xe,time:wt(ue.timeSec)}),onPointerDown:Be=>Be.stopPropagation(),onClick:()=>{S.playing&&S.pause(),S.seek(ue.timeSec)},children:xe},xe))]})]}),s.jsxs("div",{className:"ms-tl-row ms-tl-scenes",role:"group","aria-label":h.scenes,children:[s.jsxs("div",{className:"ms-tl-head",children:[s.jsx(F,{name:"grid",size:13}),s.jsx("span",{className:"ms-tl-name",children:h.scenes})]}),s.jsx("div",{className:"ms-tl-lane",style:{width:Ne},children:T.map((ue,xe)=>{const Be=hs(ue.id,ue.name),_e=Fe(ue,xe);return s.jsxs("button",{type:"button",className:"ms-tl-scene","data-scene":ue.id,disabled:Ce,title:_e,"aria-label":h.tlSceneAt({name:_e,time:wt(ue.start)}),style:{left:zn(ue.start,oe),width:zn(ue.duration,oe)},onClick:()=>S.seek(ue.start),children:[Be?s.jsx("img",{src:Be.url,alt:"",draggable:!1}):null,s.jsx("span",{children:_e})]},ue.id)})})]}),s.jsx("div",{role:"group","aria-label":h.tlTracks,children:W.map(ue=>s.jsxs("div",{className:"ms-tl-row ms-tl-track","data-track":ue.id,children:[s.jsx(i$,{track:ue,name:be(ue),onFlag:vs(ue)}),s.jsx("div",{className:le("ms-tl-lane",ue.hidden&&"ms-dim",ur(ue)&&"ms-locked"),style:{width:Ne},children:ue.clips.map(xe=>{const Be=h[u$[xe.type]],_e=!!(xe.locked||ur(ue)),ge=h.clipBar({name:xe.name??xe.id,kind:Be,start:wt(xe.start),end:wt(xe.start+xe.duration)})+(_e?`, ${h.locked.toLowerCase()}`:"")+(xe.hidden||ue.hidden?`, ${h.clipBarHidden}`:"");return s.jsx(r$,{clip:xe,left:zn(xe.start,oe),width:Math.max(2,zn(xe.duration,oe)),selected:k===xe.id,locked:_e,hidden:!!(xe.hidden||ue.hidden),label:ge,onDrag:(qe,Ye)=>Rs(xe,ue,qe,Ye),onKey:us(xe,ue)},xe.id)})})]},ue.id))}),K!==null?s.jsx("span",{className:"ms-tl-guide",style:{left:Fr+zn(K,oe)},"aria-hidden":"true"}):null,l?s.jsx("div",{className:"ms-tl-overlay",style:{left:Fr},children:l({pps:oe})}):null,s.jsx(x$,{clock:S.clock,pps:oe})]})})]})}const b$=300,j$={colors:0,texts:0,hidden:0},Sp=e=>{const t=e.problems;return{text:pe(e),reasons:Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}},y$=(e,t)=>({colors:Math.max(0,e.colors-t.colors),texts:Math.max(0,e.texts-t.texts),hidden:Math.max(0,e.hidden-t.hidden)});class w${map=new Map;listeners=new Set;subscribe=t=>(this.listeners.add(t),()=>{this.listeners.delete(t)});get=t=>this.map.get(t);set(t,n){if(this.map.get(t)!==n){n?this.map.set(t,n):this.map.delete(t);for(const a of this.listeners)a()}}}const eh=i.createContext(null),k$=e=>e.flatMap(t=>t.clips).filter(t=>t.type==="svg").map(t=>t.id);function N$({children:e}){const{draft:t,selection:n,svgElement:a}=Xt(),[r]=i.useState(()=>new w$),[l,o]=i.useState(()=>new Set),c=i.useCallback((h,f)=>o(x=>{if(x.has(h)===f)return x;const p=new Set(x);return f?p.add(h):p.delete(h),p}),[]);i.useEffect(()=>{n!==null&&a!==null&&c(n,!0)},[n,a,c]);const m=k$(t.composition.tracks).filter(h=>h===n||l.has(h)),u=i.useMemo(()=>({store:r,expanded:l,setExpanded:c}),[r,l,c]);return s.jsxs(eh.Provider,{value:u,children:[m.map(h=>s.jsx(T$,{clipId:h,store:r},h)),e]})}function Fc(e){const t=i.useContext(eh),n=t?t.store.subscribe:S$,a=()=>t&&e!==null?t.store.get(e)??null:null;return i.useSyncExternalStore(n,a,a)}const S$=()=>()=>{};function C$(){return i.useContext(eh)??E$}const E$={expanded:new Set,setExpanded:()=>{}};function T$({clipId:e,store:t}){const{draft:n}=Xt(),a=hi(n.composition.tracks,e);return!a||a.clip.type!=="svg"?null:s.jsx(R$,{clip:a.clip,locked:a.locked,store:t})}function R$({clip:e,locked:t,store:n}){const a=rs(),{slug:r,creative:l,draft:o,actions:c,token:d,stageSvg:m,readOnly:u}=Xt(),h=o.svgTexts.get(e.src),f=t||u!==null,[x,p]=i.useState(null),g=x?.src===e.src?x.failure:null;i.useEffect(()=>{if(h!==void 0||!d||g)return;let K=!0;const I=e.src;return q.getEditorSvg(r,l,d,I).then(H=>{K&&c.svgText(I,H.content)},H=>{K&&p({src:I,failure:Sp(H)})}),()=>{K=!1}},[h,d,e.src,r,l,c,g]);const[b,v]=i.useState(null),y=i.useRef(null),[w,j]=i.useState(null),S=i.useRef(0),k=i.useRef(!1),E=i.useRef(!1),N=i.useRef({clipId:e.id,src:e.src,known:h,stageSvg:m,actions:c,locale:a,key:o.key,gen:o.gen});N.current={clipId:e.id,src:e.src,known:h,stageSvg:m,actions:c,locale:a,key:o.key,gen:o.gen};const C=K=>va(N.current.key)?.gen===K,R=K=>{C(K)&&N.current.actions.svgPending(N.current.clipId,y.current!==null||k.current)},P=K=>{const I=y.current?.gen??K?.gen??N.current.gen;y.current=K,v(K),R(K?.gen??I)},z=async()=>{window.clearTimeout(S.current),S.current=0;const K=y.current;if(!K)return;if(k.current){E.current=!0;return}k.current=!0;const I=N.current;try{const H=await I.stageSvg({kind:"svgEdit",clipId:I.clipId,baseSrc:K.src,content:K.text});if(!C(K.gen)){k.current=!1,y.current=null,E.current=!1;return}I.actions.svgText(H.path,K.text);const de=y.current,J=va(I.key).composition.tracks.flatMap(U=>U.clips).find(U=>U.id===I.clipId);if(!J||!("src"in J)||J.src!==K.src){k.current=!1,P(null);return}const se=I.actions.applyAll([{kind:"clipMedia",clipId:I.clipId,src:H.path},{kind:"svgContent",clipId:I.clipId,...K.counts}]);se.ok||j({text:rl(se.problem,I.locale),reasons:[]}),k.current=!1,de===K||!se.ok||!de?P(null):P({...de,src:H.path,counts:y$(de.counts,K.counts)})}catch(H){if(k.current=!1,!C(K.gen)){y.current=null,E.current=!1;return}j(Sp(H));const de=y.current;de&&de!==K?(P(de),E.current=!0):P(null)}E.current&&(E.current=!1,await z())},O=i.useRef(z);O.current=z,i.useEffect(()=>()=>{S.current&&O.current()},[]),i.useEffect(()=>{const K=y.current;K&&K.src!==e.src&&!k.current&&(window.clearTimeout(S.current),S.current=0,P(null))},[e.src]);const T=(K,I)=>{if(f)return;const H=y.current,de=H?H.text:N.current.known;if(de===void 0)return;const J=_l(de);if(!J.ok)return;try{I(J.doc)}catch{return}const se=iy(J.doc);if(se===de)return;const U={...H?.counts??j$};U[K]+=1,P({src:H?.src??e.src,text:se,counts:U,gen:H?.gen??o.gen}),j(null),window.clearTimeout(S.current),S.current=window.setTimeout(()=>{O.current()},b$)},W=i.useRef(T);W.current=T;const Z=i.useCallback((K,I)=>W.current(K,I),[]),A=b&&b.src===e.src?b.text:h,L=i.useMemo(()=>A!==void 0?_l(A):null,[A]),_=L?.ok?L.doc:null,X=L&&!L.ok?L.reason:null,ae=i.useMemo(()=>({clipId:e.id,status:g||X?"failed":_?"ready":"loading",failure:g??(X?{text:X,reasons:[]}:null),doc:_,colors:_?ly(_):[],texts:_?ry(_):[],elements:_?Ru(_):[],editFailure:w,disabled:f,edit:Z}),[e.id,g,X,_,w,f,Z]);return i.useLayoutEffect(()=>{n.set(e.id,ae)},[n,e.id,ae]),i.useLayoutEffect(()=>()=>{n.set(e.id,void 0)},[n,e.id]),null}function M$(e,t=16){const n=new Map,a=r=>{typeof r=="string"&&/^#[0-9a-fA-F]{3,8}$/.test(r)&&!n.has(r.toLowerCase())&&n.set(r.toLowerCase(),r)};a(e.background);for(const r of e.tracks)for(const l of r.clips)if(l.type==="text"&&a(l.props.color),l.type==="shape"&&a(l.props.fill),l.type==="html")for(const o of Object.values(l.params??{}))o.type==="color"&&a(o.value);return[...n.values()].slice(0,t)}function fi(e,t){const n=new Set(t.brandColors.map(a=>a.toLowerCase()));return[{label:e.swatchBrand,colors:t.brandColors},{label:e.swatchComposition,colors:t.compositionColors.filter(a=>!n.has(a.toLowerCase()))}]}function Cp(e){return e===void 0?"unset":e.trim().toLowerCase()==="none"?"none":px(e)?"colour":"other"}function $$({fill:e,stroke:t,groups:n,disabled:a,onChange:r}){const l=V().web.editor,o={fill:Cp(e),stroke:Cp(t)},c={fill:e,stroke:t},[d,m]=i.useState(null),u=d??(o.fill!=="colour"&&o.stroke==="colour"?"stroke":"fill"),h=n.flatMap(p=>p.colors)[0]??"#000000",f={fill:l.svgFill,stroke:l.svgStroke},x=p=>{const g=o[p],b=f[p],v=p==="fill"?g==="unset"?l.svgFillInherited:l.svgNoFill:l.svgNoStroke,y=p==="fill"?g==="none"?l.svgAddFill:l.svgSetColour:l.svgAddStroke;return s.jsxs("div",{className:le("ms-paint-row",u===p&&"ms-on"),"data-paint":p,onFocusCapture:()=>m(p),onPointerDownCapture:()=>m(p),children:[s.jsx("span",{className:"ms-insp-cap ms-paint-cap","aria-hidden":"true",children:b}),g==="colour"?s.jsxs(s.Fragment,{children:[s.jsx(ni,{className:"ms-paint-field",label:b,value:c[p],disabled:a,onChange:w=>r(p,w)}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":p==="fill"?l.svgRemoveFill:l.svgRemoveStroke,title:p==="fill"?l.svgRemoveFill:l.svgRemoveStroke,disabled:a,onClick:()=>r(p,"none"),children:s.jsx(F,{name:"close",size:13})})]}):s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"ms-paint-none",role:"status","aria-label":`${b}: ${g==="other"?l.svgPaintOther:v}`,children:[s.jsx("span",{className:le("ms-paint-chip",g==="other"?"ms-other":"ms-empty"),"aria-hidden":"true"}),g==="other"?l.svgPaintOther:v]}),s.jsxs($,{size:"sm",variant:"outline",disabled:a,onClick:()=>{m(p),r(p,h)},children:[s.jsx(F,{name:"plus",size:12}),g==="other"?l.svgSetColour:y]})]})]},p)};return s.jsxs("div",{className:"ms-paint",role:"group","aria-label":l.svgPaint,children:[x("fill"),x("stroke"),n.some(p=>p.colors.length>0)?s.jsxs("div",{className:"ms-paint-swatches",children:[s.jsx("span",{className:"ms-paint-for",children:l.svgPaletteFor({field:f[u]})}),s.jsx(Gx,{groups:n,value:o[u]==="colour"?c[u]:void 0,disabled:a,onPick:p=>{c[u]?.toLowerCase()!==p.toLowerCase()&&r(u,p)}})]}):null]})}function Nt({ctl:e,field:t,fields:n=[t],children:a,className:r,extra:l=[]}){const o=[...e.problems(t,n),...l];return s.jsxs("div",{className:le("ms-insp-row",r),children:[a,o.length>0?s.jsx("p",{id:e.errId(t),className:"ms-insp-err",role:"alert",children:o.join(" · ")}):null]})}function $a({title:e,children:t,name:n}){return s.jsxs("section",{className:"ms-insp-sec","aria-label":e,"data-section":n,children:[s.jsx("h4",{children:e}),t]})}const Pc=(e,t)=>e.named?e.label:t.svgElementName({tag:e.tag,n:e.index});function wu({title:e,failure:t}){return s.jsxs("div",{className:"ms-insp-warn ms-svg-problem",role:"alert",children:[s.jsx("p",{children:`${e}: ${t.text}`}),t.reasons.length>0?s.jsx("ul",{className:"ms-svg-reasons",children:t.reasons.map(n=>s.jsx("li",{children:n},n))}):null]})}function Ib({label:e,value:t,disabled:n,onCommit:a}){const[r,l]=i.useState(null),o=()=>{r!==null&&r!==t&&a(r),l(null)},c=m=>{m.key==="Enter"&&!m.shiftKey?(m.preventDefault(),o()):m.key==="Escape"&&r!==null&&(m.preventDefault(),m.stopPropagation(),l(null))},d=r??t;return s.jsx("label",{className:le("ms-field","ms-svg-text",n&&"ms-off"),children:s.jsx("textarea",{"aria-label":e,rows:Math.min(4,d.split(`
|
|
24
|
+
`).length),spellCheck:!1,disabled:n,value:d,onChange:m=>l(m.target.value),onKeyDown:c,onBlur:o})})}function F$({ctl:e}){const n=V().web.editor,{draft:a,readOnly:r,selectSvgElement:l}=Xt(),o=e.clip,c=a.composition,d=Fc(o.id),[m,u]=i.useState(null),[h,f]=i.useState(0),x=fi(n,e),p=c.duration===0&&c.tracks.some(y=>y.clips.some(w=>w.type==="svg"&&(w.id==="small"||w.id==="dark")&&w.id!==o.id)),g=c.duration>0,b=d?.doc??null;i.useEffect(()=>{b&&m!==null&&!d.colors.some(y=>y.hex===m)&&u(null)},[b]);let v;if(!d||d.status==="loading")v=s.jsx("p",{className:"ms-insp-note",role:"status",children:n.svgLoading});else if(d.status==="failed")v=s.jsx(wu,{title:n.svgCannot,failure:d.failure});else{const{colors:y,texts:w,elements:j,disabled:S,edit:k}=d,E=(N,C)=>{k("colors",R=>{cy(R,N,C)}),u(px(C)??null)};v=s.jsxs(s.Fragment,{children:[d.editFailure?s.jsx(wu,{title:n.svgRefused,failure:d.editFailure}):null,s.jsxs("div",{className:"ms-svg-part",children:[s.jsx("span",{className:"ms-insp-cap",children:n.svgColors}),y.length===0?s.jsx("p",{className:"ms-insp-note",children:n.svgNoColors}):s.jsx("ul",{className:"ms-svg-colors","aria-label":n.svgColors,children:y.map(N=>s.jsx("li",{children:s.jsxs("button",{type:"button",className:le("ms-svg-color",m===N.hex&&"ms-on"),"aria-pressed":m===N.hex,disabled:S,"aria-label":n.svgColorCount({hex:N.hex,n:N.count}),title:n.svgColorCount({hex:N.hex,n:N.count}),onClick:()=>{f(C=>C+1),u(C=>C===N.hex?null:N.hex)},children:[s.jsx("span",{className:"ms-svg-swatch","aria-hidden":"true",style:{background:N.hex}}),s.jsx("span",{className:"ms-svg-hex",children:N.hex}),s.jsx("span",{className:"ms-svg-count","aria-hidden":"true",children:`×${N.count}`})]})},N.hex))}),m!==null?s.jsx(ni,{label:n.svgColorNew({hex:m}),value:m,disabled:S,groups:x,onChange:N=>E(m,N)},h):null]}),s.jsxs("div",{className:"ms-svg-part",children:[s.jsx("span",{className:"ms-insp-cap",children:n.svgTexts}),w.length===0?s.jsx("p",{className:"ms-insp-note",children:n.svgNoTexts}):s.jsxs(s.Fragment,{children:[w.map((N,C)=>s.jsx(Ib,{label:n.svgText({n:C+1}),value:N.text,disabled:S,onCommit:R=>k("texts",P=>gx(P,N.path,R))},N.path)),s.jsx("p",{className:"ms-insp-note",children:n.svgTextFonts})]})]}),g?s.jsxs("div",{className:"ms-svg-part",children:[s.jsx("span",{className:"ms-insp-cap",children:n.svgElements}),j.length===0?s.jsx("p",{className:"ms-insp-note",children:n.svgNoElements}):s.jsx("ul",{className:"ms-svg-elements","aria-label":n.svgElementList,children:j.map(N=>{const C=Pc(N,n);return s.jsxs("li",{className:le("ms-svg-el",N.hidden&&"ms-dim"),style:{paddingInlineStart:N.depth*12},children:[s.jsx("button",{type:"button",className:"ms-svg-el-name",title:C,onClick:()=>l(N.path,o.id),children:C}),s.jsx(F,{name:"forward",size:12,className:"ms-svg-el-go"})]},N.path)})})]}):null]})}return s.jsxs($a,{title:n.secSvg,name:"svg",children:[p?s.jsx("p",{className:"ms-insp-note",children:n.svgOtherVersions}):null,r!==null?s.jsx("p",{className:"ms-insp-note",role:"status",children:r}):null,v]})}function P$({ctl:e,element:t}){const a=V().web.editor,{readOnly:r,askElement:l}=Xt(),o=e.clip,c=Fc(o.id),{texts:d,disabled:m,edit:u}=c,h=Pc(t,a),f=t.tag==="text"?d.find(p=>p.path===t.path)??null:null,x=fi(a,e);return s.jsxs($a,{title:a.secSvgElement,name:"svg-element",children:[r!==null?s.jsx("p",{className:"ms-insp-note",role:"status",children:r}):null,c.editFailure?s.jsx(wu,{title:a.svgRefused,failure:c.editFailure}):null,s.jsxs("div",{className:"ms-insp-lab ms-svg-visible",children:[s.jsx("span",{className:"ms-insp-cap","aria-hidden":"true",children:a.svgVisible}),s.jsx(Un,{size:"sm",label:a.svgVisible,on:!t.hidden,disabled:m,onChange:p=>u("hidden",g=>xx(g,t.path,!p))})]}),f?s.jsx(Ib,{label:a.svgText({n:d.indexOf(f)+1}),value:f.text,disabled:m,onCommit:p=>u("texts",g=>gx(g,f.path,p))}):null,s.jsx($$,{fill:t.fill,stroke:t.stroke,groups:x,disabled:m,onChange:(p,g)=>u("colors",b=>oy(b,t.path,{[p]:g}))}),s.jsxs("div",{className:"ms-svg-ask",children:[d.length===0&&t.tag!=="text"?s.jsx("p",{className:"ms-insp-note",role:"note",children:a.svgOutlined}):null,l?s.jsxs($,{size:"sm",variant:"outline",className:"ms-insp-ask",title:a.svgAskElementTip({name:h}),disabled:r!==null,onClick:()=>l(o.id,{path:t.path,name:h}),children:[s.jsx(F,{name:"comment",size:13}),a.svgAskElement]}):null]})]})}const Sd={text:"text",shape:"grid",image:"image",svg:"image",video:"video",html:"code",audio:"music",subtitles:"text"};function Ol(e,t,n){return e.name?e.name:t.duration===0&&e.type==="svg"&&e.id==="small"?n.layerSmall:t.duration===0&&e.type==="svg"&&e.id==="dark"?n.layerDark:e.id}function Cd({name:e,kind:t,icon:n,hidden:a,locked:r,lockFixed:l,selected:o,nested:c,onSelect:d,onFlag:m,twisty:u}){const h=V().web.editor,f=a?h.showTrack({name:e}):h.hideTrack({name:e}),x=r?h.unlockTrack({name:e}):h.lockTrack({name:e}),p=s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-layer-name",title:e,children:e}),s.jsx("span",{className:"ms-layer-kind",children:t})]});return s.jsxs("div",{className:le("ms-layer",c&&"ms-nested",a&&"ms-dim",o&&"ms-sel"),"data-layer-name":e,"aria-current":o?"true":void 0,children:[u?s.jsx("button",{type:"button",className:le("ms-layer-twisty",u.open&&"ms-open"),"aria-expanded":u.open,"aria-label":u.open?h.layerCollapse({name:e}):h.layerExpand({name:e}),title:u.open?h.layerCollapse({name:e}):h.layerExpand({name:e}),onClick:u.onToggle,children:s.jsx(F,{name:"chevron",size:12})}):s.jsx("span",{className:"ms-layer-twisty","aria-hidden":"true"}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":f,title:f,onClick:()=>m("hidden",!a),children:s.jsx(F,{name:a?"eyeOff":"eye",size:14})}),s.jsx("span",{className:"ms-layer-thumb","aria-hidden":"true",children:s.jsx(F,{name:n,size:15})}),d?s.jsx("button",{type:"button",className:"ms-layer-main",onClick:d,children:p}):s.jsx("span",{className:"ms-layer-main ms-static",children:p}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":x,title:x,disabled:l,onClick:()=>m("locked",!r),children:s.jsx(F,{name:r?"lock":"unlock",size:14})})]})}const A$={g:"grid",text:"text",image:"image",use:"link"};function L$({clip:e,layerName:t,nested:n}){const a=V().web.editor,{selection:r,svgElement:l,selectSvgElement:o}=Xt(),c=Fc(e.id);if(!c||c.status==="loading")return s.jsx("p",{className:le("ms-layer-el-note",n&&"ms-nested"),role:"status",children:a.svgLoading});if(c.status==="failed")return s.jsx("p",{className:le("ms-layer-el-note",n&&"ms-nested"),role:"status",children:a.svgCannot});if(c.elements.length===0)return s.jsx("p",{className:le("ms-layer-el-note",n&&"ms-nested"),children:a.svgNoElements});const d=m=>{const u=Pc(m,a),h=m.hidden?a.svgShow({name:u}):a.svgHide({name:u}),f=r===e.id&&l===m.path;return s.jsx("li",{children:s.jsxs("div",{className:le("ms-layer","ms-layer-el",m.hidden&&"ms-dim",f&&"ms-sel"),"data-svg-element":m.path,style:{paddingInlineStart:(n?40:24)+m.depth*12},"aria-current":f?"true":void 0,children:[s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":h,title:h,disabled:c.disabled,onClick:()=>c.edit("hidden",x=>xx(x,m.path,!m.hidden)),children:s.jsx(F,{name:m.hidden?"eyeOff":"eye",size:13})}),s.jsx("span",{className:"ms-layer-thumb","aria-hidden":"true",children:s.jsx(F,{name:A$[m.tag]??"edit",size:13})}),s.jsx("button",{type:"button",className:"ms-layer-main",onClick:()=>o(m.path,e.id),children:s.jsx("span",{className:"ms-layer-name",title:u,children:u})})]})},m.path)};return s.jsx("ol",{className:"ms-layers-sub ms-layers-svg","aria-label":a.layerElements({name:t}),children:c.elements.map(d)})}function I$(){const t=V().web.editor,n=rs(),{draft:a,actions:r,selection:l,select:o,svgElement:c}=Xt(),d=C$(),[m,u]=i.useState(""),h=a.composition.tracks,f=[...h].reverse().filter(k=>k.clips.length>0),x={text:t.clipText,shape:t.clipShape,image:t.clipImage,svg:t.clipSvg,video:t.clipVideo,html:t.clipHtml,audio:t.clipAudio,subtitles:t.clipSubtitles},p={visual:t.kindVisual,video:t.kindVideo,text:t.kindText,audio:t.kindAudio,subtitles:t.kindSubtitles},g=k=>{const E=r.apply(k);u(E.ok?"":rl(E.problem,n))},b=(k,E,N)=>g({kind:"trackFlags",trackId:k.id,[E]:N}),v=(k,E,N)=>g({kind:"clipFlags",clipId:k.id,[E]:N}),y=(k,E,N,C)=>{if(C){b(k,N,!0);return}k[N]&&b(k,N,!1),E[N]&&v(E,N,!1)},w=k=>k.type==="svg"?{open:d.expanded.has(k.id),onToggle:()=>d.setExpanded(k.id,!d.expanded.has(k.id))}:void 0,j=(k,E)=>k.type==="svg"&&d.expanded.has(k.id)?s.jsx(L$,{clip:k,layerName:Ol(k,a.composition,t),nested:E}):null,S=k=>l===k.id&&!(k.type==="svg"&&c!==null);return s.jsxs("div",{className:"ms-layers","data-slot":"layers",children:[m?s.jsx("p",{className:"ms-layers-notice",role:"alert",children:m}):null,f.length===0?s.jsx("p",{className:"ms-layers-empty",children:t.layersEmpty}):s.jsx("ol",{className:"ms-layers-list","aria-label":t.layersList,children:f.map(k=>{const E=k.name??t.trackName({kind:p[k.kind],n:h.filter(N=>N.kind===k.kind).indexOf(k)+1});if(k.clips.length===1){const N=k.clips[0];return s.jsxs("li",{children:[s.jsx(Cd,{lockFixed:k.kind==="subtitles",name:Ol(N,a.composition,t),kind:x[N.type],icon:Sd[N.type],selected:S(N),hidden:!!(k.hidden||N.hidden),locked:!!(ur(k)||N.locked),twisty:w(N),onSelect:()=>o(N.id),onFlag:(C,R)=>y(k,N,C,R)}),j(N,!1)]},k.id)}return s.jsxs("li",{children:[s.jsx(Cd,{lockFixed:k.kind==="subtitles",name:E,kind:p[k.kind],icon:Sd[k.clips[0].type],hidden:!!k.hidden,locked:ur(k),onSelect:null,onFlag:(N,C)=>b(k,N,C)}),s.jsx("ol",{className:"ms-layers-sub",children:[...k.clips].reverse().map(N=>s.jsxs("li",{children:[s.jsx(Cd,{nested:!0,lockFixed:k.kind==="subtitles",name:Ol(N,a.composition,t),kind:x[N.type],icon:Sd[N.type],selected:S(N),hidden:!!N.hidden,locked:!!N.locked,twisty:w(N),onSelect:()=>o(N.id),onFlag:(C,R)=>v(N,C,R)}),j(N,!0)]},N.id))})]},k.id)})}),s.jsx("p",{className:"ms-layers-foot",children:t.layersAsk})]})}const Ed=1e-4,Ep=.4;function z$(e,t){const n=e.animations??[],a=o=>t==="in"?(o.start??0)<=Ed:(o.start??0)>Ed&&Math.abs((o.start??0)+o.duration-e.duration)<=Ed,r=n.filter(a),l=r.find(o=>"preset"in o)??null;return{preset:l,custom:!l&&r.length>0}}function O$({ctl:e}){const t=V().web.editor,{draft:n,askAnimation:a}=Xt(),r=e.clip,l={fadeIn:t.presetFadeIn,fadeOut:t.presetFadeOut,slideUp:t.presetSlideUp,slideDown:t.presetSlideDown,slideLeft:t.presetSlideLeft,slideRight:t.presetSlideRight,popIn:t.presetPopIn,scaleIn:t.presetScaleIn,wipe:t.presetWipe},o=[{value:"none",label:t.animNone},...dy.map(m=>({value:m,label:l[m]}))],c=[{slot:"in",label:t.animIn},{slot:"out",label:t.animOut}],d=(m,u,h,f)=>e.run(`anim-${m}`,{kind:"animationPreset",clipId:r.id,slot:m,preset:u,duration:h},f);return s.jsx($a,{title:t.secAnimation,name:"animation",children:c.map(({slot:m,label:u})=>{const{preset:h,custom:f}=z$(r,m),x=`anim-${m}`;return f?s.jsx(Nt,{ctl:e,field:x,children:s.jsxs("div",{className:"ms-insp-slot",children:[s.jsx("b",{children:u}),s.jsx("p",{className:"ms-insp-note",children:t.animCustom}),a?s.jsxs($,{size:"sm",variant:"outline",className:"ms-insp-ask",title:t.animAskTip({slot:u.toLowerCase(),name:Ol(r,n.composition,t)}),onClick:()=>a(r.id,m),children:[s.jsx(F,{name:"comment",size:13}),t.animAsk]}):null]})},m):s.jsx(Nt,{ctl:e,field:x,children:s.jsxs("div",{className:"ms-insp-slot",children:[s.jsx("b",{className:"ms-insp-slot-name",children:u}),s.jsx(At,{label:`${t.secAnimation} · ${u}`,value:h?.preset??"none",options:o,disabled:e.locked,onChange:p=>{d(m,p==="none"?null:p,h?.duration??Math.min(Ep,r.duration)),e.end()}}),s.jsx(Tt,{label:`${t.animDuration} · ${u}`,prefix:"s",value:h?.duration??null,startAt:Ep,min:.05,max:r.duration,step:.05,decimals:2,disabled:e.locked||!h,onChange:p=>{h&&d(m,h.preset,p,`insp:${r.id}:${x}`)},onEnd:e.end})]})},m)})})}const Tp=e=>e.split("/").pop()??e;function D$({open:e,onClose:t,kinds:n,onPick:a}){const l=V().web.editor,{slug:o,staging:c}=Xt(),[d,m]=i.useState(null),[u,h]=i.useState(null),[f,x]=i.useState(!1),[p,g]=i.useState(null),b=i.useRef(null),v=i.useCallback(N=>N.filter(C=>n.includes(C.kind)),[n]);i.useEffect(()=>{if(!e)return;let N=!0;return h(null),m(null),Promise.resolve().then(()=>q.listAssets(o)).then(C=>{N&&m(C.assets)}).catch(C=>{N&&h(l.pickerLoadFailed({detail:pe(C)}))}),()=>{N=!1}},[e,o]);const y=async N=>{g(N.file);try{await a(N)}finally{g(null)}},w=async N=>{if(N.length!==0){x(!0),h(null);try{let R=(await q.uploadFiles(o,"assets",N)).assets??[];if(R.length===0){const z=await q.listAssets(o);R=z.unregistered.length>0?(await q.registerAssets(o,z.unregistered)).assets:[]}m(z=>[...(z??[]).filter(O=>!R.some(T=>T.file===O.file)),...R]);const P=v(R)[0];P?await y(P):R.length>0&&h(l.pickerWrongKind({kind:j}))}catch(C){h(l.pickerUploadFailed({detail:pe(C)}))}finally{x(!1)}}},j=n.map(N=>N==="image"?l.kindImageFile:N==="svg"?l.kindSvgFile:N==="video"?l.kindVideoFile:N==="audio"?l.kindAudioFile:N).join(" / "),S=j,k=d?v(d):[],E=f||p!==null||c;return s.jsx(rt,{open:e,onClose:t,label:l.pickerFor({kind:S}),width:520,dismissible:!E,children:s.jsxs("div",{className:"ms-picker",children:[s.jsxs("header",{className:"ms-picker-head",children:[s.jsx("h2",{children:l.pickerFor({kind:S})}),s.jsxs($,{size:"sm",variant:"outline",disabled:E,onClick:()=>b.current?.click(),children:[s.jsx(F,{name:"upload",size:13}),f?l.pickerUploading:l.pickerUpload]}),s.jsx("input",{ref:b,type:"file",hidden:!0,"aria-label":l.pickerUploadInput,onChange:N=>{w(Array.from(N.target.files??[])),N.target.value=""}})]}),u?s.jsx("p",{className:"ms-insp-err",role:"alert",children:u}):null,d===null&&!u?s.jsx("div",{className:"ms-picker-state",children:s.jsx(Ts,{size:16,label:l.pickerLoading})}):null,d!==null&&k.length===0?s.jsx("p",{className:"ms-picker-empty",children:l.pickerEmpty({kind:S})}):null,k.length>0?s.jsx("ul",{className:"ms-picker-list","aria-label":l.pickerList,children:k.map(N=>s.jsx("li",{children:s.jsxs("button",{type:"button",className:le("ms-picker-item",p===N.file&&"ms-on"),disabled:E,onClick:()=>{y(N)},children:[s.jsx("span",{className:"ms-picker-name",children:Tp(N.file)}),N.description?s.jsx("span",{className:"ms-picker-desc",children:N.description}):null,p===N.file?s.jsxs("span",{className:"ms-picker-busy",role:"status",children:[s.jsx(Ts,{size:13,decorative:!0}),s.jsx("span",{children:l.pickerPreparing({file:Tp(N.file)})}),c?s.jsx("small",{children:l.stagingLong}):null]}):null]})},N.file))}):null,s.jsx("footer",{className:"ms-picker-foot",children:s.jsx($,{size:"sm",variant:"ghost",disabled:E,onClick:t,children:l.pickerClose})})]})})}function sh({kinds:e,current:t,disabled:n,describedBy:a,onStaged:r}){const l=V().web.editor,{stageAsset:o}=Xt(),[c,d]=i.useState(!1),m=async u=>{const h=await o({kind:"library",file:u.file});h&&(r(h),d(!1))};return s.jsxs("div",{className:"ms-insp-file",children:[s.jsx("span",{className:"ms-insp-path",title:t,children:t.split("/").pop()}),s.jsxs($,{size:"sm",variant:"outline",disabled:n,"aria-describedby":a,onClick:()=>d(!0),children:[s.jsx(F,{name:"image",size:13}),l.replace]}),s.jsx(D$,{open:c,onClose:()=>d(!1),kinds:e,onPick:m})]})}function B$({ctl:e}){const t=V().web.editor,n=e.clip,a=n.volume??1,r=(o,c)=>e.run(o,{kind:"clipMedia",clipId:n.id,...c},`insp:${n.id}:${o}`),l=o=>e.problems(o,[o]).length>0;return s.jsxs($a,{title:t.secAudio,name:"audio",children:[s.jsx(Nt,{ctl:e,field:"src",children:s.jsx(sh,{kinds:["audio"],current:n.src,disabled:e.locked,describedBy:e.errId("src"),onStaged:o=>{e.run("src",{kind:"clipMedia",clipId:n.id,src:o.path}),e.end()}})}),s.jsx(Nt,{ctl:e,field:"volume",children:s.jsxs("div",{className:"ms-insp-vol",children:[s.jsx(Tt,{label:t.fVolume,prefix:"VOL",value:a,min:0,max:Ja.volume,step:.05,decimals:2,disabled:e.locked,invalid:l("volume"),describedBy:e.errId("volume"),onChange:o=>r("volume",{volume:o}),onEnd:e.end}),s.jsx(cl,{label:t.fVolume,value:a,min:0,max:Ja.volume,step:.05,disabled:e.locked,valueText:`${Math.round(a*100)}%`,className:"ms-insp-slider",onChange:o=>r("volume",{volume:o})})]})}),s.jsxs("div",{className:"ms-insp-grid2",children:[s.jsx(Nt,{ctl:e,field:"fadeIn",children:s.jsx(Tt,{label:t.fFadeIn,prefix:t.tagIn,unit:"s",value:n.fadeIn??0,min:0,max:n.duration,step:.1,decimals:2,disabled:e.locked,invalid:l("fadeIn"),describedBy:e.errId("fadeIn"),onChange:o=>r("fadeIn",{fadeIn:o}),onEnd:e.end})}),s.jsx(Nt,{ctl:e,field:"fadeOut",children:s.jsx(Tt,{label:t.fFadeOut,prefix:t.tagOut,unit:"s",value:n.fadeOut??0,min:0,max:n.duration,step:.1,decimals:2,disabled:e.locked,invalid:l("fadeOut"),describedBy:e.errId("fadeOut"),onChange:o=>r("fadeOut",{fadeOut:o}),onEnd:e.end})})]})]})}const kl=Ja;function U$({ctl:e}){const t=V().web.editor,{draft:n}=Xt(),{clip:a}=e,r=a.props??{},l=n.composition,o=a.type==="text",c=(m,u)=>e.run(m,{kind:"clipProps",clipId:a.id,props:{[m]:u}},`insp:${a.id}:${m}`),d=m=>({disabled:e.locked,invalid:e.problems(m,[m]).length>0,describedBy:e.errId(m),onEnd:e.end});return s.jsxs($a,{title:t.secBox,name:"box",children:[s.jsxs("div",{className:"ms-insp-grid2",children:[s.jsx(Nt,{ctl:e,field:"x",children:s.jsx(Tt,{...d("x"),prefix:t.tagX,label:t.fX,value:r.x??0,min:-1e5,max:kl.coord,step:1,onChange:m=>c("x",m)})}),s.jsx(Nt,{ctl:e,field:"y",children:s.jsx(Tt,{...d("y"),prefix:t.tagY,label:t.fY,value:r.y??0,min:-1e5,max:kl.coord,step:1,onChange:m=>c("y",m)})}),s.jsx(Nt,{ctl:e,field:"width",children:s.jsx(Tt,{...d("width"),prefix:t.tagW,label:t.fW,value:r.width??(o?null:l.width),startAt:l.width,min:0,max:kl.size,step:1,onChange:m=>c("width",m)})}),s.jsx(Nt,{ctl:e,field:"height",children:s.jsx(Tt,{...d("height"),prefix:t.tagH,label:t.fH,value:r.height??(o?null:l.height),startAt:l.height,min:0,max:kl.size,step:1,onChange:m=>c("height",m)})}),s.jsx(Nt,{ctl:e,field:"rotation",children:s.jsx(Tt,{...d("rotation"),prefix:t.tagRot,label:t.fRotation,unit:"°",value:r.rotation??0,min:-3600,max:kl.rotation,step:1,onChange:m=>c("rotation",m)})}),s.jsx(Nt,{ctl:e,field:"opacity",children:s.jsx(Tt,{...d("opacity"),prefix:"%",label:t.fOpacityField,value:r.opacity??1,min:0,max:1,step:.01,decimals:2,onChange:m=>c("opacity",m)})})]}),s.jsx(cl,{label:t.fOpacity,value:r.opacity??1,min:0,max:1,step:.01,valueText:`${Math.round((r.opacity??1)*100)}%`,disabled:e.locked,className:"ms-insp-slider",onChange:m=>{c("opacity",m)}})]})}const _$={image:["image"],svg:["svg"],video:["video"]},Nl=e=>Math.round(e*1e3)/1e3;function q$({ctl:e}){const t=V().web.editor,{draft:n}=Xt(),a=e.clip,r=a.type==="video",l=r?a.trimStart??0:0,o=r?a.volume??1:1,c=(x,p)=>e.run(x,{kind:"clipMedia",clipId:a.id,...p},`insp:${a.id}:${x}`),d=r?n.staged.find(x=>x.path===a.src):void 0,m=l+a.duration,u=d?.durationSec!=null&&d.durationSec+.001<m?d.durationSec:null,h=()=>{if(u!==null){if(u-l<=0){e.refuse("fit",t.fitNoRoom({trim:String(Nl(l)),video:String(Nl(u))}));return}e.run("timing",{kind:"clipTiming",clipId:a.id,start:a.start,duration:Math.max(Nl(u-l),0),ripple:!1}),e.end()}},f=x=>{e.run("src",{kind:"clipMedia",clipId:a.id,src:x.path}),e.end()};return s.jsxs($a,{title:t.secMedia,name:"media",children:[s.jsx(Nt,{ctl:e,field:"src",children:s.jsx(sh,{kinds:_$[a.type],current:a.src,disabled:e.locked,describedBy:e.errId("src"),onStaged:f})}),u!==null?s.jsx(Nt,{ctl:e,field:"fit",fields:[],children:s.jsxs("div",{className:"ms-insp-warn",role:"alert",children:[s.jsx("p",{children:t.shortVideo({video:String(Nl(u)),needed:String(Nl(m))})}),s.jsx($,{size:"sm",variant:"outline",disabled:e.locked,onClick:h,children:t.fitClip})]})}):null,r?s.jsxs(s.Fragment,{children:[s.jsx(Nt,{ctl:e,field:"trimStart",children:s.jsx(Tt,{label:t.fTrimStart,prefix:t.tagIn,unit:"s",value:l,min:0,max:Ja.trimStart,step:.1,decimals:3,disabled:e.locked,invalid:e.problems("trimStart",["trimStart"]).length>0,describedBy:e.errId("trimStart"),onChange:x=>c("trimStart",{trimStart:x}),onEnd:e.end})}),s.jsx(Nt,{ctl:e,field:"volume",children:s.jsxs("div",{className:"ms-insp-vol",children:[s.jsx(Tt,{label:t.fVolume,prefix:"VOL",value:o,min:0,max:Ja.volume,step:.05,decimals:2,disabled:e.locked,invalid:e.problems("volume",["volume"]).length>0,describedBy:e.errId("volume"),onChange:x=>c("volume",{volume:x}),onEnd:e.end}),s.jsx(cl,{label:t.fVolume,value:o,min:0,max:Ja.volume,step:.05,disabled:e.locked,valueText:`${Math.round(o*100)}%`,className:"ms-insp-slider",onChange:x=>c("volume",{volume:x})})]})})]}):null]})}function V$({ctl:e}){const t=V().web.editor,n=e.clip,a=Object.entries(n.params??{});if(a.length===0)return null;const r=(l,o,c)=>e.run(`param:${l}`,{kind:"htmlParam",clipId:n.id,key:l,value:o},c);return s.jsx($a,{title:t.secParams,name:"params",children:a.map(([l,o])=>{const c=`param:${l}`,d=o.label??l,m=e.problems(c,[l]).length>0,u=`insp:${n.id}:${c}`;return s.jsx(Nt,{ctl:e,field:c,fields:[l],children:s.jsxs("div",{className:"ms-insp-param",children:[s.jsx("span",{className:"ms-insp-cap",children:d}),o.type==="text"?s.jsx(ms,{"aria-label":d,value:o.value,maxLength:ic.text,disabled:e.locked,"aria-invalid":m||void 0,"aria-describedby":e.errId(c),onChange:h=>r(l,h.target.value,u),onBlur:e.end}):o.type==="number"?s.jsx(Tt,{label:d,value:o.value,min:-1e9,max:1e9,step:1,disabled:e.locked,invalid:m,describedBy:e.errId(c),onChange:h=>r(l,h,u),onEnd:e.end}):o.type==="color"?s.jsx(ni,{label:d,value:o.value,disabled:e.locked,invalid:m,describedBy:e.errId(c),groups:fi(t,e),onChange:h=>r(l,h,u),onEnd:e.end}):s.jsx(sh,{kinds:["image","svg"],current:o.value,disabled:e.locked,describedBy:e.errId(c),onStaged:h=>{r(l,h.path),e.end()}})]})},l)})})}const K$={"composition.unknownFont":["fontFamily"],"composition.fontMissing":["fontFamily"],"composition.clipOutside":["start","duration"],"composition.clipOutsideScene":["start","duration"],"composition.clipZero":["duration"],"composition.clipStill":["start"],"composition.mediaNotAsset":["src"]};function W$(e,t){for(let n=0;n<e.tracks.length;n++){const a=e.tracks[n].clips.findIndex(r=>r.id===t);if(a>=0)return`tracks[${n}].clips[${a}]`}return null}function H$(e,t,n,a,r){const l=W$(t,n),o=[];for(const c of e){const d=typeof c.params.path=="string"?c.params.path:null;let m=!1;if(d!==null&&l!==null&&d.startsWith(l)&&(d[l.length]==="."||d[l.length]==="[")){const h=d.slice(l.length+1).replace(/\[(\d+)\]/g,".$1").split(".").filter(Boolean),f=h[0]==="props"||h[0]==="params"?h[1]:h[0];m=f!==void 0&&a.includes(f)}else c.params.clip===n&&(m=(K$[c.key]??[]).some(u=>a.includes(u)));if(m){const u=vx(c,r);o.includes(u)||o.push(u)}}return o}function G$({ctl:e}){const t=V().web.editor,n=e.clip,a=(r,l)=>e.run(r,{kind:"clipProps",clipId:n.id,props:l},`insp:${n.id}:${r}`);return s.jsxs($a,{title:t.secShape,name:"shape",children:[s.jsx(Nt,{ctl:e,field:"fill",children:s.jsx(ni,{label:t.fColorHex,value:n.props.fill,disabled:e.locked,invalid:e.problems("fill",["fill"]).length>0,describedBy:e.errId("fill"),groups:fi(t,e),onChange:r=>a("fill",{fill:r}),onEnd:e.end})}),s.jsx(Nt,{ctl:e,field:"radius",children:s.jsx(Tt,{label:t.fRadius,prefix:"R",value:n.props.radius??0,min:0,max:Ja.coord,step:1,disabled:e.locked,invalid:e.problems("radius",["radius"]).length>0,describedBy:e.errId("radius"),onChange:r=>a("radius",{radius:r}),onEnd:e.end})})]})}const X$=[100,200,300,400,500,600,700,800,900];function Z$(e,t){const n=e.fontWeights;if(!n)return[t.length===1?t[0]:400];if(n.min>=n.max)return[n.min];const a=o=>Number.isInteger(o)&&o>=n.min&&o<=n.max,r=[...new Set(t.filter(a))].sort((o,c)=>o-c);if(r.length>0)return r.slice(0,uy);const l=X$.filter(a);return l.length>0?l:[Math.min(n.max,Math.max(n.min,400))]}const Rp=hy,J$=(e,t)=>t.reduce((n,a)=>Math.abs(a-e)<Math.abs(n-e)?a:n,t[0]??400);function Y$({ctl:e,brand:t}){const n=V().web.editor,{draft:a,stageAsset:r}=Xt(),l=e.clip,o=a.composition,[c,d]=i.useState(null),m=l.props,u=m.fontFamily??o.fonts[0]?.family??"",h=(E,N,C)=>e.run(E,{kind:"clipProps",clipId:l.id,props:N},C),f=[...new Map(o.fonts.map(E=>[E.family.toLowerCase(),E.family])).values()];u&&!f.some(E=>E.toLowerCase()===u.toLowerCase())&&f.unshift(u);const x=a.fonts.filter(E=>E.source==="brand"&&!f.some(N=>N.toLowerCase()===E.family.toLowerCase())),p=[...f.map(E=>({value:`c:${E}`,label:E,group:n.fontsComposition})),...x.map(E=>{const N=t.fonts?.find(C=>C.id===E.brandFontId)?.file===null;return{value:`b:${E.brandFontId??E.family}`,label:E.family,group:n.fontsBrand,disabled:N,hint:N?n.fontNoFile:void 0}})],g=`c:${f.find(E=>E.toLowerCase()===u.toLowerCase())??u}`,b=E=>gh(o.fonts,E)??[400],v=b(u),y=Rp(m.fontWeight),w=(E,N)=>{const C=N??b(E),R=Rp(m.fontWeight);h("fontFamily",C.includes(R)?{fontFamily:E}:{fontFamily:E,fontWeight:J$(R,C)}),e.end()},j=async E=>{if(E.startsWith("c:")){w(E.slice(2));return}const N=x.find(C=>`b:${C.brandFontId??C.family}`===E);if(N?.brandFontId){d(N.family);try{const C=await r({kind:"brandFont",id:N.brandFontId});if(!C)return;const R=Z$(C,N.weights),P=R.length===1?{kind:"addFont",font:{family:N.family,src:C.path,weight:R[0]}}:{kind:"addFont",font:{family:N.family,src:C.path},weights:R},z=e.run("fontFamily",P);if(!z.ok&&z.problem.key!=="editor.fontExists")return;w(N.family,z.ok?R:void 0)}finally{d(null)}}},S=e.locked,k=E=>e.problems(E,[E]).length>0;return s.jsxs($a,{title:n.secText,name:"text",children:[s.jsx(Nt,{ctl:e,field:"text",children:s.jsx(nn,{"aria-label":n.fContent,rows:3,maxLength:ic.text,value:m.text,disabled:S,"aria-describedby":e.errId("text"),onChange:E=>h("text",{text:E.target.value},`insp:${l.id}:text`),onBlur:e.end})}),s.jsxs(Nt,{ctl:e,field:"fontFamily",children:[s.jsx(At,{label:n.fFont,value:g,options:p.length>0?p:[{value:g,label:u}],disabled:S||c!==null,onChange:E=>{j(E)}}),c?s.jsx("p",{className:"ms-insp-note",role:"status",children:n.fontAdding({family:c})}):null]}),s.jsxs("div",{className:"ms-insp-grid2",children:[s.jsx(Nt,{ctl:e,field:"fontWeight",extra:gh(o.fonts,u)&&!v.includes(y)?[n.weightNotOffered({weight:String(y)})]:[],children:s.jsx(At,{label:n.fWeight,value:String(y),display:String(y),options:v.map(E=>({value:String(E),label:String(E)})),disabled:S,onChange:E=>{h("fontWeight",{fontWeight:Number(E)}),e.end()}})}),s.jsx(Nt,{ctl:e,field:"fontSize",children:s.jsx(Tt,{label:n.fSize,prefix:"PX",value:m.fontSize??null,startAt:48,min:1,max:Ja.fontSize,step:1,disabled:S,invalid:k("fontSize"),describedBy:e.errId("fontSize"),onChange:E=>h("fontSize",{fontSize:E},`insp:${l.id}:fontSize`),onEnd:e.end})})]}),s.jsx(Nt,{ctl:e,field:"color",children:s.jsx(ni,{label:n.fColorHex,value:m.color,disabled:S,invalid:k("color"),describedBy:e.errId("color"),groups:fi(n,e),onChange:E=>h("color",{color:E},`insp:${l.id}:color`),onEnd:e.end})}),s.jsx(Nt,{ctl:e,field:"align",children:s.jsx(it,{label:n.fAlign,value:m.align??"left",disabled:S,options:my.map(E=>({value:E,label:E==="left"?n.alignLeft:E==="center"?n.alignCenter:n.alignRight})),onChange:E=>{h("align",{align:E}),e.end()}})})]})}function Q$({ctl:e}){const t=V().web.editor,{draft:n}=Xt(),{clip:a}=e,r=n.composition.duration,l=Math.round(1/n.composition.fps*1e4)/1e4,o=`insp:${a.id}:timing`,c=(h,f)=>e.run("timing",{kind:"clipTiming",clipId:a.id,start:h,duration:f,ripple:!1},o),d=Math.round((a.start+a.duration)*1e6)/1e6,m=e.problems("timing",["start","duration"]).length>0,u={step:l,decimals:3,disabled:e.locked,invalid:m,describedBy:e.errId("timing"),onEnd:e.end,unit:"s"};return s.jsx($a,{title:t.secTiming,name:"timing",children:s.jsx(Nt,{ctl:e,field:"timing",fields:["start","duration"],children:s.jsxs("div",{className:"ms-insp-grid3",children:[s.jsx(Tt,{...u,prefix:t.tagIn,label:t.fIn,value:a.start,min:0,max:r,onChange:h=>c(h,a.duration)}),s.jsx(Tt,{...u,prefix:t.tagDur,label:t.fDur,value:a.duration,min:0,max:r,onChange:h=>c(a.start,h)}),s.jsx(Tt,{...u,prefix:t.tagOut,label:t.fOut,value:d,min:0,max:r,onChange:h=>c(a.start,h-a.start)})]})})})}function eF(e){const[t,n]=i.useState({colors:[],fonts:null});return i.useEffect(()=>{let a=!0;return Promise.resolve().then(()=>q.getBrand(e)).then(r=>{a&&n({colors:r.kit.colors.map(l=>l.hex),fonts:r.kit.fonts})}).catch(()=>{}),()=>{a=!1}},[e]),t}function sF({clip:e,locked:t}){const a=V().web.editor,r=rs(),{slug:l,draft:o,actions:c,svgElement:d,selectSvgElement:m}=Xt(),u=eF(l),h=o.composition,[f,x]=i.useState({}),p=i.useCallback((E,N,C)=>{const R=c.apply(N,C!==void 0?{coalesce:C}:void 0);return x(P=>{const z={...P};return R.ok?delete z[E]:z[E]=rl(R.problem,r),z}),R},[c,r]),g=i.useMemo(()=>M$(h),[h]),b=i.useCallback((E,N)=>{const C=[];f[E]&&C.push(f[E]);for(const R of H$(o.problems,h,e.id,N,r))C.includes(R)||C.push(R);return C},[f,o.problems,h,e.id,r]),v={clip:e,locked:t,run:p,end:c.endRun,problems:b,refuse:(E,N)=>x(C=>({...C,[E]:N})),errId:E=>`insp-${e.id}-${E}-err`.replace(/[^A-Za-z0-9_-]/g,"_"),brandColors:u.colors,compositionColors:g,problemsOf:o.problems},y=h.duration>0,w=Fc(e.type==="svg"?e.id:null),j=e.type==="svg"&&d!==null&&w?.status==="ready"?w.elements.find(E=>E.path===d)??null:null,S=Ol(e,h,a);if(j)return s.jsxs("div",{className:"ms-insp","data-clip-type":"svg-element",children:[s.jsxs("header",{className:"ms-insp-head ms-insp-crumbs",children:[s.jsxs("nav",{className:"ms-insp-crumbnav","aria-label":a.svgCrumbs,children:[s.jsx("button",{type:"button",className:"ms-insp-crumb",title:a.svgBackToLayer({name:S}),onClick:()=>m(null),children:S}),s.jsx(F,{name:"forward",size:11,className:"ms-insp-crumb-sep"}),s.jsx("b",{className:"ms-insp-name","aria-current":"location",children:Pc(j,a)})]}),s.jsx("span",{className:"ms-insp-kind",children:a.svgElementKind})]}),t?s.jsxs("p",{className:"ms-insp-locked",role:"status",children:[s.jsx(F,{name:"lock",size:13}),a.inspLocked]}):null,s.jsx(P$,{ctl:v,element:j})]});const k={text:a.clipText,shape:a.clipShape,image:a.clipImage,svg:a.clipSvg,video:a.clipVideo,html:a.clipHtml,audio:a.clipAudio,subtitles:a.clipSubtitles};return s.jsxs("div",{className:"ms-insp","data-clip-type":e.type,children:[s.jsxs("header",{className:"ms-insp-head",children:[s.jsx("b",{className:"ms-insp-name",children:S}),s.jsx("span",{className:"ms-insp-kind",children:k[e.type]})]}),t?s.jsxs("p",{className:"ms-insp-locked",role:"status",children:[s.jsx(F,{name:"lock",size:13}),a.inspLocked]}):null,e.type==="subtitles"?null:s.jsxs(s.Fragment,{children:[y?s.jsx(Q$,{ctl:v}):null,e.type!=="audio"?s.jsx(U$,{ctl:v}):null,e.type==="text"?s.jsx(Y$,{ctl:v,brand:u}):null,e.type==="shape"?s.jsx(G$,{ctl:v}):null,e.type==="image"||e.type==="svg"||e.type==="video"?s.jsx(q$,{ctl:v}):null,e.type==="svg"?s.jsx(F$,{ctl:v}):null,e.type==="audio"?s.jsx(B$,{ctl:v}):null,e.type==="html"?s.jsx(V$,{ctl:v}):null,y&&e.type!=="audio"?s.jsx(O$,{ctl:v}):null]})]})}function tF(){const e=V().web.editor,{draft:t,selection:n,readOnly:a}=Xt(),r=hi(t.composition.tracks,n);return r?s.jsxs("div",{"data-slot":"inspector",className:"ms-insp-wrap",children:[a!==null?s.jsxs("p",{className:"ms-insp-locked ms-insp-ro",role:"status",children:[s.jsx(F,{name:"lock",size:13}),a]}):null,s.jsx("fieldset",{className:"ms-insp-fieldset",disabled:a!==null,children:s.jsx(sF,{clip:r.clip,locked:r.locked},r.clip.id)})]}):s.jsx("div",{className:"ms-insp-empty","data-slot":"inspector",children:s.jsx(Rt,{icon:"cursor",title:e.inspEmptyTitle,sub:e.inspEmptySub})})}const nF=50,aF=400,rF=10;function lF(e,t,n){return n===null?{width:`min(100cqw, calc(100cqh * ${e/t}))`,aspectRatio:`${e} / ${t}`}:{width:`${Math.round(e*n/100)}px`,aspectRatio:`${e} / ${t}`}}function iF({zoom:e,onZoom:t}){const n=V().web.editor,a=rs(),r=l=>n.zoomValue({pct:Vs(a,l)});return s.jsxs("div",{className:"ms-ed-zoom",role:"group","aria-label":n.zoom,children:[s.jsx($,{size:"sm",variant:e===null?"outline":"ghost","aria-pressed":e===null,title:n.zoomFitTitle,onClick:()=>t(null),children:n.zoomFit}),s.jsx(cl,{className:"ms-ed-zoom-slider",label:n.zoom,min:nF,max:aF,step:rF,value:e??100,valueText:e===null?n.zoomFit:r(e),onChange:t}),s.jsx("span",{className:"ms-ed-zoom-value",children:e===null?n.zoomFit:r(e)})]})}const Mp=e=>Pt()?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey;function oF(e,t,n){const a=i.useRef(n);a.current=n;const r=c=>t&&!c.isComposing&&!c.altKey&&!jr(c)&&!pr(c),l=(c,d)=>c.key.toLowerCase()===d;qt(e,c=>r(c)&&Mp(c)&&!c.shiftKey&&l(c,"z"),()=>a.current.undo()),qt(e,c=>r(c)&&(Mp(c)&&c.shiftKey&&l(c,"z")||!Pt()&&c.ctrlKey&&!c.metaKey&&!c.shiftKey&&l(c,"y")),()=>a.current.redo());const o=c=>r(c)&&ui(c)&&!c.shiftKey;qt(e,c=>o(c)&&(c.key===" "||c.code==="Space")&&!za(c,Wo),()=>a.current.toggle()),qt(e,c=>o(c)&&(c.key==="ArrowLeft"||c.key==="ArrowRight")&&!za(c,Wo),c=>a.current.step(c.key==="ArrowRight"?1:-1)),qt(e,c=>o(c)&&(c.key==="Delete"||c.key==="Backspace"),()=>a.current.remove()),qt(e,c=>o(c)&&l(c,"c")&&!za(c)&&!!a.current.commentClip,()=>a.current.commentClip?.()),qt(e,c=>o(c)&&l(c,"r")&&!za(c)&&!!a.current.commentRange,()=>a.current.commentRange?.()),qt(e,c=>o(c)&&l(c,"p")&&!za(c)&&!!a.current.commentSpot,()=>a.current.commentSpot?.()),qt(e,c=>o(c)&&c.key==="Escape",()=>a.current.deselect())}const $p={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]};function cF(e,t,n){const a=i.useRef(n);a.current=n,qt(e,r=>t&&r.altKey&&!r.metaKey&&!r.ctrlKey&&!r.isComposing&&Object.hasOwn($p,r.key)&&!jr(r)&&!pr(r)&&a.current.can(),r=>{const[l,o]=$p[r.key],c=r.shiftKey?10:1;a.current.nudge(l*c,o*c)})}function zb(e,t,n){const[a]=i.useState(Lm),[r,l]=i.useState(!1),[o,c]=i.useState(!1),[d,m]=i.useState(!1),[u,h]=i.useState(0);i.useEffect(()=>{l(!1),c(!1),m(!1),a.set(0,!0)},[t,a]),i.useEffect(()=>{if(!e){c(!1),m(!1),l(!1);return}const b=[],v=(w,j)=>{e.addEventListener(w,j),b.push(()=>e.removeEventListener(w,j))},y=()=>{Number.isFinite(e.duration)&&h(e.duration),c(!0),m(!1)};return v("error",()=>m(!0)),e.error&&m(!0),v("timeupdate",()=>a.set(e.currentTime,!0)),v("loadedmetadata",y),v("durationchange",y),v("play",()=>l(!0)),v("pause",()=>l(!1)),v("ended",()=>l(!1)),Number.isFinite(e.duration)&&(y(),a.set(e.currentTime,!0)),()=>{for(const w of b)w()}},[e,a]),i.useEffect(()=>{if(!r||!e)return;let b=0;const v=()=>{a.set(e.currentTime,!1),b=requestAnimationFrame(v)};return b=requestAnimationFrame(v),()=>cancelAnimationFrame(b)},[r,e,a]);const f=i.useCallback(b=>{if(!e)return;const v=Math.max(0,Number.isFinite(e.duration)?Math.min(e.duration,b):b);e.currentTime=v,a.set(v,!0)},[e,a]),x=i.useCallback(()=>{e?.pause(),l(!1),e&&a.set(e.currentTime,!0)},[e,a]),p=i.useCallback(()=>{if(!(!e||!o)){if(r){x();return}u&&e.currentTime>=u-1/n/2&&f(0),l(!0),e.play().catch(()=>l(!1))}},[e,o,r,x,u,n,f]),g=i.useCallback(b=>{!e||!o||(r&&x(),f(Math.round((e.currentTime+b/n)*n)/n))},[e,o,r,x,f,n]);return{clock:a,playing:r,ready:o,failed:d,duration:u,seek:f,pause:x,toggle:p,step:g}}const dF=fy;function uF(e){const t=JSON.stringify(e.composition);return e.staged.map(n=>n.path).filter(n=>t.includes(JSON.stringify(n).slice(1,-1)))}const Fp={ok:!1,problem:si("editor.readOnly")},mF=400;function hF({slug:e,creative:t,format:n,live:a,exportNamePattern:r,onSettings:l}){const o=V(),c=o.web.editor,d=o.web.canvas,m=o.web.formatView,u=rs(),h=i.useContext(Mn),f=i.useRef(null),x=i.useRef(null),p=ul(e,a),{detail:g,conversation:b,error:v,reload:y}=Mm(e,t,Hm(a.creativeTicks,e,t)),w=Gm(a,e,t,g),j=Zn({name:"format",slug:e,creative:t,format:n}),S=!h||Zn(h.route)===j,[k]=i.useState(()=>zo(`format:${e}/${t}/${n}`)),[E]=i.useState(()=>performance.now()),[N,C]=i.useState([]),[R,P]=i.useState(!1),[z,O]=i.useState(null);i.useEffect(()=>{let ce=!0;return Promise.resolve().then(()=>q.getFormats()).then($e=>{ce&&(C($e.presets),P(!0))}).catch($e=>{ce&&(O(pe($e)),P(!0))}),()=>{ce=!1}},[]);const T=i.useMemo(()=>g?.versions??[],[g]),W=i.useMemo(()=>Ul(g?.subtitles),[g]),Z=T.at(-1)??null,A=i.useMemo(()=>g?Al(g,N):{},[g,N]),L=A[n]?.follows??n,_=i.useMemo(()=>Vo(A,L),[A,L]),X=pt(N,L)??void 0,ae=pt(N,n)??(R?null:pt(Tu,n)),K=g?.creative.brief.formatLabels,I=i.useCallback(ce=>nr({id:ce,preset:pt(N,ce),labels:K},u),[N,u,K]),[H]=i.useState(()=>Gu(`${e}/${t}`)),[de,J]=i.useState(void 0),se=Z&&Bn(Z,L)?ja(T,A[L],Z.n):null,U=ce=>ce===null?null:Bn(T.find($e=>$e.n===ce),L),te=U(se)?.hash??null,G=i.useCallback(ce=>ce===se||te!==null&&U(ce)?.hash===te,[se,te,T,L]),re=de===null?null:de??H[L],oe=mM(e,t,L),[Ne,Q]=jp(oe),Re=Ne!==null&&Wi(Ne),[Ue,is]=i.useState(null),[Qe,gs]=i.useState(0),As=re===null?null:Nc(A[L],re),hs=As!==null&&!G(As)&&!(re===void 0&&Re)&&(re===void 0||re!==null&&!!A[L]?.history.includes(re)),Oe=hs?As:Ue??Ne?.base.n??se,be=hs?`${oe}#v${Oe}`:oe,[Fe,je]=jp(be),he=hs?Fe:Ne,Ke=hs?je:Q,we=Oe!==null?T.find(ce=>ce.n===Oe)??null:null,ze=Bn(we,L),We=Bn(Z,L),Rs=!g||!R,us=!!(g&&(g.creative.brief.formats.includes(n)||T.some(ce=>ce.outputs.some($e=>$e.format===n)||ce.compositions?.some($e=>$e.format===n)))),fs=!Rs&&(!us||Oe===null||we!==null&&ze===null),fe=i.useRef(()=>{}),Ge=g?.variants&&!g.variants.orphan?g.variants.letter.toUpperCase():null,De=Tc(j,S&&!fs,{title:g?.creative.title??null,variant:Ge,open:()=>fe.current()});i.useEffect(()=>hs?()=>{je.discard()}:void 0,[hs,je]);const os=i.useCallback(ce=>J(G(ce)?null:ce),[G]),[Ze,vs]=i.useState(null),[Le,ne]=i.useState(null),Ee=ze!==null;i.useEffect(()=>{if(Oe===null||!Ee||!R)return;let ce=!0;return ne(null),Promise.resolve().then(()=>q.getEditorComposition(e,t,Oe,L)).then($e=>{ce&&(vs($e),Ke.open($e,X))}).catch($e=>{ce&&ne(pe($e))}),()=>{ce=!1}},[e,t,Oe,L,Ee,R,Qe,be]);const Ce=i.useMemo(()=>{if(!g)return;const ce=Object.values(a.jobs).filter($e=>$e.key===g.jobKey);return ce.find($e=>$e.state==="queued"||$e.state==="running")??ce.sort(($e,Je)=>Je.createdAt.localeCompare($e.createdAt))[0]},[a.jobs,g]),Xe=Ce?.state==="queued"||Ce?.state==="running",ue=Ce&&Xe?Ce.state==="queued"?o.web.creatives.queued:Xr(a.events[Ce.id])??o.web.creatives.working:null,xe=g&&g.jobKey.startsWith("creative:")?`render:${g.jobKey.slice(9)}:v`:null,Be=xe!==null&&Object.values(a.jobs).some(ce=>ce.key.startsWith(xe)&&(ce.state==="queued"||ce.state==="running")),_e=he!==null&&Wi(he),ge=!hs&&!!(he&&We&&Z&&he.base.n<Z.n&&he.base.hash!==We.hash),[qe,Ye]=i.useState(!1),[Ls,et]=i.useState(!1),bs=ge||Ls,[Us,Me]=i.useState(!1);i.useEffect(()=>{!ge||!Z||(_e?Ye(!0):is(Z.n))},[ge,_e,Z?.n]);const ss=el({slug:e,creative:t,n:Oe,format:L,enabled:Ee&&Oe!==null}),[Ie,ys]=i.useState(null),[ns,Ys]=i.useState(0),mt=ss.state.kind==="ready"?ss.state.session.token:null,Ns=i.useRef(null);Ns.current=mt;const ct=he?.composition.fps??El,ls=zb(Ie,`${Oe}/${L}`,ct),[Is,Hs]=i.useState("1"),[ee,as]=i.useState(!1);i.useEffect(()=>{Ie&&(Ie.loop=ee,Ie.playbackRate=Number(Is))},[Ie,ee,Is]);const ds=i.useRef(he);ds.current=he;const Ks=i.useMemo(()=>we?ub(T,we,n):null,[T,we,n]),tt=mb({slug:e,creative:t,n:Ee&&Ks?Ks.n:null,format:n,rows:Ks?.rows??[],player:Ie,token:mt,original:()=>ds.current?.composition??null}),js=tt.locale!==null,Ds=i.useRef(0),ht=i.useRef({player:null,composition:null});i.useEffect(()=>{if(!Ie||!he||js||ht.current.player===Ie&&ht.current.composition===he.composition)return;const ce=ht.current.player!==Ie;ht.current={player:Ie,composition:he.composition},!(ce&&he.ops.length===0)&&(Ds.current=Ie.setComposition(he.composition))},[Ie,he?.composition,js]);const[un,Os]=i.useState(null);i.useEffect(()=>{if(!Ie)return;const ce=()=>{const $e=Ie.applied;if(!$e||$e.seq!==Ds.current)return;const Je=$e.errors.find(xs=>xs.code==="compositionInvalid")??$e.errors[0];Os(Je?o.web.render.runtimeError[Je.code]??Je.code:null)};return Ie.addEventListener("compositionapplied",ce),()=>Ie.removeEventListener("compositionapplied",ce)},[Ie,o]);const gt=i.useRef([]);gt.current=he?.staged??[];const mn=i.useCallback(ce=>{if(ss.showing(ce),!ce||!Ie)return;let $e=!1;for(const xs of gt.current)xs.media&&Ie.addSessionMedia(xs.path,xs.media)&&($e=!0);const Je=va(be);$e&&Je&&(Ds.current=Ie.setComposition(Je.composition))},[ss,Ie,be]),[Wt,$n]=i.useState(!1),[gn,zt]=i.useState(null),Mt=i.useCallback(async ce=>{zt(null),$n(!0);try{const Je=await(async()=>{const xs=Ns.current;if(!xs)throw new Error(c.previewBusy);try{return await q.stageEditorAsset(e,t,{token:xs,from:ce})}catch(yt){if(yt instanceof lt&&yt.code==="editor-no-session"&&Ns.current&&Ns.current!==xs)return q.stageEditorAsset(e,t,{token:Ns.current,from:ce});throw yt}})();return Ke.stage(Je,{from:ce,token:Ns.current??void 0}),Je.media&&Ie&&Ie.addSessionMedia(Je.path,Je.media),Je}catch($e){return zt(c.stageFailed({detail:pe($e)})),null}finally{$n(!1)}},[e,t,Ke,Ie,c]),Yn=i.useCallback(async ce=>{const $e=Ns.current;if(!$e)throw new Error(c.previewBusy);let Je;try{Je=await q.stageSvgEdit(e,t,{token:$e,from:ce})}catch(xs){if(!(xs instanceof lt&&xs.code==="editor-no-session"&&Ns.current&&Ns.current!==$e))throw xs;Je=await q.stageSvgEdit(e,t,{token:Ns.current,from:ce})}return Ke.stage(Je,{from:ce,token:Ns.current??void 0}),Je},[e,t,Ke,c]),vt=ss.state.kind==="ready"?ss.state.session:null,St=!!he&&vt!==null&&uu(vt)!==null&&!ls.ready&&!ls.failed,[an,Zt]=i.useState(!1);i.useEffect(()=>{const ce=va(be);if(!vt||!ce||ce.stagedIn===vt.token)return;if(ce.staged.length===0){Ke.stagedIn(vt.token);return}const $e=vt.token,Je=new Map((vt.staged??[]).map(In=>[In.path,In]));for(const In of Je.values())ce.staged.some(Cr=>Cr.path===In.path)&&Ke.stage(In,{token:$e});const xs=ce.staged.filter(In=>!Je.has(In.path));if(xs.length===0){Ke.stagedIn($e);return}let yt=!0;return Zt(!0),(async()=>{let In=null;for(const bi of xs){const Er=bi.from?await q.stageEditorAsset(e,t,{token:$e,from:bi.from}).catch(()=>null):null;if(!yt||Ns.current!==$e)return;Er&&Er.path===bi.path?(Ke.stage(Er,{token:$e}),Er.media&&Ie&&Ie.addSessionMedia(Er.path,Er.media)):In??=bi.path}Ke.stagedIn($e);const Cr=va(be);Ie&&Cr&&(Ds.current=Ie.setComposition(Cr.composition)),In?zt(c.stagedLost({file:In})):Pe.show(c.stagedRestored)})().finally(()=>{yt&&Zt(!1)}),()=>{yt=!1,Zt(!1)}},[vt?.token,be]);const $t=i.useRef(()=>{}),[rn,Jt]=i.useState(!1),[hn,D]=i.useState(null),[Ae,ts]=i.useState(null),ps=i.useRef(0);i.useEffect(()=>()=>window.clearTimeout(ps.current),[]);const Cs=(Z?.n??Oe??0)+1,ks=xn(X??null,L,u,K),Ms=i.useCallback(async()=>{const ce=va(be);if(!ce||rn)return!1;if(ce.svgPending.size>0)return D(c.saveWhileStaging),!1;Jt(!0),D(null);const $e=Je=>({baseVersion:ce.base.n,format:ce.primaryFormat,baseHash:ce.base.hash,composition:ce.composition,staged:uF(ce).slice(0,dF),ops:oM(ce.ops),token:Je});try{const Je=Ns.current;if(!Je)throw new Error(c.previewBusy);let xs;try{xs=await q.saveEdits(e,t,$e(Je))}catch(yt){if(yt instanceof lt&&Ns.current&&Ns.current!==Je&&(yt.status===422||yt.status===404))xs=await q.saveEdits(e,t,$e(Ns.current));else throw yt}return $t.current(ce.base.n,xs.version),Ke.discard(),vs(null),is(xs.version),J(null),Ye(!1),et(!1),y(),ts({name:ks,n:xs.version}),window.clearTimeout(ps.current),ps.current=window.setTimeout(()=>ts(null),cM),!0}catch(Je){return Je instanceof lt&&Je.code==="editor-base-changed"?(Ye(!0),et(!0),D(Je.message),y()):Je instanceof lt&&Je.problems?.length?D(Je.message):D(Je instanceof lt?Je.message:c.saveFailed({detail:pe(Je)})),!1}finally{Jt(!1)}},[be,rn,e,t,Ke,y,ks,c]),Bt=i.useCallback(()=>{const ce=va(be)?.baseComposition;Ke.discard(),Ie&&ce&&(Ds.current=Ie.setComposition(ce)),D(null),Os(null),Ze&&Ke.open(Ze,X);const $e=va(be);Ie&&$e&&(ht.current={player:Ie,composition:$e.composition})},[be,Ke,Ie,Ze,X]),[bt,nt]=i.useState(null);i.useEffect(()=>RM({blocks:ce=>{const $e=va(oe);return $e!==null&&Wi($e)&&Zn(Ix(ce))!==j},ask:ce=>nt({mode:"route",target:ce})}),[oe,j]);const fn=i.useCallback(()=>new Promise(ce=>{const $e=va(oe);if(!$e||!Wi($e)){ce(!0);return}nt({mode:"chat",resolve:ce})}),[oe]),Nn=ce=>{const $e=bt;nt(null),$e&&($e.mode==="chat"?$e.resolve(ce):ce&&Bs($e.target))},Vn=async()=>{Nn(await Ms())},jt=()=>{hs?Q.discard():Bt(),Nn(!0)},ha=()=>Nn(!1),[Ct,vn]=i.useState(null),[ln,Kn]=i.useState("chat"),Qn=i.useCallback(()=>{const ce=f.current?.querySelector("#ms-ed-panel");(ce?[...ce.querySelectorAll("textarea")]:[]).some(Je=>Je===document.activeElement||Je.value.trim()!=="")||Kn("inspector")},[]),Ut=i.useCallback(ce=>{vn(ce),ce!==null&&Qn()},[Qn]),[fa,Sn]=i.useState(!0),[pa,Fn]=i.useState(null);i.useEffect(()=>{vn(null)},[Oe,L]);const[_t,ea]=i.useState(null),Wn=_t!==null&&_t.clip===Ct?_t.path:null,Fa=i.useCallback((ce,$e)=>{const Je=$e??Ct;Je!==null&&(Je!==Ct&&vn(Je),ea(ce===null?null:{clip:Je,path:ce}),Qn())},[Ct,Qn]),dt=he?he.composition.duration>0:X?.kind!=="image",{stored:ya,setStored:Hn,others:Cn,drop:Pn}=Um(e,t,w.pinScope),Lt=g?g.creative.resumeFrom?.version??Z?.n??null:null,Es=Oe!==null&&ja(T,A[L],Lt)===Oe,st=i.useMemo(()=>ya.flatMap((ce,$e)=>ce.version===Lt?[{pin:ce.pin,at:$e}]:[]),[ya,Lt]),sa=i.useMemo(()=>(Es?st.map((ce,$e)=>({pin:ce.pin,number:$e+1})):[]).filter(ce=>ce.pin.format===n||ce.pin.format===L),[Es,st,n,L]);$t.current=(ce,$e)=>Hn(Je=>Je.some(xs=>xs.version===ce||xs.version===Lt)?Je.map(xs=>xs.version===ce||xs.version===Lt?{...xs,version:$e}:xs):Je);const[Yt,An]=i.useState(!1),wa=()=>{Qt&&An(!0)},[ut,Gn]=i.useState(null),Qt=!!(he&&he.composition.duration>0),En=(ce,$e={})=>{if(!Es){Pe.show(o.web.conversation.onlyOnVersion({n:Lt??0}));return}Gn({pin:ce,index:null,...$e.stay?{stay:!0}:{}})},at=()=>{if(Wn===null||!he||!Ct)return null;const ce=Oi(he.composition,Ct),$e=ce&&ce.type==="svg"?he.svgTexts.get(ce.src):void 0,Je=$e!==void 0?_l($e):null,xs=Je?.ok?Ru(Je.doc).find(yt=>yt.path===Wn):void 0;return xs?{path:xs.path,name:wo(xs.named?xs.label:c.svgElementName({tag:xs.tag,n:xs.index}))}:null},Xs=()=>{if(!he)return;const ce=Ct?Oi(he.composition,Ct):null;if(!ce){Pe.show(dt?o.web.conversation.clipCommentNeeds:c.commentLayerNeeds);return}const $e=Ie?.clipBounds&&Ie.clipBounds.clipId===ce.id?Ie.clipBounds:null,Je=Qt?ls.clock.get().time:0,xs=at(),yt={...uo({format:L,comp:he.composition,clip:ce,time:Je,drawn:$e}),...xs?{element:xs}:{}};En(Qt?yt:{...yt,timeSec:null})},xa=ce=>{if(!he)return;const $e=hv({format:L,start:ce.start,end:ce.end,duration:he.composition.duration});$e&&En($e)},[ta,bn]=i.useState(!1);i.useEffect(()=>{Es||bn(!1)},[Es]);const ka=()=>{if(!Es){Pe.show(o.web.conversation.onlyOnVersion({n:Lt??0}));return}ls.playing&&ls.pause(),bn(ce=>!ce)},lr=ce=>{ce.stopPropagation();const $e=xm(ce.currentTarget.getBoundingClientRect(),ce);bn(!1),En({format:n,x:$e.x,y:$e.y,timeSec:dt?Za(ls.clock.get().time):null})},Ot=(ce,$e)=>{const Je=he?Oi(he.composition,ce):null;if(!he||!Je||Lt===null)return;const xs=$e==="in"?Je.start:Math.max(Je.start,Je.start+Je.duration-1/he.composition.fps),yt={...uo({format:L,comp:he.composition,clip:Je,time:xs}),animation:$e};En(Qt?yt:{...yt,timeSec:null},{stay:!0})},na=(ce,$e)=>{const Je=he?Oi(he.composition,ce):null;if(!he||!Je||Lt===null)return;const xs=Ie?.clipBounds&&Ie.clipBounds.clipId===Je.id?Ie.clipBounds:null,yt={...uo({format:L,comp:he.composition,clip:Je,time:Qt?ls.clock.get().time:0,drawn:xs}),element:{path:$e.path,name:wo($e.name)}};En(Qt?yt:{...yt,timeSec:null},{stay:!0})},Na=ce=>{const $e=ut;if(Gn(null),!$e||Lt===null)return;const Je={...$e.pin,...ce?{note:ce}:{}};if(ce||delete Je.note,$e.index===null)Hn(xs=>[...xs,{pin:Je,version:Lt}]),$e.stay?Pe.show(o.web.conversation.commentWaiting):Kn("chat");else{const xs=st[$e.index]?.at;Hn(yt=>yt.map((In,Cr)=>Cr===xs?{...In,pin:Je}:In))}},Ws=i.useCallback(ce=>{const $e=st[ce]?.at;Hn(Je=>Je.filter((xs,yt)=>yt!==$e))},[st,Hn]),Et=i.useCallback(ce=>{const $e=st[ce]?.pin;$e&&Gn({pin:$e,index:ce})},[st]),ie=i.useCallback(({pins:ce})=>{Pn(ce)},[Pn]),ke=ut?ut.pin.clipName??ut.pin.clipId??"":"",cs=ut?ut.pin.clipId&&ut.pin.animation?(ut.pin.animation==="in"?o.web.conversation.noteTitleAnimIn:o.web.conversation.noteTitleAnimOut)({name:ke}):ut.pin.clipId&&ut.pin.element?o.web.conversation.noteTitleElement({name:ke,element:ut.pin.element.name}):ut.pin.clipId&&!ut.pin.range?o.web.conversation.noteTitleClip({name:ke}):ut.pin.range?o.web.conversation.noteTitleRange(br(u,ut.pin.range)):ut.pin.timeSec!==null?m.commentFrame({time:wt(ut.pin.timeSec)}):d.commentOn({label:I(n)}):"",Ps=gm(g?.variants).discarded,ft=Ps?o.web.variantGroup.discardedReadOnly:hs&&Oe!==null&&se!==null?c.olderVersion({n:Oe,latest:se}):Xe||Be?c.busyAgent:null,Tn=i.useMemo(()=>ft===null?Ke:{...Ke,apply:()=>Fp,applyAll:()=>Fp,undo:()=>{},redo:()=>{}},[Ke,ft]);oF(f,!!he&&S&&bt===null,{commentClip:Xs,commentRange:wa,commentSpot:ka,undo:()=>Tn.undo(),redo:()=>Tn.redo(),toggle:ls.toggle,step:ls.step,deselect:()=>{ta?bn(!1):vn(null)},remove:()=>Pe.show(c.keysDeleteClip)}),cF(f,!!he&&S&&bt===null,{can:()=>he?n$(he,Ct):!1,nudge:(ce,$e)=>{const Je=va(be)??he;if(!Je)return;const xs=a$(Je,Tn,Ct,ce,$e);xs.ok||(xs.reason==="locked"?Pe.show(c.locked):xs.reason==="refused"&&Pe.show(rl(xs.result.problem,u)))}});const ir=()=>{ls.pause(),x.current&&Hl(`canvas:${e}/${t}/${n}`,x.current.getBoundingClientRect()),Oe!==null&&Hu(`${e}/${t}`,{[L]:Oe}),Bs(es.creative(e,t))};fe.current=ir;const qa=i.useRef(!1);i.useLayoutEffect(()=>{if(qa.current||!x.current)return;qa.current=!0;const ce=k&&performance.now()-E<=mF?k:null;ce&&Eo(x.current,ce,qs.l)});const aa=i.useRef(!1),B=!!he&&!Le;i.useEffect(()=>{aa.current||!B||!f.current||(aa.current=!0,f.current.querySelectorAll("[data-part]").forEach(ce=>{const $e=ce.dataset.part;Gs(ce,{x:$e==="l"?-16:$e==="r"?16:0,y:$e==="b"?24:0,ms:qs.m})}))},[B]);const[ye,He]=i.useState(null),_s=i.useMemo(()=>Object.values(a.approvals).filter(w.shows),[a.approvals,w]),$s=w.single?w.groupJob:Ce,Ss=i.useMemo(()=>$s?a.events[$s.id]??[]:[],[$s,a.events]),Ft=(g?.creative.brief.formats??[]).filter(ce=>A[ce]&&!A[ce].follows),Sr=i.useMemo(()=>T.length&&Ft.length>1?{primaries:Ft.map(ce=>({id:ce,label:I(ce),followers:Vo(A,ce).map(I)})),followerOf:ce=>A[ce]?.follows??null,fallback:[L],groups:mm(Ft,N,g?.creative.brief??{},u,o.web.formatUi.other)}:void 0,[T.length,Ft.join(","),A,I,L,N,g?.creative.brief,u,o]),Ac=i.useCallback(ce=>{ie(ce),J(void 0),y()},[y,ie]),Lc=i.useCallback(ce=>{const $e=ja(T,A[L],ce);$e!==null&&os($e)},[T,A,L,os]),[pi,ml]=i.useState(null),hl=g?.variants,Va=hl&&!hl.orphan?hl:null,M=_m({slug:e,creative:t,states:A,labelOf:I,resumeFrom:g?.creative.resumeFrom?.version??null,onChanged:y,onError:ml,...Va?{groupPick:(ce,$e)=>q.setVariantPick(e,Va.host,ce,$e===null?null:{slug:t,version:$e})}:{}}),Y=i.useRef(null),me=i.useRef(null),[Se,Te]=i.useState(!1);Wm(!!g&&!fs,Z?.n??null,S&&!fs,Y);const[Ve,zs]=i.useState(null),Zs=()=>{const ce=A[L];if(!ce||Oe===null||ce.history.length<2)return;const $e=ce.history.indexOf(Oe),Je=ce.history[$e-1]??ce.history[$e+1];zs({open:!0,init:Je<Oe?[Je,Oe]:[Oe,Je]})},[on,cn]=i.useState(!1),Sa=async()=>{if(!(!we||on)){cn(!0),ml(null);try{const ce=await q.duplicateFormat(e,t,we.n,{instanceId:n});ls.pause(),y(),Pe.show(o.web.instances.duplicated({label:xn(ae??null,ce.instanceId,u,K)}),{tone:"ok"}),Bs(es.format(e,t,ce.instanceId))}catch(ce){ml(o.web.instances.duplicateFailed({detail:pe(ce)}))}cn(!1)}},jn=we?.outputs.find(ce=>ce.format===L)??null,Ln=ae?.identity??null,yn=Ln&&jn?.identitySet?jn.identitySet:null,or=Ln==="logo"&&yn?yn.files.find(ce=>ce.path==="logo-dark.png")??null:null,[cr,Pa]=i.useState("edit"),[rh,Yb]=i.useState(!1),Ic=he?{slug:e,creative:t,format:n,primary:L,draft:he,actions:Tn,player:Ie,controls:ls,loadingVideo:St,selection:Ct,select:Ut,snap:fa,setSnap:Sn,token:mt,staging:Wt,stageAsset:ft===null?Mt:async()=>null,stageSvg:ft===null?Yn:async()=>{throw new Error(ft)},readOnly:ft,svgElement:Wn,selectSvgElement:Fa,askAnimation:Ot,askElement:na}:null;if(v&&!g)return s.jsx("div",{className:"ms-cv-state",children:s.jsx(Rt,{icon:"warn",title:d.tryAgain,sub:s.jsx("span",{role:"alert",children:d.loadFailed({detail:v})}),action:s.jsxs($,{variant:"ink",onClick:y,children:[s.jsx(F,{name:"refresh",size:13}),d.tryAgain]})})});if(fs){const ce=re!=null?{[L]:re}:{};return s.jsx(rM,{slug:e,creative:t,format:n,live:a,exportNamePattern:r,onSettings:l,origin:k,viewing:ce,onViewing:$e=>{const xs=(typeof $e=="function"?$e(ce):$e)[L];J(xs===void 0?void 0:G(xs)?null:xs)}})}const zc=he?.composition.width??X?.width??1080,Oc=he?.composition.height??X?.height??1920,Ka=I(L),Dc=I(n),lh=g?.creative.brief.durationSec??null,Qb=!!(he&&dt&&lh!==null&&hx(he.composition.duration,lh)),xi=he?dt?c.meta({size:`${zc}×${Oc}`,seconds:Vs(u,he.composition.duration,{maximumFractionDigits:1}),fps:he.composition.fps}):c.metaImage({size:`${zc}×${Oc}`}):"",ih=lF(zc,Oc,dt?null:pa),oh=_.map(I).join(", "),fl=he?hs?c.saveFromLatest:Xe||Be?c.busyAgent:bs?c.baseChangedTitle:Wt||an||he.svgPending.size>0?c.saveWhileStaging:he.problems.length>0?vx(he.problems[0],u):null:null,wn=g?.creative??null,Ca=A[n],gi=Ca?.follows?I(Ca.follows):null,Bc=Ca?.follows?A[Ca.follows]?.star.version??null:null,vi=yn!==null&&cr!=="edit",Wa=jn&&we?Da(e,t,we.n,jn.file):null,ch=or&&yn&&we?Da(e,t,we.n,`${yn.dir}/${or.path}`):null,Uc=Va?.group.picks[L],ej=ae?Dn(ae.channel,u):null,dh=s.jsxs("div",{ref:f,className:le("ms-ed",dt?"ms-ed-video":"ms-ed-image"),"aria-busy":!he||void 0,children:[De?.title?ma.createPortal(s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"ms-crumb ms-last ms-fv-crumb",children:[s.jsx("span",{className:"ms-crumb-sep","aria-hidden":"true",children:"/"}),ae?s.jsx(en,{channel:da(ae.channel)}):null,s.jsx("b",{"aria-current":"page",title:[ej,xi].filter(Boolean).join(" · ")||void 0,children:xn(ae??null,n,u,K)})]}),xi?s.jsx("span",{className:"ms-fv-meta",title:xi,children:xi}):null,Qb&&he&&wn?s.jsx(Sb,{slug:e,creative:t,brief:wn.brief,actual:he.composition.duration,edited:we?.origin==="editor",disabled:Ps?o.web.variantGroup.discardedReadOnly:Xe?c.busyAgent:null,onChanged:y}):null,jn&&!jn.verified?s.jsx(Qs,{tone:"warn",className:"ms-cv-state-pill",children:o.web.formatUi.unverified}):null]}),De.title):null,De?.end?ma.createPortal(s.jsxs(s.Fragment,{children:[Ca&&wn&&Ca.follows&&gi?s.jsxs("span",{className:"ms-fv-badge",children:[s.jsx(Vm,{label:Dc,primary:gi,primaryStar:Bc,follower:n,actions:M,busy:Xe}),s.jsx("span",{className:"ms-fv-follows",children:Bc!==null?o.web.formatVersions.followsStar({primary:gi,n:Bc}):o.web.formatVersions.follows({primary:gi})})]}):Ca&&wn?s.jsx("span",{className:"ms-fv-badge",children:s.jsx(qm,{bar:!0,buttonRef:Y,slug:e,creative:t,label:Dc,versions:T,shown:Oe,resumeFrom:wn.resumeFrom?.version??null,state:Va?{...Ca,star:{...Ca.star,version:Uc?.slug===t?Uc.version:null,manual:Uc?.slug===t,newer:null}}:Ca,labelOf:I,actions:M,busy:Xe,onView:os,onCompare:Zs,subtitleHashes:W})}):null,s.jsx(Bm,{slug:e,creative:t,detail:g,version:we??Z,presets:N,live:a,onChanged:y,readOnly:Ps?o.web.variantGroup.discardedReadOnly:null}),s.jsx(Dm,{jobs:Object.values(a.jobs),jobKey:g?.jobKey??null,scope:ze!==null?{version:we,format:L}:null,disabled:!Z,onClick:()=>{Z&&He({open:!0,snapshot:{versions:T,states:A}})}}),ze!==null&&!Xe||T.length&&wn?s.jsx(Cb,{buttonRef:me,children:ce=>s.jsxs(s.Fragment,{children:[ze!==null&&!Xe?s.jsx(Go,{icon:"copy",close:ce,run:()=>{Sa()},hint:o.web.instances.duplicateHint({label:Dc}),disabled:Ps?o.web.variantGroup.discardedReadOnly:on?o.web.instances.duplicate:null,children:o.web.instances.duplicate}):null,T.length&&wn?s.jsx(Go,{icon:"clock",close:ce,run:()=>Te(!0),children:Ge?o.web.canvas.versions.historyItemVariant({letter:Ge}):o.web.canvas.versions.historyItem}):null]})}):null,T.length&&wn?s.jsx(Km,{slug:e,creative:t,versions:T,resumeFrom:wn.resumeFrom?.version??null,actions:M,open:Se,onClose:()=>Te(!1),anchor:me}):null]}),De.end):null,s.jsxs("aside",{className:"ms-ed-side ms-ed-left","aria-label":dt?c.scenes:c.layers,"data-part":"l",children:[s.jsx("div",{className:"ms-fv-side-head",children:s.jsx("b",{children:dt?c.scenes:c.layers})}),he?dt?s.jsx(PM,{}):s.jsx(I$,{}):s.jsx("div",{className:"ms-ed-slot","data-slot":dt?"scenes":"layers",children:s.jsx("p",{children:dt?c.scenesSoon:c.layersSoon})})]}),s.jsxs("main",{className:"ms-fv-main ms-ed-main","aria-label":c.stage({label:Ka}),children:[s.jsxs("div",{className:"ms-ed-tools",children:[s.jsxs("div",{className:"ms-ed-undo",role:"toolbar","aria-label":c.draft({n:he?.ops.length??0}),children:[s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":c.undo,title:c.undoTip({keys:Pt()?"⌘Z":"Ctrl+Z"}),"aria-keyshortcuts":Pt()?"Meta+Z":"Control+Z",disabled:!he||ft!==null||he.past.length===0,onClick:()=>Tn.undo(),children:s.jsx(F,{name:"undo",size:14})}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":c.redo,title:c.redoTip({keys:Pt()?"⇧⌘Z":"Ctrl+Shift+Z"}),"aria-keyshortcuts":Pt()?"Shift+Meta+Z":"Control+Shift+Z",disabled:!he||ft!==null||he.future.length===0,onClick:()=>Tn.redo(),children:s.jsx(F,{name:"redo",size:14})}),he&&!dt?s.jsx($,{size:"sm",variant:"ghost",icon:!0,className:"ms-ed-snap","aria-label":c.snap,title:c.snapTip,"aria-pressed":fa,onClick:()=>Sn(!fa),children:s.jsx(F,{name:"magnet",size:14})}):null]}),s.jsxs("div",{className:"ms-ed-comments",role:"toolbar","aria-label":c.commentTools,children:[s.jsxs($,{size:"sm",variant:ta?"outline":"ghost",className:"ms-ed-spot","aria-pressed":ta,"aria-keyshortcuts":"P",title:Es?c.commentSpotTip:c.commentSpotLocked({n:Lt??0}),disabled:!he||!Es,onClick:ka,children:[s.jsx(F,{name:"pin",size:13}),c.commentSpot]}),he&&!dt?s.jsxs($,{size:"sm",variant:"ghost",className:"ms-ed-comment","aria-keyshortcuts":"C",disabled:Ct===null||!Es,title:Es?Ct===null?c.commentLayerNeeds:Wn!==null?c.commentElementTip:c.commentLayerTip:c.commentSpotLocked({n:Lt??0}),onClick:Xs,children:[s.jsx(F,{name:"comment",size:13}),Wn!==null?c.commentElement:c.commentLayer]}):null]}),s.jsx("span",{className:"ms-grow"}),he&&(_e||Ae)?s.jsx(dM,{edits:he.ops.length,nextN:Cs,blocked:fl,saving:rn,saved:Ae,onSave:()=>{Ms()},onDiscard:Bt}):null,s.jsx("span",{className:"ms-grow"}),!Va&&g?.subtitles?.length?s.jsxs($,{size:"sm",variant:"outline",className:"ms-ed-subtitles",onClick:()=>{uN(`${e}/${t}`,location.hash),Bs(es.subtitles(e,t,Xm(g.subtitles,Ht(g.creative.brief)?.primary)??void 0))},children:[s.jsx(F,{name:"text",size:13}),d.subtitles]}):null,X?.safeZone&&he&&!vi?s.jsxs("span",{className:"ms-fv-safe-toggle",children:[s.jsx(Un,{size:"sm",on:rh,onChange:Yb,label:d.safeZones}),s.jsx("span",{"aria-hidden":"true",children:d.safeZones})]}):null]}),s.jsxs("div",{className:"ms-fv-notes",children:[p.state?s.jsx(vr,{slug:e,state:p.state,reload:p.reload}):null,z?s.jsx("p",{role:"alert",className:"ms-cv-note ms-err",children:o.web.creative.formatsLoadFailed({detail:z})}):null,wn?.resumeFrom?s.jsx("p",{className:"ms-cv-note ms-info",children:o.web.creative.resumeNote({n:wn.resumeFrom.version})}):null,wn&&(wn.status==="error"||wn.status==="interrupted")&&wn.error&&!Xe?s.jsx("p",{role:"alert",className:"ms-cv-note ms-err",children:wn.error}):null,pi?s.jsx("p",{role:"alert",className:"ms-cv-note ms-err",children:pi}):null,L!==n?s.jsx("p",{className:"ms-cv-note ms-info",role:"status",children:c.editingPrimary({primary:I(L),also:oh})}):_.length>0?s.jsx("p",{className:"ms-cv-note ms-info ms-ed-also",role:"status",children:c.alsoUsedBy({list:oh})}):null,ft?s.jsxs("p",{className:"ms-cv-note ms-info ms-ed-readonly",role:"status",children:[s.jsx(F,{name:"lock",size:13}),s.jsx("span",{children:ft}),hs&&se!==null?s.jsx($,{size:"sm",variant:"outline",onClick:()=>J(null),children:c.editLatest({n:se})}):null]}):null,Xe&&ue?s.jsxs("div",{className:"ms-cv-note ms-info ms-fv-gen",children:[s.jsx("div",{className:"ms-progress ms-indet",role:"progressbar","aria-label":o.web.ui.progress,children:s.jsx("i",{})}),s.jsx("span",{className:"ms-cv-gen-step",children:ue})]}):null,yn&&Ln&&Oe!==null?s.jsxs("div",{className:"ms-idn-bar",children:[s.jsx(it,{label:o.web.identity.view,value:cr,onChange:Pa,options:[{value:"edit",label:c.edit,icon:"edit"},{value:"image",label:o.web.identity.viewImage,icon:"image"},{value:"sizes",label:o.web.identity.viewSizes,icon:"grid"}]}),yn.files.some(ce=>ce.role==="vector")?s.jsx(Tb,{slug:e,creative:t,n:Oe,format:L,label:Ka,kind:Ln,disabled:Xe,hasDark:or!==null}):null,Ln==="logo"&&or===null?s.jsxs("span",{className:"ms-idn-nodark",role:"note",title:o.web.identity.noDarkLogoTip,children:[s.jsx(F,{name:"refresh",size:13}),o.web.identity.noDarkLogo]}):null]}):null,Le?s.jsx("p",{role:"alert",className:"ms-cv-note ms-err",children:c.loadFailed({detail:Le})}):null,bs&&!qe&&_e?s.jsxs("p",{className:"ms-cv-note ms-err ms-ed-stale",role:"alert",children:[c.baseChangedBody({name:I(L),n:Z?.n??0}),s.jsx($,{size:"sm",variant:"outline",onClick:()=>Me(!0),children:c.reopenLatest})]}):null,hn?s.jsx("p",{role:"alert",className:"ms-cv-note ms-err",children:hn}):null,un?s.jsx("p",{role:"alert",className:"ms-cv-note ms-err",children:c.previewRefused({text:un})}):null,gn?s.jsx("p",{role:"alert",className:"ms-cv-note ms-err",children:gn}):null,Wt?s.jsxs("p",{className:"ms-cv-note ms-info ms-ed-staging",role:"status",children:[s.jsx(Ts,{size:13,label:c.stagingLong}),c.stagingLong]}):null]}),vi&&yn&&Ln&&Oe!==null?cr==="sizes"?s.jsx("section",{className:"ms-fv-stage ms-idn-stage","aria-label":o.web.identity.sizesTitle,children:s.jsx(Eb,{slug:e,creative:t,n:Oe,set:yn,kind:Ln})}):s.jsx("section",{className:"ms-fv-stage","aria-label":m.stage({label:Ka}),children:s.jsx("div",{className:"ms-fv-frame",style:ih,children:s.jsx("div",{className:"ms-fv-media",children:Wa&&Ln==="logo"?s.jsxs("div",{className:"ms-idn-split",role:"img","aria-label":o.web.identity.logoSides({label:`${Ka} v${Oe}`}),children:[s.jsxs("span",{className:"ms-idn-side ms-idn-light",children:[s.jsx("img",{src:Wa,alt:"",draggable:!1},Wa),s.jsx("span",{className:"ms-idn-sidelbl",children:o.web.identity.onLight})]}),s.jsxs("span",{className:"ms-idn-side ms-idn-dark",children:[s.jsx("img",{src:ch??Wa,alt:"",draggable:!1},ch??Wa),s.jsx("span",{className:"ms-idn-sidelbl",children:o.web.identity.onDark})]})]}):Wa?s.jsx("img",{src:Wa,alt:`${Ka} v${Oe}`,draggable:!1},Wa):null})})}):null,s.jsx("section",{className:"ms-fv-stage ms-ed-stage","aria-label":c.stage({label:Ka}),hidden:vi,children:s.jsxs("div",{ref:x,className:"ms-fv-frame",style:ih,"data-slot":"stage",children:[s.jsxs("div",{className:"ms-fv-media",children:[!he||ss.state.kind==="loading"||ss.state.kind==="busy"||ss.state.kind==="idle"?s.jsx("span",{className:"ms-cplayer-state",role:"status",children:he?ss.state.kind==="busy"?o.web.render.busy:o.web.render.loading:c.loading}):null,St?s.jsxs("span",{className:"ms-cplayer-state ms-cplayer-loading",role:"status",children:[s.jsx(Ts,{size:16,decorative:!0}),c.loadingVideo]}):null,ss.state.kind==="ready"?s.jsx(di,{session:ss.state.session,title:o.web.render.playerFrame({label:`${Ka} v${Oe??""}`}),onMedia:ys,onStall:ss.stalled,onShowing:mn},ns):null,ss.state.kind==="failed"?s.jsxs("span",{className:"ms-fv-failed",role:"alert",children:[s.jsx("span",{children:c.previewFailed({detail:ss.state.message})}),s.jsxs($,{size:"sm",variant:"outline",onClick:()=>{ss.retry(),Ys(ce=>ce+1)},children:[s.jsx(F,{name:"refresh",size:12}),o.web.render.retry]})]}):null,rh&&X?s.jsx(Jv,{preset:X}):null]}),he&&!js?s.jsx(t$,{}):null,s.jsx(db,{player:Ie,preview:tt}),Es&&B&&ls.ready&&(!dt||!ls.playing)?s.jsx(yb,{clock:ls.clock,video:dt,marks:sa,open:ut?.index??null,onOpen:ce=>Et(ce-1)}):null,ta&&B?s.jsx(jb,{clock:ls.clock,video:dt,label:Ka,onPlace:lr}):null]})}),ta&&B?s.jsx(wb,{clock:ls.clock,video:dt}):null,g?s.jsx(cb,{brief:g.creative.brief,preview:tt,className:"ms-ed-locales"}):null,js?s.jsx("p",{className:"ms-cv-note ms-info",role:"status",children:o.web.languages.editorPreviewNote}):null,he&&!dt&&!vi?s.jsx(iF,{zoom:pa,onZoom:Fn}):null]}),s.jsx("aside",{className:"ms-ed-side ms-ed-right ms-chat-col","aria-label":c.panelTabs,"data-part":"r",children:s.jsxs("div",{className:"ms-chat-card",children:[s.jsx(hc,{label:c.panelTabs,value:ln,onChange:Kn,className:"ms-ed-tabs",tabs:[{value:"chat",label:c.chat,controls:"ms-ed-panel",...st.length?{count:st.length}:{}},{value:"inspector",label:c.inspector,controls:"ms-ed-panel"}]}),st.length?s.jsx("span",{className:"ms-sr",role:"status",children:c.pendingComments({n:st.length})}):null,s.jsx("div",{id:"ms-ed-panel",role:"tabpanel",className:"ms-ed-panel",children:ln==="chat"?g?s.jsx(Ec,{slug:e,creative:t,entries:b,approvals:_s,job:$s,live:Ss,self:w.self,memberJobs:w.memberJobs,single:w.single,otherPins:Cn,onRemoveOtherPin:ce=>Pn([ce]),pins:st.map(ce=>ce.pin),onRemovePin:Ws,onEditPin:Et,onSelectVersion:Lc,formatName:I,canGenerate:T.length===0,onSent:Ac,beforeSend:fn,snapshots:a.snapshots,versionSummary:ce=>{const $e=T.find(Je=>Je.n===ce);return $e?.origin==="editor"&&$e.request?$e.request:null},appliesTo:Sr,brief:g.creative.brief,onBriefSaved:y,queued:g.creative.queued,onQueueChanged:y}):s.jsx("div",{className:"ms-cv-state",children:s.jsx(Ts,{size:16,label:d.loading})}):Ic?s.jsx(tF,{}):s.jsx("div",{className:"ms-ed-slot","data-slot":"inspector",children:s.jsx("p",{children:c.inspectorSoon})})})]})}),s.jsx("section",{className:"ms-ed-timeline","aria-label":c.timeline,"data-part":"b","data-slot":"timeline",children:dt&&he?s.jsx(v$,{loop:ee,onLoop:as,speed:Is,onSpeed:Hs,marks:sa,overlay:({pps:ce})=>s.jsx(YR,{marks:sa,pps:ce}),onRange:xa,onCommentClip:Xs,onCommentRange:wa,canCommentClip:Ct!==null}):null}),Yt?s.jsx(bb,{open:!0,playhead:Ie?.currentTime??ls.clock.get().time,duration:he?.composition.duration??0,onSubmit:ce=>{An(!1),xa(ce)},onCancel:()=>An(!1)}):null,s.jsx(UR,{open:ut!==null,title:cs,initial:ut?.pin.note??"",adding:ut?.index===null,onSubmit:Na,onCancel:()=>Gn(null)}),s.jsx(rt,{open:bt!==null,onClose:ha,label:c.leaveTitle,width:480,dismissible:!rn,children:s.jsxs("div",{className:"ms-ed-dialog",children:[s.jsx("h2",{children:c.leaveTitle}),s.jsx("p",{children:c.leaveBody({n:Ne?.ops.length??0})}),bt?.mode==="chat"?s.jsx("p",{children:c.leaveBodyChat}):null,s.jsxs("div",{className:"ms-ed-dialog-foot",children:[s.jsx($,{variant:"ghost",disabled:rn,onClick:ha,children:c.leaveKeep}),s.jsx($,{variant:"outline",disabled:rn,onClick:jt,children:c.leaveDiscard}),s.jsx($,{variant:"ink",loading:rn,disabled:fl!==null,title:fl??void 0,onClick:()=>{Vn()},children:c.leaveSave({n:Cs})})]}),fl!==null?s.jsx("p",{className:"ms-ed-dialog-why",role:"note",children:fl}):null]})}),s.jsx(rt,{open:qe&&_e,onClose:()=>Ye(!1),label:c.baseChangedTitle,width:480,children:s.jsxs("div",{className:"ms-ed-dialog",children:[s.jsx("h2",{children:c.baseChangedTitle}),s.jsx("p",{children:c.baseChangedBody({name:I(L),n:Z?.n??0})}),hn?s.jsx("p",{children:hn}):null,s.jsxs("div",{className:"ms-ed-dialog-foot",children:[s.jsx($,{variant:"ghost",onClick:()=>Ye(!1),children:c.keepEditing}),s.jsx($,{variant:"ink",onClick:()=>{Ye(!1),Me(!0)},children:c.reopenLatest})]})]})}),s.jsx(rt,{open:Us,onClose:()=>Me(!1),label:c.reopenTitle,width:440,children:s.jsxs("div",{className:"ms-ed-dialog",children:[s.jsx("h2",{children:c.reopenTitle}),s.jsx("p",{children:c.reopenBody}),s.jsxs("div",{className:"ms-ed-dialog-foot",children:[s.jsx($,{variant:"ghost",onClick:()=>Me(!1),children:c.keepEditing}),s.jsx($,{variant:"danger",onClick:()=>{Me(!1),Ye(!1),et(!1),D(null),Ke.discard(),vs(null),Z&&is(Z.n),gs(ce=>ce+1)},children:c.reopenConfirm})]})]})}),Ve?s.jsx(Im,{open:Ve.open,onClose:()=>zs(ce=>ce&&{...ce,open:!1}),slug:e,creative:t,versions:T,presets:N,labels:K,states:A,format:L,initial:Ve.init,actions:M}):null,s.jsx(Ho,{open:!!ye?.open,onClose:()=>He(ce=>ce&&{...ce,open:!1}),slug:e,creative:t,title:g?.creative.title??"",snapshot:ye?.snapshot??null,presets:N,labels:g?.creative.brief.formatLabels,pattern:r??So,onSettings:l,jobs:a.jobs,...g&&Ht(g.creative.brief)?{locales:Ht(g.creative.brief)}:{},...g?.subtitles?.length?{subtitles:g.subtitles}:{}})]});return Ic?s.jsx(Mb.Provider,{value:Ic,children:s.jsx(N$,{children:dh})}):dh}const Ob=["1","2","3","4","5"],fF=Ob.length;function Pp({count:e,onCount:t,directions:n,onDirections:a,disabled:r}){const l=V().web.variantGroup,o=(c,d)=>{const m=[...n];for(;m.length<=c;)m.push("");m[c]=d,a(m)};return s.jsxs("div",{className:"ms-nc-variants",role:"group","aria-label":l.variants,children:[t?s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"ms-nc-lbl",children:[l.variants," ",s.jsx("span",{className:"ms-nc-faint",children:l.fieldHint})]}),s.jsx(it,{label:l.variants,value:String(Math.min(fF,Math.max(1,e))),disabled:r,onChange:c=>t(Number(c)),options:Ob.map(c=>({value:c,label:c}))})]}):null,e>=2?s.jsxs("div",{className:"ms-nc-vdirs",children:[Array.from({length:e},(c,d)=>bx(d)).map((c,d)=>s.jsxs("div",{className:"ms-nc-vdir",children:[s.jsx("label",{htmlFor:`ms-nc-dir-${c}`,children:l.directionOf({letter:It(c)})}),s.jsx(ms,{id:`ms-nc-dir-${c}`,value:n[d]??"",maxLength:_o,disabled:r,placeholder:l.directionPlaceholder,onChange:m=>o(d,m.target.value)})]},c)),s.jsx("span",{className:"ms-nc-faint ms-nc-small",children:l.directionAuto})]}):null]})}const ku=["6","15","30","60","custom"];function pF(e,t){const n=Number(e==="custom"?t:e);return Number.isInteger(n)&&n>=1&&n<=600?n:null}function xF(e){return{goal:e.goal,message:e.message,notes:e.notes,durationSec:pF(e.length,e.customSec),assets:e.picked,linkedCodebases:e.codebases,formats:e.selected,variants:Math.min(xy,Math.max(1,Math.round(e.variantCount)))}}function gF(e){if(e===null)return{length:"custom",customSec:""};const t=ku.find(n=>n!=="custom"&&Number(n)===e);return t?{length:t,customSec:""}:{length:"custom",customSec:String(e)}}const vF=(e,t)=>JSON.stringify(e)===JSON.stringify(t);function bF(e,t,n=[]){const a={...e.form},r=new Set,l=new Set,o=[],c=[];for(const d of py){const m=!vF(e.form[d],t.form[d]);if(e.pending.has(d)&&m&&!n.includes(d)){r.add(d);continue}o.push(d),m&&(c.push(d),a[d]=t.form[d]),t.userEdited.includes(d)&&r.add(d),t.agentFields.includes(d)&&!t.userEdited.includes(d)&&l.add(d)}return{form:a,userEdited:r,agentFields:l,taken:o,changed:c}}const jF=400,Ap=new Set(["queued","running"]),yF=[],Lp=(e,t)=>[...new Set([...e,...t])],Hi=(e,t)=>e?t?{seq:Math.max(e.seq,t.seq),written:Lp(e.written,t.written),reclaimed:Lp(e.reclaimed,t.reclaimed)}:e:t,Gi=(e,t,n)=>e!==null&&e.id===n&&t.revision<e.revision;function wF(e,t,n={}){const a=i.useRef(n.onFormatUnavailable);a.current=n.onFormatUnavailable;const[r,l]=i.useState({session:null,entries:[],status:"loading",lastFill:null}),[o,c]=i.useState(null),[d,m]=i.useState(null),u=i.useRef(null),h=i.useCallback(U=>{l(te=>{const G=U(te);return u.current=G.session,G})},[]),f=i.useRef(new Set),x=i.useRef(!0);i.useEffect(()=>(x.current=!0,()=>{x.current=!1}),[]);const p=i.useRef(async()=>{}),g=i.useCallback(U=>{if(!(U instanceof lt))return!1;if(U.code==="format-unavailable"&&a.current)return a.current(),!0;if(U.code==="brief-session-unreadable")return h(()=>({session:null,entries:[],status:"unreadable",lastFill:null})),!0;if(U.code==="brief-session-gone"||U.code==="brief-session-handed-off"){m({code:U.code,message:U.message,sessionId:u.current?.id??null});const te=U.code==="brief-session-gone";return p.current(null).then(()=>{te&&x.current&&m(G=>G?.code==="brief-session-gone"?null:G)}),!0}return!1},[h]),b=i.useCallback(U=>{x.current&&!g(U)&&c(pe(U))},[g]),v=i.useRef(null),y=i.useRef(null),w=i.useCallback(async U=>{if(v.current)return y.current={fill:Hi(y.current?.fill??null,U)},v.current;const te=(async()=>{try{const G=await q.getBriefSession(e),re=G?await q.getBriefConversation(e,G.id):[];if(!x.current)return;h(oe=>G&&Gi(oe.session,G,G.id)?U&&oe.session?{...oe,session:{...oe.session},lastFill:Hi(oe.lastFill,U)}:oe:{session:G,entries:re,status:"ready",lastFill:U?Hi(oe.lastFill,U):oe.lastFill}),c(null)}catch(G){if(!x.current)return;G instanceof lt&&G.code==="brief-session-unreadable"?h(()=>({session:null,entries:[],status:"unreadable",lastFill:null})):(h(re=>({...re,status:re.status==="loading"||re.status==="failed"?"failed":re.status})),c(pe(G)))}})();if(v.current=te,await te,v.current=null,y.current){const G=y.current.fill;y.current=null,await w(G)}},[e,h]);p.current=w,i.useEffect(()=>{w(null)},[w]);const j=t?.briefTicks?.[e]??0,S=i.useRef(j),k=i.useRef(Math.max(0,...(t?.briefFills?.[e]??[]).map(U=>U.seq)));i.useEffect(()=>{if(j===S.current)return;S.current=j;const U=u.current?.id,te=(t?.briefFills?.[e]??[]).filter(re=>re.seq>k.current);k.current=Math.max(k.current,...te.map(re=>re.seq));const G=te.filter(re=>!U||re.sessionId===U).reduce((re,oe)=>Hi(re,{seq:oe.seq,written:oe.written,reclaimed:oe.reclaimed}),null);w(G)},[j]);const E=t?.snapshots??0,N=i.useRef(E);i.useEffect(()=>{E!==N.current&&(N.current=E,w(null))},[E,w]);const C=i.useMemo(()=>{const U=r.session,te=new Set(r.entries.flatMap(G=>G.type==="agent"?[G.jobId]:G.type==="user"&&G.jobId?[G.jobId]:[]));return Object.values(t?.jobs??{}).filter(G=>G.kind==="brief"&&G.key.startsWith("brief:")&&G.key.endsWith(`:${e}`)).filter(G=>G.id===U?.jobId||te.has(G.id)||f.current.has(G.id)).sort((G,re)=>G.createdAt.localeCompare(re.createdAt)).at(-1)},[t?.jobs,r.session,r.entries,e]),R=C?`${C.id}:${C.state}`:"",P=i.useRef(R);i.useEffect(()=>{if(R===P.current)return;const U=P.current!==""&&C&&!Ap.has(C.state);P.current=R,(U||C&&Ap.has(C.state)&&r.session?.jobId!==C.id)&&w(null)},[R]);const z=i.useCallback(U=>{x.current&&h(te=>Gi(te.session,U,U.id)?te:{...te,session:U,status:"ready"})},[h]),O=i.useCallback(async U=>{if(u.current)return u.current;try{const te=await q.startBriefSession(e,U);return u.current=te,z(te),m(null),te}catch(te){throw b(te),te}},[e,z,b]),T=i.useCallback(async(U,te)=>{const G=te??u.current?.id;if(!G)throw new Error("no brief session");try{const re=await q.sendBriefMessage(e,G,U);return re.outcome==="started"&&f.current.add(re.job.id),m(null),w(null),re}catch(re){throw x.current&&g(re),re}},[e,w,g]),W=i.useRef(Promise.resolve()),Z=i.useCallback(async U=>{const te=u.current;if(!te)return null;try{const G=await q.saveBriefForm(e,te.id,U());return x.current&&(h(re=>re.session&&re.session.id===te.id&&!Gi(re.session,G,te.id)?{...re,session:{...re.session,form:G.form,userEdited:G.userEdited,agentFields:G.agentFields,revision:G.revision}}:re),c(null)),G}catch(G){return b(G),null}},[e,h,b]),A=i.useCallback(U=>{const te=W.current.then(()=>Z(U));return W.current=te.catch(()=>{}),te},[Z]),L=i.useRef(null),_=i.useRef(null),X=i.useCallback(()=>{_.current&&(clearTimeout(_.current),_.current=null);const U=L.current;if(L.current=null,!U)return;const te=u.current?.id;A(U.body).then(G=>{U.settle?.(G!==null),G&&te&&x.current&&h(re=>re.session&&Gi(re.session,G,te)?{...re,session:{...re.session}}:re)})},[A,h]),ae=i.useCallback((U,te)=>{L.current={body:U,...te?{settle:te}:{}},_.current&&clearTimeout(_.current),_.current=setTimeout(X,jF)},[X]),K=i.useCallback(U=>A(U),[A]),I=i.useRef(X);I.current=X,i.useEffect(()=>()=>{I.current()},[]);const H=i.useCallback(async U=>{const te=u.current;if(te)try{z(await q.setBriefContext(e,te.id,U))}catch(G){throw b(G),G}},[e,z,b]),de=i.useCallback(async U=>{const te=u.current;if(te)try{z(await q.removeBriefQueued(e,te.id,U))}catch(G){throw b(G),G}},[e,z,b]),J=i.useCallback(async()=>{const U=u.current;await q.discardBriefSession(e,U?.id??d?.sessionId??"unreadable"),L.current=null,_.current&&(clearTimeout(_.current),_.current=null),f.current.clear(),m(null),x.current&&h(()=>({session:null,entries:[],status:"ready",lastFill:null}))},[e,d,h]),se=i.useCallback(()=>w(null),[w]);return{session:r.session,entries:r.entries,job:C,live:C&&t?.events[C.id]||yF,status:r.status,error:o,conflict:d,lastFill:r.lastFill,ensure:O,send:T,saveForm:ae,saveNow:K,flushSave:X,setContext:H,removeQueued:de,discard:J,refresh:se,report:g}}const kF=e=>e.slice(e.lastIndexOf("/")+1);function NF({slug:e,view:t,onDone:n}){const a=V(),[r,l]=i.useState(t.pending);if(i.useEffect(()=>{t.pending&&l(t.pending)},[t.pending]),!r)return null;const o=r.kind==="long"?a.videoAnalysis.longTitle({file:kF(t.file)}):em(a,t.file),c=()=>n?.(t.file);return s.jsx("div",{className:"ms-tcard",role:"group","aria-label":o,"data-analysis-question":t.file,children:r.kind==="long"?s.jsx(bg,{slug:e,view:t,question:r,onDone:c}):s.jsx(jg,{slug:e,view:t,question:r,onDone:c})})}const SF=e=>e.split("/").pop()??e;function CF({open:e,onClose:t,anchor:n,placement:a="bottom-start",onComputer:r,onLibrary:l}){const o=V().web.newCreative,c=i.useRef(null),d=u=>{const h=[...c.current?.querySelectorAll('[role="menuitem"]')??[]],f=h.indexOf(document.activeElement),x=u.key==="ArrowLeft"||u.key==="ArrowRight"?null:Ma(u.key,f<0?0:f,h.length);x!==null&&(u.preventDefault(),h[x]?.focus())},m=(u,h,f,x)=>s.jsxs("button",{type:"button",role:"menuitem","data-row":"",className:"ms-brief-mi",onClick:()=>{t(),x()},children:[s.jsx(F,{name:u,size:16}),s.jsxs("span",{children:[s.jsx("b",{children:h}),s.jsx("small",{children:f})]})]});return s.jsx(ot,{open:e,onClose:t,anchor:n,placement:a,width:300,children:s.jsxs("div",{ref:c,role:"menu","aria-label":o.addAssets,className:"ms-brief-menu",onKeyDown:d,children:[m("upload",o.fromComputer,o.fromComputerHint,r),m("image",o.fromLibrary,o.fromLibraryHint,l)]})})}function Db({path:e,reference:t,busy:n,onToggle:a,className:r}){const l=V().web.newCreative,o=SF(e),c=t?l.referenceOnlyHint({name:o}):l.referenceSavedHint({name:o});return s.jsxs("button",{type:"button",className:le("ms-nc-refmark",!t&&"ms-saved",r),"aria-label":c,title:c,"aria-pressed":!t,"aria-busy":n||void 0,disabled:n,onClick:a,children:[s.jsx(F,{name:t?"pin":"check",size:10,strokeWidth:2}),s.jsx("span",{children:t?l.referenceOnly:l.referenceSaved})]})}function EF(e,t){const n=V().web.newCreative,[a,r]=i.useState([]),[l,o]=i.useState(()=>new Set),[c,d]=i.useState([]),[m,u]=i.useState(()=>new Set),[h,f]=i.useState(()=>new Map),x=j=>f(S=>new Map([...S,...j.map(k=>[`assets/${k.file}`,k])])),p=i.useRef(0),g=i.useRef(t.onLibraryChanged);g.current=t.onLibraryChanged;const b=i.useCallback(async(j,S={})=>{if(j.length===0)return{paths:[],error:null};const k=++p.current,E=j.map(C=>C.name),N=S.tiles!==!1;N&&d(C=>[...C,{id:k,names:E,error:null}]);try{const C=(await q.uploadFiles(e,"assets",j,{reference:!0})).assets??[];d(P=>P.filter(z=>z.id!==k)),r(P=>[...P.filter(z=>!C.some(O=>O.file===z.file)),...C]),x(C);const R=C.map(P=>`assets/${P.file}`);return o(P=>new Set([...P,...R])),{paths:R,error:null}}catch(C){return N&&d(R=>R.map(P=>P.id===k?{...P,error:pe(C)}:P)),{paths:[],error:pe(C)}}},[e]),v=i.useCallback(j=>d(S=>S.filter(k=>k.id!==j)),[]),y=i.useCallback(async j=>{const S=!ql(j);u(k=>new Set([...k,j.file]));try{const k=await q.setAssetReference(e,j.file,S);return r(E=>S?[...E.filter(N=>N.file!==k.file),k]:E.filter(N=>N.file!==k.file)),x([k]),g.current(),k}catch(k){return Pe.show(n.referenceFailed({detail:pe(k)})),null}finally{u(k=>new Set([...k].filter(E=>E!==j.file)))}},[e,n]);return{refs:a,setRefs:r,here:l,pending:c,busy:m,upload:b,dismiss:v,toggle:y,entryOf:(j,S)=>h.get(j)??S?.find(k=>`assets/${k.file}`===j)??a.find(k=>`assets/${k.file}`===j)??null}}const TF=new Set(["queued","running"]);function RF({slug:e,projectName:t,brief:n,live:a,snapshot:r,onCarried:l,draft:o,library:c,onRetryLibrary:d,onLibraryChanged:m,hidden:u,panelRef:h,className:f,onOpenCreative:x,analysisQuestions:p,references:g}){const b=V(),v=b.web.briefSession,[y,w]=i.useState([]),j=i.useRef(y);j.current=y;const[S,k]=i.useState(!1),[E,N]=i.useState(""),[C,R]=i.useState(null),[P,z]=i.useState(!1),O=i.useRef(null),T=i.useRef(null),W=n.session,Z=n.job,A=!!(Z&&TF.has(Z.state)),L=n.entries.some(Q=>Q.type==="user"),_=A?v.state.working:(W?.agentFields.length??0)>0?v.state.filled:v.state.new,X=Q=>w(Re=>Re.some(Ue=>Ue.kind===Q.kind&&Ue.path===Q.path)?Re:[...Re,Q]),ae=Q=>w(Re=>Re.filter(Ue=>!(Ue.kind===Q.kind&&Ue.path===Q.path))),K=Q=>{const Re=Q.trim(),Ue=SC(Re,b);return Ue?(R(Ue),!1):(R(null),X({kind:"folder",path:Re}),!0)},I=async()=>{const Q=xt();if(!Q){k(!0),R(null);return}try{const Re=await Q.pickFolder(v.folder.title);Re&&K(Re)}catch(Re){R(pe(Re))}},H=async Q=>{if(Q.length!==0){if(R(null),g){const Re=await g.upload(Q,{tiles:!1});for(const Ue of Re.paths)X({kind:"asset",path:Ue});Re.error!==null&&R(v.uploadFailed({detail:Re.error}));return}try{const Re=await q.uploadFiles(e,"assets",Q,{reference:!0});for(const Ue of Re.assets??[])X({kind:"asset",path:Ll(Ue.file)});m()}catch(Re){R(v.uploadFailed({detail:pe(Re)}))}}},de=(Q,Re)=>{const Ue=[...Q.codebases],is=[...Q.assets];for(const Qe of Re)Qe.kind==="folder"&&!Ue.some(gs=>gs.path===Qe.path)&&Ue.push({path:Qe.path}),Qe.kind==="asset"&&!is.includes(Qe.path)&&is.push(Qe.path);return{context:{codebases:Ue,assets:is},added:Ue.length>Q.codebases.length||is.length>Q.assets.length}},J=i.useMemo(()=>({start:async({clientId:Q,text:Re})=>{const Ue=r(),is=n.session;try{const Qe=await n.ensure({form:Ue.form,userEdited:Ue.userEdited}),gs=j.current,As=await n.send({clientId:Q,text:Re,context:de(Qe.context,gs).context,form:Ue.form,userEdited:Ue.userEdited,baseRevision:is?Ue.baseRevision:Qe.revision},Qe.id);return l?.(!0),w(hs=>hs.filter(Oe=>!gs.includes(Oe))),As.outcome==="started"?As.job:null}catch(Qe){throw l?.(!1),Qe}},post:async({clientId:Q,text:Re,mode:Ue})=>{const is=r(),Qe=n.session;if(!Qe)throw new Error(b.errors.briefSessionGone);const gs=j.current;let As;try{As=await n.send({clientId:Q,text:Re,context:de(Qe.context,gs).context,form:is.form,userEdited:is.userEdited,baseRevision:is.baseRevision,mode:Ue})}catch(hs){throw l?.(!1),hs}return l?.(!0),w(hs=>hs.filter(Oe=>!gs.includes(Oe))),{outcome:As.outcome==="started"?"delivered-pending":As.outcome}}}),[n,r,l,b]),se=i.useMemo(()=>Object.values(a?.approvals??{}).filter(Q=>Z&&Q.jobId===Z.id),[a?.approvals,Z]),U=i.useMemo(()=>(W?.queued??[]).map(Q=>({clientId:Q.clientId,text:Q.text,pins:[],at:Q.at})),[W?.queued]),te=Q=>g?g.entryOf(Q,c.value):c.value?.find(Re=>Ll(Re.file)===Q)??null,G=Q=>{const Re=te(Q);return!g||!Re||!(ql(Re)||g.here.has(Q))?null:s.jsx(Db,{path:Q,reference:ql(Re),busy:g.busy.has(Re.file),onToggle:()=>{g.toggle(Re)},className:"ms-brief-refmark"})},re=Q=>{const Re=te(Q);return Re&&(Re.kind==="image"||Re.kind==="svg")?q.projectFileUrl(e,Q):null},oe=y.filter(Q=>Q.kind==="asset").map(Q=>Q.path),Ne=i.useMemo(()=>(p??[]).map(Q=>({key:Q.file,node:s.jsx(NF,{slug:e,view:Q})})),[p,e]);return s.jsxs("aside",{ref:h,className:le("ms-brief-panel ms-chat-card",f),"aria-label":v.panelLabel,"aria-hidden":u||void 0,inert:u||void 0,children:[s.jsxs("header",{className:"ms-brief-head",children:[s.jsx("span",{className:"ms-brief-avatar","aria-hidden":"true",children:s.jsx(F,{name:"sparkle",size:12})}),s.jsx("b",{className:"ms-brief-title",children:v.title}),s.jsx(Qs,{tone:"neutral",className:"ms-brief-state",children:_})]}),n.status==="unreadable"?s.jsxs("div",{className:"ms-brief-alert",role:"alert",children:[s.jsx("span",{children:b.errors.briefSessionUnreadable}),s.jsx($,{size:"sm",variant:"outline",onClick:()=>{n.discard().catch(Q=>R(pe(Q)))},children:v.startOver})]}):n.conflict||W?.handedOffTo!==void 0?s.jsxs("div",{className:"ms-brief-alert",role:"alert",children:[s.jsx("span",{children:n.conflict?.message??b.errors.briefHandedOff}),n.conflict?.code!=="brief-session-gone"?s.jsxs(s.Fragment,{children:[W?.handedOffTo&&x?s.jsx($,{size:"sm",variant:"outline",onClick:()=>x(W.handedOffTo),children:v.openCreative}):null,s.jsx($,{size:"sm",variant:"ghost",onClick:()=>{n.discard().catch(Q=>R(pe(Q)))},children:v.discard})]}):null]}):n.status==="failed"?s.jsxs("div",{className:"ms-brief-alert",role:"alert",children:[s.jsx("span",{children:v.loadFailed({detail:n.error??""})}),s.jsx($,{size:"sm",variant:"outline",onClick:()=>{n.refresh()},children:b.web.newCreative.tryAgain})]}):n.error?s.jsx("p",{className:"ms-brief-alert",role:"alert",children:n.error}):null,s.jsx(Ec,{slug:e,creative:"",entries:n.entries,approvals:se,job:Z,live:n.live,snapshots:a?.snapshots,queued:U,queueOps:{remove:n.removeQueued},onQueueChanged:()=>{n.refresh()},transport:J,draft:o,composerLabel:v.composerLabel,placeholder:L?v.placeholderFollowUp:v.placeholderFirst,extraContent:y.length>0,composerDisabled:n.status==="failed",intro:v.intro,cards:Ne,composerTop:s.jsxs(s.Fragment,{children:[S?s.jsxs("div",{className:"ms-brief-folder-form",role:"group","aria-label":v.folder.title,children:[s.jsx(ms,{className:"ms-brief-folder-input","aria-label":v.folderPath,placeholder:b.web.codebase.pathPlaceholder,value:E,autoFocus:!0,onChange:Q=>{N(Q.target.value),R(null)},onKeyDown:Q=>{Q.key==="Enter"&&(Q.preventDefault(),K(E)&&(N(""),k(!1))),Q.key==="Escape"&&(Q.preventDefault(),k(!1))}}),s.jsx($,{size:"sm",variant:"ghost",onClick:()=>{k(!1),R(null)},children:v.cancel}),s.jsx($,{size:"sm",variant:"ink",onClick:()=>{K(E)&&(N(""),k(!1))},children:v.link})]}):null,C?s.jsx("p",{className:"ms-composer-error",role:"alert",children:C}):null,s.jsx(EC,{pins:y,onRemove:ae,thumb:re,mark:G})]}),composerTools:s.jsxs(s.Fragment,{children:[s.jsx(CC,{disabled:n.status==="failed",onFolder:()=>{I()},onLibrary:Q=>{O.current=Q,z(!0)},onUpload:()=>T.current?.click()}),s.jsx("input",{ref:T,type:"file",multiple:!0,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:Q=>{const Re=[...Q.target.files??[]];Q.target.value="",H(Re)}})]}),composerBelow:W?s.jsx(Lf,{context:W.context,onChange:Q=>{n.setContext(Q).catch(Re=>R(pe(Re)))}}):s.jsx(Lf,{context:{codebases:[],assets:[]},onChange:()=>{},disabled:!0})}),s.jsx(Cm,{slug:e,projectName:t,open:P,onClose:()=>z(!1),anchor:O,placement:"top-start",library:c,onRetry:d,chosen:oe,...g?{extra:g.refs.filter(Q=>oe.includes(Ll(Q.file)))}:{},onToggle:Q=>oe.includes(Q)?ae({kind:"asset",path:Q}):X({kind:"asset",path:Q})})]})}function MF({open:e,onResume:t,onStartOver:n}){const a=V().web.briefSession;return s.jsx(rt,{open:e,onClose:()=>{},label:a.resumeTitle,width:460,dismissible:!1,children:s.jsxs("div",{className:"ms-brief-resume",children:[s.jsx("h2",{children:a.resumeTitle}),s.jsx("p",{children:a.resumeBody}),s.jsxs("div",{className:"ms-brief-resume-actions",children:[s.jsx($,{variant:"ghost",onClick:n,children:a.startOver}),s.jsx($,{variant:"ink",autoFocus:!0,onClick:t,children:a.resume})]})]})})}const $F=[[1,1],[4,5],[9,16],[16,9]],FF=1080,Yl=16,Yo=8192,Qo=(e,t,n)=>{if(!/^\d+$/.test(e.trim()))return null;const a=Number(e.trim());return a>=t&&a<=n?a:null};function PF(e,t,n,a=0){const r={},l=e.name.trim();l?t.some(o=>yx(o)&&!o.hidden&&o.id!==n&&vy(o.name,l))&&(r.name="nameTaken"):r.name="name";for(const o of["width","height"]){const c=Qo(e[o],Yl,Yo);c===null?r[o]="size":e.kind==="video"&&c>jx?r[o]="videoMax":e.kind==="video"&&c%2!==0&&(r[o]="even")}if(e.kind==="video"&&e.duration.trim()){const o=Qo(e.duration,1,by);o===null?r.duration="duration":o<a&&(r.duration="durationShort")}return r}function AF(e){return{name:e.name.trim(),kind:e.kind,width:Number(e.width),height:Number(e.height),...e.kind==="video"&&e.duration.trim()?{maxDurationSec:Number(e.duration)}:{}}}function LF(e,[t,n],a=!1){const r=e*n/t;return a?Math.min(jx,Math.max(Yl,Math.round(r/2)*2)):Math.min(Yo,Math.max(Yl,Math.round(r)))}const IF=(e,t,[n,a])=>Math.abs(e*a/n-t)<=1,Ip=e=>e?{name:e.name,kind:e.kind,width:String(e.width),height:String(e.height),duration:e.maxDurationSec!==void 0?String(e.maxDurationSec):""}:{name:"",kind:"image",width:"1080",height:"1080",duration:""},zF={"custom-format-name-taken":"name","custom-format-in-use":"width","custom-format-duration-too-short":"duration"};function OF({open:e,onClose:t,editing:n,presets:a,onSaved:r,onDeleted:l}){const o=V(),c=o.web.newCreative,[d,m]=i.useState(()=>Ip(n)),[u,h]=i.useState({}),[f,x]=i.useState(!1),[p,g]=i.useState(null),[b,v]=i.useState(!1),[y,w]=i.useState(null),[j,S]=i.useState(0),k={name:i.useRef(null),width:i.useRef(null),height:i.useRef(null),duration:i.useRef(null)},E=i.useRef(null),N=i.useRef(!1);i.useEffect(()=>{e&&(m(Ip(n)),h({}),g(null),v(!1),x(!1),w(null))},[e,n]),i.useEffect(()=>{if(!e||!n)return;let U=!0;return w(null),Promise.resolve().then(()=>q.customFormatUsage(n.id)).then(te=>{U&&w(te)}).catch(()=>{U&&w("failed")}),()=>{U=!1}},[e,n,j]),i.useEffect(()=>{!b&&N.current&&(N.current=!1,E.current?.focus())},[b]);const C=y!==null&&y!=="failed"?y:null,R=C?C.creatives+C.unreadable:0,P=n!==null&&(C===null||R>0),z=C?.longestSec??0,O=U=>{m(te=>({...te,...U})),h(te=>{const G={...te};for(const re of Object.keys(U))re==="kind"?(delete G.width,delete G.height,delete G.duration):delete G[re];return G})},T=U=>U.replace(/\D/g,"").slice(0,4),W=d.kind==="video",Z=Qo(d.width,Yl,Yo),A=Qo(d.height,Yl,Yo),L=U=>Z!==null&&A!==null&&IF(Z,A,U),_=U=>{const te=Z??FF;O({width:String(te),height:String(LF(te,U,W))})},X=U=>({name:c.customErrName,nameTaken:c.customErrNameTaken,size:c.customErrSize,even:c.customErrEven,videoMax:c.customErrVideoMax,duration:c.customErrDuration,durationShort:c.customErrDurationShort({sec:z})})[U],ae=U=>{const te=["name","width","height","duration"].find(G=>U[G]);return te&&k[te].current?.focus(),te},K=async()=>{if(f)return;const U=PF(d,a,n?.id??null,z);if(h(Object.fromEntries(Object.entries(U).map(([te,G])=>[te,X(G)]))),!ae(U)){x(!0),g(null);try{const te=AF(d),G=n?await q.editCustomFormat(n.id,te):await q.addCustomFormat(te);r(G.preset,G.catalog,n===null)}catch(te){x(!1);const G=te instanceof lt&&te.code?zF[te.code]:void 0;G?(h({[G]:pe(te)}),te instanceof lt&&te.code==="custom-format-in-use"&&S(re=>re+1),setTimeout(()=>k[G].current?.focus(),0)):g(c.customFailed({detail:pe(te)}))}}},I=async()=>{if(!(!n||f)){x(!0),g(null);try{const U=await q.deleteCustomFormat(n.id);l(n,U.outcome,U.catalog)}catch(U){g(c.customDeleteFailed({detail:pe(U)})),x(!1)}}},H=U=>U==="width"||U==="height"?"ms-cfd-size-err":`ms-cfd-${U}-err`,de=U=>({"aria-invalid":u[U]?!0:void 0,"aria-describedby":[u[U]?H(U):"",(U==="width"||U==="height")&&P?"ms-cfd-locked":"",U==="duration"?"ms-cfd-dur-hint":""].filter(Boolean).join(" ")||void 0}),J=U=>u[U]?s.jsx("p",{id:H(U),className:"ms-cfd-err",role:"alert",children:u[U]}):null,se=n?c.customEditTitle:c.customNewTitle;return s.jsx(rt,{open:e,onClose:t,label:se,width:460,dismissible:!f,children:s.jsxs("form",{className:"ms-cfd",noValidate:!0,onSubmit:U=>{U.preventDefault(),K()},children:[s.jsx("h2",{children:se}),s.jsx("label",{htmlFor:"ms-cfd-name",children:c.customName}),s.jsx(ms,{id:"ms-cfd-name",ref:k.name,autoFocus:!0,value:d.name,maxLength:gy,placeholder:c.customNamePlaceholder,onChange:U=>O({name:U.target.value}),...de("name")}),J("name"),s.jsx("span",{className:"ms-cfd-lbl","aria-hidden":"true",children:c.customKind}),s.jsx(it,{className:"ms-cfd-kind",label:c.customKind,value:d.kind,disabled:P,describedBy:P?"ms-cfd-locked":void 0,onChange:U=>O({kind:U}),options:[{value:"image",label:c.customKindImage,icon:"image"},{value:"video",label:c.customKindVideo,icon:"video"}]}),s.jsxs("div",{className:"ms-cfd-size",children:[s.jsxs("div",{className:"ms-cfd-dim",children:[s.jsx("label",{htmlFor:"ms-cfd-w",children:c.customWidth}),s.jsxs("span",{className:"ms-cfd-px",children:[s.jsx(ms,{id:"ms-cfd-w",ref:k.width,inputMode:"numeric",value:d.width,disabled:P,onChange:U=>O({width:T(U.target.value)}),...de("width")}),s.jsx("span",{"aria-hidden":"true",children:c.customPx})]})]}),s.jsx("span",{className:"ms-cfd-x","aria-hidden":"true",children:"×"}),s.jsxs("div",{className:"ms-cfd-dim",children:[s.jsx("label",{htmlFor:"ms-cfd-h",children:c.customHeight}),s.jsxs("span",{className:"ms-cfd-px",children:[s.jsx(ms,{id:"ms-cfd-h",ref:k.height,inputMode:"numeric",value:d.height,disabled:P,onChange:U=>O({height:T(U.target.value)}),...de("height")}),s.jsx("span",{"aria-hidden":"true",children:c.customPx})]})]})]}),u.width?J("width"):J("height"),P?null:s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ms-cfd-ratios",role:"group","aria-labelledby":"ms-cfd-ratio-lbl","aria-describedby":"ms-cfd-ratio-hint",children:[s.jsx("span",{className:"ms-cfd-lbl",id:"ms-cfd-ratio-lbl",children:c.customRatio}),$F.map(U=>{const te=`${U[0]}:${U[1]}`;return s.jsx(sn,{on:L(U),title:c.customRatioAria({ratio:te}),onClick:()=>_(U),children:te},te)})]}),s.jsx("p",{className:"ms-cfd-hint",id:"ms-cfd-ratio-hint",children:c.customRatioHint})]}),W?s.jsxs(s.Fragment,{children:[s.jsx("label",{htmlFor:"ms-cfd-dur",children:c.customDuration}),s.jsxs("span",{className:"ms-cfd-px ms-cfd-dur",children:[s.jsx(ms,{id:"ms-cfd-dur",ref:k.duration,inputMode:"numeric",value:d.duration,onChange:U=>O({duration:T(U.target.value)}),...de("duration")}),s.jsx("span",{"aria-hidden":"true",children:c.customSecondsUnit})]}),s.jsxs("p",{className:"ms-cfd-hint",id:"ms-cfd-dur-hint",children:[c.customDurationHint,z>0?` ${c.customLongest({sec:z})}`:""]}),J("duration")]}):null,n&&y===null?s.jsx("p",{className:"ms-cfd-note",id:"ms-cfd-locked",role:"status",children:c.customUsageLoading}):null,n&&y==="failed"?s.jsxs("p",{className:"ms-cfd-note ms-cfd-note-row",id:"ms-cfd-locked",children:[s.jsx("span",{children:c.customUsageFailed}),s.jsx($,{size:"sm",variant:"outline",onClick:()=>S(U=>U+1),children:c.tryAgain})]}):null,C&&R>0?s.jsxs("div",{id:"ms-cfd-locked",className:"ms-cfd-notes",children:[C.creatives>0?s.jsx("p",{className:"ms-cfd-note",children:c.customInUse({count:C.creatives})}):null,C.unreadable>0?s.jsx("p",{className:"ms-cfd-note",children:c.customUnreadable({n:C.unreadable})}):null]}):null,p?s.jsx("p",{className:"ms-cfd-err",role:"alert",children:p}):null,b&&n?s.jsxs("div",{className:"ms-cfd-confirm",role:"group","aria-labelledby":"ms-cfd-ask",children:[s.jsx("p",{id:"ms-cfd-ask",children:c.customDeleteAsk({name:n.name})}),s.jsxs("div",{className:"ms-cfd-actions",children:[s.jsx($,{type:"button",variant:"ghost",autoFocus:!0,onClick:()=>{N.current=!0,v(!1)},disabled:f,children:o.common.cancel}),s.jsx($,{type:"button",variant:"danger",loading:f,onClick:()=>{I()},children:c.customDeleteConfirm})]})]}):s.jsxs("div",{className:"ms-cfd-actions",children:[n?s.jsx($,{ref:E,type:"button",variant:"ghost",className:"ms-cfd-delete",onClick:()=>v(!0),disabled:f,children:c.customDelete}):null,s.jsx("span",{className:"ms-grow"}),s.jsx($,{type:"button",variant:"ghost",onClick:t,disabled:f,children:o.common.cancel}),s.jsx($,{type:"submit",variant:"ink",loading:f,children:n?c.customSave:c.customCreate})]})]})})}const zp=yy,Xi=60,Op=["Instagram","TikTok","YouTube"],Dp=["App Store","Play Store"],DF=["teaser","feature","screenshots"],BF="appstore-iphone-69",UF=5,_F=6;function qF(e,t){let a=(e.trim().split(new RegExp("\\n|(?<=[.!?…])\\s"))[0]??"").replace(/\s+/g," ").trim();if(a.length>Xi){const r=a.slice(0,Xi),l=/[\p{L}\p{N}]/u.test(a[Xi])?r.lastIndexOf(" "):Xi;a=l>0?r.slice(0,l):r}return a=a.replace(/[\s.,;:!?…\-–—"'“”«»()]+$/u,""),a?a.charAt(0).toLocaleUpperCase()+a.slice(1):t}function Bb(e){return e>=120&&e%60===0?`≤ ${e/60} min`:`≤ ${e} s`}const Ub=(e,t)=>t?Ub(t,e%t):e,VF=[[1,1],[4,5],[5,4],[9,16],[16,9],[2,3],[3,2],[3,4],[4,3],[4,1],[1,4]];function KF(e,t){const n=Ub(e,t);if(e/n<=21&&t/n<=21)return`${e/n}:${t/n}`;const a=VF.find(([r,l])=>Math.abs(e/t/(r/l)-1)<.015);return a?`${a[0]}:${a[1]}`:`${e}×${t}`}function Bp(e,t){const n=(e.length-1)*t,a=Math.floor(n),r=Math.ceil(n);return e[a]+(e[r]-e[a])*(n-a)}const WF=3;function HF(e,t){if(e.length<WF)return null;const n=[...e].sort((u,h)=>u-h),a=Bp(n,.25),r=Bp(n,.75),l=r>=1e3,o=l&&r<1e4?1:0,c=u=>Vs(t,l?u/1e3:u,{minimumFractionDigits:o,maximumFractionDigits:o}),d=c(a),m=c(r);return`${d===m?d:`${d}–${m}`}${l?"k":""}`}function GF(e,t,n){const a={},r={},l={},o=[];for(const c of e){if(wy(c.id)>1){o.push(c);continue}const d=o.find(m=>kt(m.id)!==kt(c.id)&&vh(m,c,n).ok);if(d){if(r[c.id]=d.id,!t.has(c.id)){a[c.id]=d.id;continue}}else{const m=o.find(h=>h.width===c.width&&h.height===c.height),u=m?vh(m,c,n):null;m&&u&&!u.ok&&(l[c.id]={primary:m.id,reason:u.reason})}o.push(c)}return{links:a,candidates:r,blocked:l}}const Up=e=>e.split("/").pop()??e,XF=e=>`assets/${e}`;function ZF({slug:e,live:t}){const n=V(),a=n.web.newCreative,r=rs(),l=i.useContext(Mn),o=wF(e,t??l?.live,{onFormatUnavailable:()=>Ne(B=>B+1)}),c=l?.catalog.projects?.find(B=>B.slug===e)?.name??e,[d,m]=i.useState(""),[u,h]=i.useState(""),[f,x]=i.useState("6"),[p,g]=i.useState(""),[b,v]=i.useState([]),[y,w]=i.useState("all"),[j,S]=i.useState(""),[k,E]=i.useState(()=>new Set),[N,C]=i.useState([]),[R,P]=i.useState(""),[z,O]=i.useState([]),[T,W]=i.useState(void 0),Z=Sc(),A=Cc(),[L,_]=i.useState(!1),[X,ae]=i.useState(null),[K,I]=i.useState(null),[H,de]=i.useState(!1),[J,se]=i.useState(!1),[U,te]=i.useState(!1),[G,re]=i.useState({value:null,error:null,warning:null}),[oe,Ne]=i.useState(0),[Q,Re]=i.useState({value:null,error:null}),[Ue,is]=i.useState(0),[Qe,gs]=i.useState({value:null,error:null}),[As,hs]=i.useState(!1),[Oe,be]=i.useState(!1),[Fe,je]=i.useState(!1),he=i.useRef(0),Ke=i.useRef(null),we=EF(e,{onLibraryChanged:()=>is(B=>B+1)}),ze=we.setRefs,[We,Rs]=i.useState(!1),[us,fs]=i.useState({open:!1,editing:null}),[fe,Ge]=i.useState(null),[De,os]=i.useState(void 0),[Ze,vs]=i.useState(void 0),[Le,ne]=i.useState([]),[Ee,Ce]=i.useState([]),[Xe,ue]=i.useState(()=>new Set),[xe,Be]=i.useState(()=>new Set),[_e,ge]=i.useState(null),[qe,Ye]=i.useState("you"),[Ls,et]=i.useState(void 0),bs=i.useRef(null),Us=i.useRef(null),Me=Zn({name:"new-creative",slug:e}),ss=Tc(Me,!l?.route||Zn(l.route)===Me),Ie=i.useRef(null),ys=i.useRef(null),ns=i.useRef(null),Ys=i.useRef(null);i.useEffect(()=>{let B=!0;return Promise.resolve().then(()=>q.getFormats()).then(ye=>{B&&re({value:ye.presets,error:null,warning:ye.error})}).catch(ye=>{B&&re(He=>He.value?He:{value:null,error:pe(ye),warning:null})}),()=>{B=!1}},[oe]),i.useEffect(()=>{let B=!0;return Promise.resolve().then(()=>q.listAssets(e)).then(ye=>{B&&(Re({value:ye.assets,error:ye.error}),ze(ye.creativeReferences??[]))}).catch(ye=>{B&&Re({value:null,error:pe(ye)})}),()=>{B=!1}},[e,Ue,ze]),i.useEffect(()=>{let B=!0;return Promise.resolve().then(()=>q.getBrand(e)).then(ye=>{B&&gs({value:ye.kit,error:ye.kitError})}).catch(ye=>{B&&gs({value:null,error:pe(ye)})}),()=>{B=!1}},[e]),i.useEffect(()=>{let B=!0;return Promise.resolve().then(()=>q.getFirstGenerations()).then(ye=>{B&&Array.isArray(ye?.tokens)&&Ce(ye.tokens.filter(He=>Number.isFinite(He)&&He>0))}).catch(()=>{}),()=>{B=!1}},[]);const mt=HF(Ee,r);cN(e,i.useCallback(B=>{C(ye=>[...ye,...B.filter(He=>!ye.includes(He))]),xa.current("assets")},[]));const Ns=i.useMemo(()=>(G.value??[]).filter(B=>!B.hidden),[G.value]),ct=i.useMemo(()=>b.flatMap(B=>{const ye=Zi(Ns,B);return ye?[ye]:[]}),[b,Ns]),ls=ct.filter(B=>B.kind==="video"),Is=Number(f==="custom"?p:f),Hs=Number.isInteger(Is)&&Is>=1&&Is<=600,[ee,as]=i.useState(()=>new Set),ds=i.useMemo(()=>GF(ct,ee,Hs?Is:void 0),[ct,ee,Hs,Is]),Ks=B=>as(ye=>{const He=new Set(ye);return He.has(B)?He.delete(B):He.add(B),He}),tt=B=>{const ye=Ns.find(He=>He.id===kt(B));return ye?nx(B,Dd(ye,r)):B},js=ls.find(B=>B.maxDurationSec!==void 0&&Hs&&Is>B.maxDurationSec)??null,Ds=i.useMemo(()=>jy([d,u,R].join(`
|
|
25
|
+
`)),[d,u,R]),ht=ls.length>0&&Ds!==null&&(!Hs||Ds!==Is)?Ds:null,un=B=>{Xs("durationSec");const ye=ku.find(He=>He!=="custom"&&Number(He)===B);ye?x(ye):(x("custom"),g(String(B))),te(!1)},Os=qF(d,a.untitled),gt=j.trim().toLocaleLowerCase(),mn=B=>(y==="all"||B.kind===y)&&(!gt||`${Dn(B.channel,r)} ${Su(B,r)} ${B.channel} ${B.name}`.toLocaleLowerCase().includes(gt)),Wt=i.useMemo(()=>[...new Set([...Ns.map(B=>Ar(B.channel)),wi])],[Ns]),$n=Wt.some(B=>Op.includes(B))?Wt.filter(B=>Op.includes(B)):Wt.slice(0,3),gn=!gt||`${n.web.storePack.entryTitle} ${n.web.storePack.entryHint} ${n.web.storePack.title}`.toLocaleLowerCase().includes(gt),zt=B=>Dp.includes(B)&&gn,Mt=B=>B===wi&&(!gt||`${a.customTile} ${a.customTileHint} ${Dn(wi,r)}`.toLocaleLowerCase().includes(gt)),Yn=B=>gt!==""||B===wi||$n.includes(B)||k.has(B)||Ns.some(ye=>Ar(ye.channel)===B&&b.includes(ye.id))||fe!==null&&Dp.includes(B),vt=Wt.map(B=>({g:B,items:Ns.filter(ye=>Ar(ye.channel)===B&&mn(ye))})).filter(({g:B,items:ye})=>Yn(B)&&(ye.length>0||zt(B)||Mt(B))),St=gt?[]:Wt.filter(B=>!Yn(B)),an=b.filter(B=>{const ye=Ns.find(He=>He.id===kt(B));return ye!==void 0&&!mn(ye)}).length,Zt=Ra([G.value!==null]),$t=B=>{Xs("formats"),se(!1),v(ye=>ye.includes(B)?ye.filter(He=>kt(He)!==B):[...ye,B])},rn=(B,ye)=>{Xs("formats"),v(He=>{const _s=He.findIndex(Ss=>kt(Ss)===B);if(_s===-1)return He;const $s=He.filter(Ss=>kt(Ss)!==B);return $s.splice(_s,0,...Array.from({length:Math.min(Bd,Math.max(1,ye))},(Ss,Ft)=>ky(B,Ft+1))),$s})},Jt=B=>b.filter(ye=>kt(ye)===B).length,[hn,D]=i.useState(0),Ae=i.useRef(null);i.useEffect(()=>{if(G.value===null)return;const B=b.filter(He=>!Zi(Ns,He));if(B.length===0)return;const ye=B.join(`
|
|
26
|
+
`);if(Ae.current?.key!==ye){Ae.current={key:ye,catalog:G},Ne(He=>He+1);return}Ae.current.catalog!==G&&(D(B.length),Xs("formats"),v(He=>He.filter(_s=>Zi(Ns,_s))))},[G,Ns,b]);const ts=(B,ye,He)=>{re({value:ye.presets,error:null,warning:ye.error}),fs(_s=>({..._s,open:!1})),He&&(Xs("formats"),se(!1),v(_s=>_s.includes(B.id)?_s:[..._s,B.id]),Pe.show(a.customAdded({name:B.name}),{tone:"ok"}))},ps=(B,ye,He)=>{re({value:He.presets,error:null,warning:He.error}),fs(_s=>({..._s,open:!1})),b.some(_s=>kt(_s)===B.id)&&(Xs("formats"),v(_s=>_s.filter($s=>kt($s)!==B.id))),Pe.show(ye==="hidden"?a.customHidden({name:B.name}):a.customDeleted({name:B.name}),{tone:"ok"})},Cs=B=>{if(Xs("goal"),m(a.suggestions[B].text),de(!1),B==="screenshots"){const ye=Ns.find(He=>He.id===BF);ye&&(Xs("formats"),v([ye.id]),E(He=>new Set([...He,ye.channel])),se(!1))}Yi(ys.current)},ks=B=>{Xs("assets"),C(ye=>ye.includes(B)?ye.filter(He=>He!==B):[...ye,B])},Ms=B=>{Ys.current=B,hs(!0)},Bt=B=>{Ys.current=B,be(!0)},bt=async B=>{const{paths:ye}=await we.upload(B);ye.length!==0&&(Xs("assets"),C(He=>[...He,...ye.filter(_s=>!He.includes(_s))]))},nt=B=>Array.from(B.dataTransfer?.types??[]).includes("Files"),fn={onDragEnter:B=>{nt(B)&&(B.preventDefault(),he.current+=1,je(!0))},onDragOver:B=>{nt(B)&&B.preventDefault()},onDragLeave:B=>{nt(B)&&(he.current=Math.max(0,he.current-1),he.current===0&&je(!1))},onDrop:B=>{nt(B)&&(B.preventDefault(),he.current=0,je(!1),bt(Array.from(B.dataTransfer.files)))}},Nn=i.useRef(!1),Vn=async B=>{if(!(Nn.current||Ot)&&!vn&&!Sn){if(!d.trim()){de(!0),Ie.current?.focus(),Yi(ys.current);return}if(ct.length===0&&!fe){se(!0),Yi(ns.current);return}if(ls.length>0&&!Hs){te(!0);return}Nn.current=!0,ae(B?"generate":"draft"),I(null);try{const ye=L0(_t,Le),He=ye.some(Ft=>Ft!==null),_s=_t>1,$s=await q.createCreative(e,{title:Os,brief:{goal:d.trim(),message:u.trim(),formats:[...Qn,...Ut.formats],durationSec:ls.length>0?Is:Ut.durationSec,assets:[...N,...Ut.assets.filter(Ft=>!N.includes(Ft))],notes:R.trim(),links:ds.links,...Object.keys(Ut.formatLabels).length>0?{formatLabels:Ut.formatLabels}:{},...fe?{storePack:Ut.pack}:{},...T?{services:T}:{},...Ct?{identity:{...Mv(De,ha),concepts:_t}}:{}},generate:B&&(!_s||Fn&&!He),linkedCodebases:z,...at&&o.session?{briefSession:{id:o.session.id,group:_t>1}}:{}});$s.briefError&&(Pe.show($s.briefError,{tone:"neutral"}),o.refresh());let Ss=$s.groupError?ea.groupFailed({detail:$s.groupError}):$s.startError?ea.startFailed({detail:$s.startError}):null;if(_s&&!(Fn&&!He)&&!$s.groupError)try{if(Fn)for(const[Ft,Sr]of ye.entries())Sr!==null&&await q.setVariantDirection(e,$s.slug,bx(Ft),Sr);else await q.addVariants(e,$s.slug,{count:_t,directions:ye});B&&await q.runVariants(e,$s.slug,{targets:"all-active",request:null}).catch(Ft=>{Ss=ea.startFailed({detail:pe(Ft)})})}catch(Ft){Ss=ea.groupFailed({detail:pe(Ft)})}Ss&&Pe.show(Ss,{tone:"neutral"}),B?(qe==="agent"&&Us.current&&(Hl(`brief-panel:${e}/${$s.slug}`,Us.current.getBoundingClientRect()),Fx(bs.current,qs.m)),Bs(es.creative(e,$s.slug))):(Pe.show(a.draftSaved({title:Os}),{tone:"ok",action:{label:a.open,run:()=>Bs(es.creative(e,$s.slug))}}),Bs(es.project(e)))}catch(ye){Nn.current=!1,ae(null),ye instanceof lt&&ye.code==="format-unavailable"&&Ne(He=>He+1),o.report(ye),I(ye?.code==="brief-session-gone"?n.web.briefSession.goneOnCreate:pe(ye))}}};qt(Zt,dc,()=>{Vn(!0)});const jt=Qe.value,ha=(jt?.logos.length??0)>0,Ct=ct.some(B=>B.identity),vn=Ct&&De===void 0&&Qe.value===null&&Qe.error===null,ln=Tm(De,ha),Kn=ct,Qn=Kn.map(B=>B.id),Ut=kE(fe,Ns,Qn),fa=i.useMemo(()=>{const B=new Map;if(fe)for(const ye of Rl(fe,Ns).formats)B.set(kt(ye),(B.get(kt(ye))??0)+1);return B},[fe,Ns]),Sn=Ut.full?tt(Ut.full):null,pa=Ut.formats.length,Fn=Ct&&ln.start==="scratch",_t=Ze??A0([...Qn,...Ut.formats],Fn),ea=n.web.variantGroup,Wn=Kn.filter(B=>B.kind==="video").length+Ut.videos,Fa=Kn.filter(B=>B.kind==="image").length+Ut.images,dt=a.summary({formats:Kn.length+pa,videos:Wn,images:Fa}),ya=!!jt&&(jt.colors.length>0||jt.fonts.length>0||jt.logos.length>0||jt.tone!==null),Hn=jt?[jt.fonts[0]?.family,jt.colors[0]?.name,jt.tone?.text].filter(Boolean).join(" · "):"",Cn=B=>we.entryOf(B,Q.value),Pn=B=>{const ye=Cn(B);return!ye||!(ql(ye)||we.here.has(B))?null:s.jsx(Db,{path:B,reference:ql(ye),busy:we.busy.has(ye.file),onToggle:()=>{we.toggle(ye)}})},Lt=xF({goal:d,message:u,length:f,customSec:p,picked:N,codebases:z,notes:R,selected:b,variantCount:_t}),Es=i.useRef(Lt);Es.current=Lt;const st=i.useRef(Xe);st.current=Xe;const sa=i.useRef(0),Yt=i.useRef(new Set),An=i.useRef(new Set),wa=()=>new Set([...Yt.current,...An.current]),ut=i.useRef(!1),Gn=()=>[...st.current].filter(B=>!(ut.current&&B==="goal")),Qt=i.useCallback(()=>(An.current=new Set([...An.current,...Yt.current]),Yt.current=new Set,{form:Es.current,userEdited:Gn(),baseRevision:sa.current}),[]),En=i.useCallback(B=>{B||(Yt.current=new Set([...Yt.current,...An.current])),An.current=new Set},[]),at=o.session!==null&&_e===!0,Xs=B=>{Yt.current.add(B),B==="goal"&&(ut.current=!1),ue(ye=>ye.has(B)?ye:new Set(ye).add(B)),Be(ye=>{if(!ye.has(B))return ye;const He=new Set(ye);return He.delete(B),He}),at&&o.saveForm(Qt,En)},xa=i.useRef(Xs);xa.current=Xs,i.useEffect(()=>{if(_e!==null||o.status==="loading"||o.status==="failed")return;const B=o.session,ye=o.entries.some(He=>He.type==="user");!B||!ye||o.job?.state==="running"||o.job?.state==="queued"?ge(!0):ge(!1)},[_e,o.status,o.session,o.entries,o.job]);const ta=i.useRef(0),[bn,ka]=i.useState(null);i.useEffect(()=>{const B=o.session;if(!B||_e!==!0)return;const ye=o.lastFill&&o.lastFill.seq>ta.current?o.lastFill:null;ye&&(ta.current=ye.seq);const He=Es.current,_s=bF({form:He,userEdited:st.current,pending:wa()},B,ye?.reclaimed??[]);for(const $s of _s.taken)Yt.current.delete($s);if(ut.current&&(B.userEdited.includes("goal")?(_s.userEdited.delete("goal"),o.saveForm(Qt,En)):ut.current=!1),lr(_s.form,_s.changed),ue(_s.userEdited),Be(_s.agentFields),sa.current=B.revision,ye){const $s=[...ye.written,...ye.reclaimed].filter(Ss=>_s.taken.includes(Ss));ka({seq:ye.seq,glow:$s.filter(Ss=>Ss!=="assets"&&Ss!=="formats"),assets:$s.includes("assets")?_s.form.assets.filter(Ss=>!He.assets.includes(Ss)):[],formats:$s.includes("formats")?_s.form.formats.filter(Ss=>!He.formats.includes(Ss)):[]})}},[o.session,_e]);function lr(B,ye){for(const He of ye)if(He==="goal")m(B.goal);else if(He==="message")h(B.message);else if(He==="notes")P(B.notes),B.notes&&_(!0);else if(He==="durationSec"){const _s=gF(B.durationSec);x(_s.length),g(_s.customSec),te(!1)}else He==="assets"?C(B.assets):He==="linkedCodebases"?(O(B.linkedCodebases),B.linkedCodebases.length&&_(!0)):He==="formats"?(v(B.formats),B.formats.length&&se(!1)):He==="variants"&&vs(B.variants);ye.includes("goal")&&B.goal.trim()&&de(!1)}i.useEffect(()=>{if(!bn||!Zt.current)return;const B=Zt.current,ye={goal:ys.current,message:B.querySelector("#ms-nc-msg"),durationSec:B.querySelector(".ms-nc-len"),notes:B.querySelector("#ms-nc-notes"),linkedCodebases:B.querySelector('[data-brief-field="linkedCodebases"]'),variants:B.querySelector(".ms-nc-variants")};for(const $s of bn.glow)Gy(ye[$s]??null);const He=($s,Ss)=>[...B.querySelectorAll(`[data-${$s}]`)].find(Ft=>Ft.dataset[$s]===Ss)??null;[...bn.assets.map($s=>He("asset",$s)),...[...new Set(bn.formats.map(kt))].map($s=>He("format",$s))].forEach(($s,Ss)=>{Xy($s,Ss*90)})},[bn]);const Ot=o.job?.state==="queued"||o.job?.state==="running",na=i.useRef(!1);i.useEffect(()=>{_e===!0&&!na.current&&o.session&&Ot&&(na.current=!0,Ye("agent"))},[_e,o.session,Ot]);const Na=()=>{if(Ye("agent"),!d.trim()){Et();return}et(B=>({text:d.trim(),nonce:(B?.nonce??0)+1})),m(""),Yt.current.delete("goal"),ue(B=>{if(!B.has("goal"))return B;const ye=new Set(B);return ye.delete("goal"),ye}),Et(),Ws()},Ws=async()=>{const B=o.session;if(!B||_e!==!0||!B.form.goal)return;const ye=()=>[...st.current].filter($s=>$s!=="goal");let He=sa.current;if(!B.userEdited.includes("goal")){const $s=await o.saveNow(()=>({form:{...Es.current,goal:""},userEdited:[...ye(),"goal"],baseRevision:He}));if(!$s)return;He=$s.revision}ut.current=!0,await o.saveNow(()=>({form:{...Es.current,goal:""},userEdited:ye(),baseRevision:He}))||o.saveForm(Qt,En)},Et=()=>{setTimeout(()=>Us.current?.querySelector("textarea")?.focus(),0)},ie=()=>{ge(!0),Ye("agent")},ke=async()=>{try{await o.discard()}catch(B){I(pe(B));return}ge(!0),Ye("you")},cs=i.useCallback(()=>Qt(),[Qt]),Ps=Xu(e,t??l?.live??Nm),ft=new Set([...N,...o.session?.context.assets??[]]),Tn=Ps.pending.filter(B=>ft.has(B.file)),ir=Jg(),qa=Tn.map(B=>B.file).join(`
|
|
27
|
+
`);i.useEffect(()=>qe==="agent"&&qa?ir.claim(e,qa.split(`
|
|
28
|
+
`)):void 0,[qe,qa,e,ir]);const aa=B=>xe.has(B)?s.jsx(Qs,{tone:"accent",className:"ms-nc-agentmark",children:n.web.briefSession.agentMark}):null;return s.jsxs("div",{className:le("ms-nc",qe==="agent"&&"ms-nc-agent"),ref:Zt,children:[ss?.end?ma.createPortal(s.jsx(it,{className:"ms-nc-mode",label:n.web.briefSession.modeLabel,value:qe,onChange:B=>Ye(B==="agent"?"agent":"you"),options:[{value:"you",label:n.web.briefSession.modeYou},{value:"agent",label:n.web.briefSession.modeAgent,icon:"sparkle"}]}),ss.end):null,s.jsx(RF,{slug:e,projectName:c,brief:o,live:t??l?.live,snapshot:cs,onCarried:En,draft:Ls,library:Q,onRetryLibrary:()=>{Re({value:null,error:null}),is(B=>B+1)},onLibraryChanged:()=>is(B=>B+1),references:we,hidden:qe!=="agent",panelRef:Us,className:"ms-nc-panel",onOpenCreative:B=>Bs(es.creative(e,B)),analysisQuestions:Tn}),s.jsxs("div",{className:"ms-nc-form",ref:bs,children:[s.jsxs("div",{className:"ms-nc-body",children:[s.jsxs("div",{className:"ms-nc-left",children:[s.jsxs("section",{className:"ms-nc-sec ms-nc-brief","data-enter":!0,children:[s.jsxs("div",{className:"ms-nc-qrow",children:[s.jsx("label",{htmlFor:"ms-nc-goal",className:"ms-nc-q",children:a.goalQuestion}),aa("goal")]}),s.jsxs("div",{ref:ys,className:le("ms-nc-goalbox",H&&"ms-invalid"),children:[s.jsx("textarea",{id:"ms-nc-goal",ref:Ie,rows:4,maxLength:zp,value:d,placeholder:a.goalPlaceholder,"aria-invalid":H||void 0,"aria-describedby":H?"ms-nc-goal-err":void 0,onChange:B=>{Xs("goal"),m(B.target.value),B.target.value.trim()&&de(!1)}}),s.jsxs("div",{className:"ms-nc-goalbar",children:[ya?s.jsxs(sn,{className:"ms-nc-kit",children:[s.jsx("span",{className:"ms-nc-mono","aria-hidden":"true",children:ai(c)}),a.brandKit]}):null,N.length>0?s.jsxs(sn,{className:"ms-nc-kit",children:[s.jsx(cu,{slug:e,path:N[0],entry:Cn(N[0]),small:!0}),a.assetCount({count:N.length})]}):null,s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":a.addAssets,title:a.addAssets,"aria-haspopup":"menu",onClick:B=>Bt(B.currentTarget),children:s.jsx(F,{name:"plus",size:14})}),qe==="you"?s.jsxs("button",{type:"button",className:"ms-chip ms-nc-cta",onClick:Na,children:[s.jsx(F,{name:"sparkle",size:13,fill:!0}),n.web.briefSession.cta]}):null,s.jsx("span",{className:"ms-nc-count",children:a.goalCount({n:d.length,max:zp})})]})]}),H?s.jsxs("p",{id:"ms-nc-goal-err",className:"ms-nc-err",children:[s.jsx(F,{name:"warn",size:13}),a.goalRequired]}):null,d.trim()?s.jsxs("p",{className:"ms-nc-title",children:[s.jsxs("span",{children:[a.title,":"]})," ",s.jsx("b",{children:Os})," ",s.jsxs("span",{className:"ms-nc-faint",children:["· ",a.titleHint]})]}):null,s.jsxs("div",{className:"ms-nc-try",children:[s.jsx("span",{className:"ms-nc-faint",children:a.tryLabel}),DF.map(B=>s.jsx(sn,{onClick:()=>Cs(B),children:a.suggestions[B].label},B))]})]}),s.jsxs("section",{className:"ms-nc-sec","data-enter":!0,children:[s.jsxs("div",{className:"ms-nc-qrow",children:[s.jsxs("label",{className:"ms-nc-lbl",htmlFor:"ms-nc-msg",children:[a.keyMessage," ",s.jsx("span",{className:"ms-nc-faint",children:a.keyMessageHint})]}),aa("message")]}),s.jsx(ms,{id:"ms-nc-msg",className:"ms-nc-msg",value:u,onChange:B=>{Xs("message"),h(B.target.value)}})]}),s.jsxs("div",{className:le("ms-nc-sec",ls.length===0&&"ms-nc-off"),"data-enter":!0,children:[s.jsxs("div",{className:"ms-nc-row",children:[s.jsxs("span",{className:"ms-nc-qrow",children:[s.jsx("span",{className:"ms-nc-lbl",children:a.videoLength}),aa("durationSec")]}),s.jsx("span",{id:"ms-nc-len-why",className:"ms-nc-faint ms-nc-small",children:ls.length?a.lengthFor({count:ls.length}):a.noVideo})]}),s.jsx(it,{className:"ms-nc-len",label:a.videoLength,disabled:ls.length===0,describedBy:"ms-nc-len-why",value:f,onChange:B=>{Xs("durationSec"),x(B),te(!1)},options:ku.map(B=>({value:B,label:B==="custom"?a.custom:a.secondsShort({n:Number(B)})}))}),f==="custom"&&ls.length>0?s.jsx(ms,{className:"ms-nc-custom",inputMode:"numeric","aria-label":a.customSeconds,placeholder:a.customSeconds,value:p,"aria-invalid":U||void 0,onChange:B=>{Xs("durationSec"),g(B.target.value.replace(/\D/g,"").slice(0,3)),te(!1)}}):null,U?s.jsxs("p",{className:"ms-nc-err",children:[s.jsx(F,{name:"warn",size:13}),a.customInvalid]}):null,ht!==null?s.jsxs("p",{className:"ms-nc-note ms-nc-stated",role:"status",children:[s.jsx(F,{name:"clock",size:13}),s.jsx("span",{children:Hs?a.durationMismatch({stated:ht,current:Is}):a.durationMismatchUnset({stated:ht})}),s.jsx($,{size:"sm",variant:"outline",onClick:()=>un(ht),children:a.durationUse({n:ht})})]}):null,js&&js.maxDurationSec?s.jsxs("p",{className:"ms-nc-note",children:[s.jsx(F,{name:"clock",size:13}),a.overMax({label:Dd(js,r),max:Bb(js.maxDurationSec)})]}):null]}),s.jsxs("section",{className:le("ms-nc-sec ms-nc-assetsec",Fe&&"ms-dropping"),"data-enter":!0,...fn,children:[s.jsxs("div",{className:"ms-nc-row",children:[s.jsxs("span",{className:"ms-nc-qrow",children:[s.jsx("span",{className:"ms-nc-lbl",id:"ms-nc-assets-lbl",children:a.assetsToUse}),aa("assets")]}),s.jsxs("span",{className:"ms-nc-assetbtns",children:[s.jsx($,{size:"sm",variant:"ghost",className:"ms-nc-browse",onClick:()=>Ke.current?.click(),children:a.fromComputer}),s.jsx($,{size:"sm",variant:"ghost",className:"ms-nc-browse",onClick:B=>Ms(B.currentTarget),children:a.browse})]})]}),s.jsx("input",{ref:Ke,type:"file",multiple:!0,hidden:!0,"aria-label":a.uploadInput,onChange:B=>{const ye=Array.from(B.target.files??[]);B.target.value="",bt(ye)}}),s.jsxs("div",{className:"ms-nc-assets",role:"list","aria-labelledby":"ms-nc-assets-lbl",children:[N.map(B=>{const ye=Pn(B);return s.jsxs("div",{role:"listitem",className:le("ms-nc-asset-item",ye&&"ms-nc-asset-col"),"data-asset":B,children:[s.jsxs("button",{type:"button",className:"ms-nc-asset ms-on","aria-label":a.removeAsset({name:Up(B)}),title:a.removeAsset({name:Up(B)}),onClick:()=>ks(B),children:[s.jsx(cu,{slug:e,path:B,entry:Cn(B)}),s.jsx("span",{className:"ms-nc-tick","aria-hidden":"true",children:s.jsx(F,{name:"check",size:10,strokeWidth:2.4})})]}),ye]},B)}),we.pending.flatMap(B=>B.names.map((ye,He)=>s.jsx("div",{role:"listitem",className:"ms-nc-asset-item ms-nc-asset-col",children:B.error===null?s.jsxs("span",{className:"ms-nc-asset ms-nc-uploading",role:"status","aria-label":a.uploadingAsset({name:ye}),title:a.uploadingAsset({name:ye}),children:[s.jsx(Ts,{size:16,decorative:!0}),s.jsx("span",{className:"ms-nc-upname",children:ye})]}):s.jsxs("span",{className:"ms-nc-asset ms-nc-upfailed",title:a.uploadAssetFailed({name:ye,detail:B.error}),children:[s.jsx(F,{name:"warn",size:16}),s.jsx("span",{className:"ms-nc-upname",children:ye})]})},`${B.id}:${He}`))),s.jsx("div",{role:"listitem",className:"ms-nc-asset-item",children:s.jsx("button",{type:"button",className:"ms-nc-asset ms-nc-add","aria-label":a.addAssets,title:a.addAssets,"aria-haspopup":"menu",onClick:B=>Bt(B.currentTarget),children:s.jsx(F,{name:"plus",size:16})})})]}),we.pending.filter(B=>B.error!==null).map(B=>s.jsxs("p",{className:"ms-nc-err ms-nc-uperr",role:"alert",children:[s.jsx(F,{name:"warn",size:13}),s.jsx("span",{children:B.names.map(ye=>a.uploadAssetFailed({name:ye,detail:B.error})).join(" · ")}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":a.dismissUpload({name:B.names.join(", ")}),title:a.dismissUpload({name:B.names.join(", ")}),onClick:()=>we.dismiss(B.id),children:s.jsx(F,{name:"close",size:11})})]},B.id)),s.jsx("span",{className:"ms-nc-faint ms-nc-small",children:a.brandAuto}),Fe?s.jsxs("div",{className:"ms-nc-dropzone","aria-hidden":"true",children:[s.jsx(F,{name:"upload",size:16}),s.jsx("span",{children:a.dropHere})]}):null]}),s.jsx("section",{className:"ms-nc-sec","data-enter":!0,children:Qe.value===null&&Qe.error===null?null:ya&&jt?s.jsxs("div",{className:"ms-nc-brand",children:[s.jsx("div",{className:"ms-nc-swatches","aria-hidden":"true",children:jt.colors.slice(0,4).map(B=>s.jsx("span",{style:{background:B.hex}},B.id))}),s.jsxs("div",{className:"ms-nc-brand-text",children:[s.jsx("b",{children:a.followsBrand({project:c})}),Hn?s.jsx("span",{className:"ms-nc-ell",title:Hn,children:Hn}):null]}),s.jsx("a",{className:"ms-link ms-nc-editbrand",href:es.project(e,"brand"),children:a.editBrand})]}):s.jsxs("div",{className:"ms-nc-brand ms-nc-nobrand",children:[s.jsx("span",{className:"ms-nc-brand-icon","aria-hidden":"true",children:s.jsx(F,{name:"drop",size:14})}),s.jsxs("div",{className:"ms-nc-brand-text",children:[s.jsx("b",{children:Qe.error?a.brandFailed({detail:Qe.error}):a.noBrand}),s.jsx("span",{className:"ms-nc-wrap",children:a.noBrandBody})]}),s.jsx($,{size:"sm",variant:"outline",onClick:()=>Bs(es.project(e,"brand")),children:a.setUpBrand})]})}),Ct?s.jsx("section",{className:"ms-nc-sec","data-enter":!0,children:s.jsx(Fv,{value:{...ln,concepts:_t},onChange:B=>{os(B),B.concepts!==void 0&&B.concepts!==_t&&(Xs("variants"),vs(B.concepts))},hasBrandLogo:ha,fromCodebase:$v(jt?.logos??[])?.source.kind==="codebase",withConcepts:!0})}):null,Fn?_t>=2?s.jsx("section",{className:"ms-nc-sec","data-enter":!0,children:s.jsx(Pp,{count:_t,directions:Le,onDirections:ne})}):null:s.jsx("section",{className:"ms-nc-sec","data-enter":!0,children:s.jsx(Pp,{count:_t,onCount:B=>{Xs("variants"),vs(B)},directions:Le,onDirections:ne})}),s.jsxs("section",{className:"ms-nc-sec ms-nc-options","data-enter":!0,children:[s.jsxs("button",{type:"button",className:"ms-nc-disclose","aria-expanded":L,"aria-controls":"ms-nc-options",onClick:()=>_(B=>!B),children:[s.jsx(F,{name:L?"chevron":"forward",size:13}),a.moreOptions]}),L?s.jsxs("div",{id:"ms-nc-options",className:"ms-nc-options-body",children:[s.jsxs("div",{className:"ms-nc-qrow",children:[s.jsxs("label",{className:"ms-nc-lbl",htmlFor:"ms-nc-notes",children:[a.notesForAgent," ",s.jsx("span",{className:"ms-nc-faint",children:a.optional})]}),aa("notes")]}),s.jsx(ms,{id:"ms-nc-notes",value:R,onChange:B=>{Xs("notes"),P(B.target.value)}}),s.jsxs("div",{className:"ms-nc-qrow",children:[s.jsxs("span",{className:"ms-nc-lbl",children:[a.codebases," ",s.jsx("span",{className:"ms-nc-faint",children:a.codebasesHint})]}),aa("linkedCodebases")]}),s.jsx("div",{"data-brief-field":"linkedCodebases",children:s.jsx(Pv,{value:z,onChange:B=>{Xs("linkedCodebases"),O(B)}})}),s.jsxs("span",{className:"ms-nc-lbl",children:[n.web.services.title," ",s.jsx("span",{className:"ms-nc-faint",children:n.web.services.hint})]}),s.jsx(Sm,{value:T,configured:Z,checks:A,onChange:W})]}):null]})]}),s.jsxs("div",{className:"ms-nc-right",children:[s.jsxs("div",{className:"ms-nc-boardhead",ref:ns,children:[s.jsxs("div",{className:"ms-nc-qrow ms-nc-boardtitle",children:[s.jsx("h2",{children:a.whereTo}),aa("formats")]}),s.jsx("div",{className:"ms-grow"}),s.jsx(it,{className:"ms-nc-kind",label:a.formatKind,value:y,onChange:w,options:[{value:"all",label:a.kindAll},{value:"video",label:a.kindVideo,icon:"video"},{value:"image",label:a.kindImage,icon:"image"}]}),s.jsxs("label",{className:"ms-nc-search",children:[s.jsx(F,{name:"search",size:14}),s.jsx("input",{type:"search",value:j,onChange:B=>S(B.target.value),placeholder:a.searchFormats,"aria-label":a.searchFormats})]})]}),hn>0?s.jsx("p",{className:"ms-nc-faint ms-nc-small ms-nc-hidden-note",role:"status",children:a.formatsDropped({n:hn})}):null,an>0?s.jsx("p",{className:"ms-nc-faint ms-nc-small ms-nc-hidden-note",role:"status",children:a.hiddenChosen({n:an})}):null,G.warning?s.jsxs("p",{className:"ms-nc-alert",role:"status",children:[s.jsx(F,{name:"warn",size:14}),s.jsx("span",{children:G.warning})]}):null,G.error?s.jsxs("div",{className:"ms-nc-alert",role:"alert",children:[s.jsx(F,{name:"warn",size:14}),s.jsx("span",{children:a.formatsFailed({detail:G.error})}),s.jsx($,{size:"sm",variant:"outline",onClick:()=>{re({value:null,error:null,warning:null}),Ne(B=>B+1)},children:a.tryAgain})]}):null,G.value===null&&!G.error?s.jsxs("div",{className:"ms-nc-group","aria-busy":"true",children:[s.jsx("span",{className:"ms-sr",role:"status",children:a.formatsLoading}),s.jsx("div",{className:"ms-nc-tiles",children:[0,1,2,3,4,5].map(B=>s.jsx("div",{className:"ms-nc-tile ms-nc-skel","aria-hidden":"true"},B))})]}):null,G.value!==null&&vt.length===0?s.jsx(Rt,{icon:"search",title:a.noMatch,sub:a.noMatchBody,action:s.jsx($,{size:"sm",variant:"outline",onClick:()=>{S(""),w("all")},children:a.showAllFormats})}):null,vt.length?s.jsx("div",{className:"ms-nc-groups",children:vt.map(({g:B,items:ye})=>{const He=ye.filter(Ss=>b.includes(Ss.id)).length,_s=b.filter(Ss=>ye.some(Ft=>Ft.id===kt(Ss))).length,$s=Dn(B,r);return s.jsxs("div",{className:"ms-nc-group",role:"group","aria-label":$s,"data-enter":!0,style:{"--cols":Math.min(ye.length+(zt(B)?1:0)+(Mt(B)?1:0),_F)},children:[s.jsxs("div",{className:"ms-nc-ghead",children:[s.jsx(en,{channel:da(B),size:20}),s.jsx("b",{className:"ms-nc-ell",children:$s}),He?(()=>{const Ss=`${a.selectedCount({n:He})}${_s>He?` · ${a.copiesTotal({n:_s})}`:""}`;return s.jsx("span",{className:"ms-nc-faint ms-nc-small ms-nc-gcount",title:Ss,children:Ss})})():null]}),s.jsxs("div",{className:"ms-nc-tiles",children:[zt(B)?s.jsx(YF,{pack:fe,onOpen:()=>Rs(!0),onRemove:()=>Ge(null)}):null,Mt(B)?s.jsx(QF,{onOpen:()=>fs({open:!0,editing:null})}):null,ye.map(Ss=>s.jsx(eP,{preset:Ss,on:b.includes(Ss.id),onClick:()=>$t(Ss.id),onEdit:yx(Ss)?()=>fs({open:!0,editing:Ss}):null,copies:b.includes(Ss.id)&&!Ss.identity?{n:Jt(Ss.id),packTaken:fa.get(Ss.id)??0,onChange:Ft=>rn(Ss.id,Ft)}:null,link:b.includes(Ss.id)&&ds.candidates[Ss.id]?{primary:tt(ds.candidates[Ss.id]),on:!ee.has(Ss.id),onToggle:()=>Ks(Ss.id)}:null,blocked:b.includes(Ss.id)&&ds.blocked[Ss.id]?{primary:tt(ds.blocked[Ss.id].primary),reason:n.errors.followReason[ds.blocked[Ss.id].reason]}:null},Ss.id))]})]},B)})}):null,G.value!==null&&St.length>0?s.jsxs("div",{className:"ms-nc-more","data-enter":!0,children:[s.jsx("span",{className:"ms-nc-lbl ms-nc-muted",children:a.moreChannels}),s.jsx("div",{className:"ms-nc-more-list",children:St.map(B=>s.jsxs($,{variant:"outline",className:"ms-nc-chbtn",onClick:()=>E(ye=>new Set([...ye,B])),children:[s.jsx(en,{channel:da(B),size:20}),s.jsx("span",{className:"ms-nc-ell",children:Dn(B,r)}),s.jsx("span",{className:"ms-nc-faint ms-nc-small",children:Ns.filter(ye=>Ar(ye.channel)===B).length})]},B))})]}):null]})]}),s.jsxs("div",{className:"ms-nc-errbar",children:[Sn?s.jsxs("div",{className:"ms-nc-ferr",role:"alert",children:[s.jsx(F,{name:"warn",size:14}),s.jsx("span",{children:a.packFull({label:Sn,max:Bd})})]}):null,K?s.jsxs("div",{className:"ms-nc-ferr",role:"alert",children:[s.jsx(F,{name:"warn",size:14}),s.jsx("span",{children:a.createFailed({detail:K})}),o.conflict?.code==="brief-session-handed-off"?s.jsx(JF,{brief:o,onOpen:B=>Bs(es.creative(e,B)),onDone:()=>I(null)}):null]}):null]}),s.jsxs("footer",{className:"ms-nc-foot",children:[s.jsx("div",{className:"ms-nc-frames","aria-hidden":"true",children:ct.slice(0,UF).map(B=>{const He=Math.max(14,Math.min(64,Math.round(40*B.width/B.height)));return s.jsx("span",{style:{width:He,height:Math.min(40,Math.round(He*B.height/B.width))}},B.id)})}),s.jsxs("div",{className:"ms-nc-sum",children:[ct.length+pa?s.jsx("b",{title:dt,children:dt}):s.jsx("b",{className:le(J&&"ms-nc-warn"),children:a.pickFormat}),s.jsx("span",{className:"ms-nc-muted ms-nc-small",children:a.summaryHint}),mt?s.jsx("span",{className:"ms-nc-muted ms-nc-small ms-nc-estimate",children:a.similar({range:mt})}):null]}),s.jsx("div",{className:"ms-grow"}),s.jsx($,{size:"lg",variant:"ghost",loading:X==="draft",disabled:X!==null||vn||Ot||Sn!==null,title:Ot?n.web.briefSession.agentWorking:void 0,onClick:()=>{Vn(!1)},children:a.saveDraft}),s.jsxs($,{size:"lg",variant:"accent","aria-label":a.generate,loading:X==="generate",disabled:X!==null||vn||Ot||Sn!==null,title:Ot?n.web.briefSession.agentWorking:void 0,onClick:()=>{Vn(!0)},children:[s.jsx(F,{name:"sparkle",size:14}),a.generate,s.jsx("kbd",{className:"ms-nc-kbd","aria-hidden":"true",children:Pt()?"⌘↵":"Ctrl ↵"})]})]})]}),s.jsx(MF,{open:_e===!1,onResume:ie,onStartOver:()=>{ke()}}),s.jsx(Lv,{open:We,onClose:()=>Rs(!1),slug:e,...fe?{initial:fe}:{},onConfirm:B=>{Ge(B),se(!1)}}),s.jsx(OF,{open:us.open,editing:us.editing,presets:Ns,onClose:()=>fs(B=>({...B,open:!1})),onSaved:ts,onDeleted:ps}),s.jsx(CF,{open:Oe,onClose:()=>be(!1),anchor:Ys,onComputer:()=>Ke.current?.click(),onLibrary:()=>hs(!0)}),s.jsx(Cm,{slug:e,projectName:c,open:As,onClose:()=>hs(!1),anchor:Ys,library:Q,onRetry:()=>{Re({value:null,error:null}),is(B=>B+1)},chosen:N,onToggle:ks,extra:we.refs.filter(B=>N.includes(XF(B.file))),onUpload:()=>Ke.current?.click()})]})}function JF({brief:e,onOpen:t,onDone:n}){const a=V().web.briefSession,r=e.session?.handedOffTo;return s.jsxs("span",{className:"ms-nc-conflict",children:[r?s.jsx($,{size:"sm",variant:"outline",onClick:()=>t(r),children:a.openCreative}):null,s.jsx($,{size:"sm",variant:"ghost",onClick:()=>{e.discard().then(()=>n?.(),()=>{})},children:a.discard})]})}function YF({pack:e,onOpen:t,onRemove:n}){const a=V().web.storePack,r=e?a.entryOn({count:e.screenshots.length}):a.entryHint;return s.jsxs("div",{className:"ms-nc-tile-wrap",children:[s.jsxs("button",{type:"button",className:le("ms-nc-tile",e&&"ms-on"),"aria-pressed":e!==null,title:r,"aria-label":e?a.entryAria({count:e.screenshots.length}):a.entryAdd,onClick:t,children:[s.jsx("span",{className:"ms-nc-tile-top",children:s.jsx("span",{className:"ms-nc-frame","aria-hidden":"true",children:s.jsx(F,{name:"image",size:12})})}),s.jsxs("span",{className:"ms-nc-tile-text",children:[s.jsx("b",{className:"ms-nc-ell",children:a.entryTitle}),s.jsx("span",{className:"ms-nc-tile-meta ms-nc-ell",children:r})]}),e?s.jsx("span",{className:"ms-nc-tick","aria-hidden":"true",children:s.jsx(F,{name:"check",size:10,strokeWidth:2.4})}):null]}),e?s.jsx("button",{type:"button",className:"ms-nc-link ms-nc-pack-remove","aria-label":a.entryRemoveAria,title:a.entryRemoveAria,onClick:n,children:s.jsx(F,{name:"close",size:13})}):null]})}function QF({onOpen:e}){const t=V().web.newCreative;return s.jsx("div",{className:"ms-nc-tile-wrap",children:s.jsxs("button",{type:"button",className:"ms-nc-tile ms-nc-custom-add","aria-label":t.customTileAria,title:t.customTileAria,onClick:e,children:[s.jsx("span",{className:"ms-nc-tile-top",children:s.jsx("span",{className:"ms-nc-frame","aria-hidden":"true",children:s.jsx(F,{name:"plus",size:14})})}),s.jsxs("span",{className:"ms-nc-tile-text",children:[s.jsx("b",{className:"ms-nc-ell",children:t.customTile}),s.jsx("span",{className:"ms-nc-tile-meta ms-nc-ell",children:t.customTileHint})]})]})})}function eP({preset:e,on:t,onClick:n,onEdit:a,copies:r,link:l,blocked:o}){const c=V(),d=c.web.newCreative,m=rs(),u=i.useRef(null),h=i.useRef(!0);i.useLayoutEffect(()=>{if(h.current){h.current=!1;return}qn(u.current,[{transform:"scale(.96)"},{transform:"scale(1)"}],260,Vt.spring)},[t]);const f=48,x=Math.max(18,Math.min(56,Math.round(f*e.width/e.height))),p=Math.min(f,Math.round(x*e.height/e.width)),g=e.kind==="video",b=e.maxDurationSec!==void 0?Bb(e.maxDurationSec):g?c.web.formatUi.video:c.web.formatUi.image,v=Dd(e,m),y=o?d.notLinkable(o):null;return s.jsxs("div",{className:le("ms-nc-tile-wrap",r&&"ms-nc-has-copies",a&&"ms-nc-is-custom"),"data-format":e.id,children:[s.jsxs("button",{ref:u,type:"button",className:le("ms-nc-tile",t&&"ms-on"),"aria-pressed":t,onClick:n,title:`${e.width}×${e.height}`,children:[s.jsx("span",{className:"ms-nc-tile-top",children:s.jsx("span",{className:"ms-nc-frame",style:{width:x,height:p},"aria-hidden":"true",children:s.jsx(F,{name:g?"play":"image",size:g?10:12,fill:g})})}),s.jsxs("span",{className:"ms-nc-tile-text",children:[s.jsx("b",{className:"ms-nc-ell",children:Su(e,m)}),s.jsxs("span",{className:"ms-nc-tile-meta ms-nc-ell",children:[KF(e.width,e.height)," · ",b]})]}),t?s.jsx("span",{className:"ms-nc-tick","aria-hidden":"true",children:s.jsx(F,{name:"check",size:10,strokeWidth:2.4})}):null]}),r?s.jsx(sP,{label:v,n:r.n,packTaken:r.packTaken,onChange:r.onChange}):null,a?s.jsx("button",{type:"button",className:"ms-nc-link ms-nc-custom-edit","aria-label":d.customEditAria({label:v}),title:d.customEditAria({label:v}),onClick:a,children:s.jsx(F,{name:"edit",size:13})}):null,l?s.jsx("button",{type:"button",className:le("ms-nc-link",l.on&&"ms-on"),"aria-pressed":l.on,"aria-label":d.linkToggle({label:v,primary:l.primary}),title:l.on?d.linkOn({primary:l.primary}):d.linkOff({primary:l.primary}),onClick:l.onToggle,children:s.jsx(F,{name:"link",size:13})}):y?s.jsx("span",{className:"ms-nc-link ms-nc-link-no",role:"img","aria-label":y,title:y,children:s.jsx(F,{name:"link",size:13})}):null]})}function sP({label:e,n:t,packTaken:n,onChange:a}){const r=V().web.newCreative,l=Math.max(1,Bd-n),o=t<=1,c=t>=l,d=c&&n>0?r.copiesPackLimit({n}):void 0,[m,u]=i.useState(""),h=i.useRef(!0);return i.useEffect(()=>{if(h.current){h.current=!1;return}u(`${r.copiesSaid({label:e,n:t})}${d?`. ${d}`:""}`)},[t]),s.jsxs("div",{className:"ms-nc-copies",role:"group","aria-label":r.copiesLabel({label:e}),title:r.copiesHint,children:[s.jsx($,{variant:"ghost",size:"sm",icon:!0,className:"ms-nc-copy-btn","aria-label":r.copiesLess,"aria-disabled":o||void 0,onClick:()=>{o||a(t-1)},children:s.jsx(F,{name:"minus",size:14})}),s.jsx("span",{className:"ms-nc-copies-n","aria-hidden":"true",children:t}),s.jsx("span",{className:"ms-sr",role:"status",children:m}),s.jsx($,{variant:"ghost",size:"sm",icon:!0,className:"ms-nc-copy-btn","aria-label":r.copiesMore,"aria-disabled":c||void 0,title:d,onClick:()=>{c||a(t+1)},children:s.jsx(F,{name:"plus",size:14})})]})}const _p="npx @motion-studio/cli --print-url",tP=1600;function nP(e){const t=window.getSelection();if(!e||!t)return;const n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}function aP(){const t=V().web.pairing,n=Ra([]),a=i.useRef(null),[r,l]=i.useState("idle"),o=i.useRef(null);i.useEffect(()=>()=>{o.current&&clearTimeout(o.current)},[]);const c=async()=>{o.current&&clearTimeout(o.current);try{if(!navigator.clipboard?.writeText)throw new Error("clipboard unavailable");await navigator.clipboard.writeText(_p),l("copied"),o.current=setTimeout(()=>l("idle"),tP)}catch{nP(a.current),l("manual")}};return s.jsx("div",{className:"ms-pairing",children:s.jsxs("div",{className:"ms-pairing-col",ref:n,children:[s.jsx("div",{className:"ms-pairing-brand","data-enter":!0,children:s.jsx(Hr,{height:26})}),s.jsxs("div",{className:"ms-pairing-head","data-enter":!0,children:[s.jsx("h1",{children:t.title}),s.jsx("p",{role:"alert",children:t.body})]}),s.jsxs("figure",{className:"ms-term","data-enter":!0,"aria-label":t.terminalExample,children:[s.jsxs("div",{className:"ms-term-bar","aria-hidden":"true",children:[s.jsx("span",{className:"ms-term-dot"}),s.jsx("span",{className:"ms-term-dot"}),s.jsx("span",{className:"ms-term-dot"}),s.jsx("span",{className:"ms-term-title",children:t.terminal})]}),s.jsxs("div",{className:"ms-term-body",children:[s.jsxs("div",{children:[s.jsx("span",{className:"ms-term-dim",children:"$"})," npx @motion-studio/cli"]}),s.jsx("div",{className:"ms-term-dim",children:t.running}),s.jsxs("div",{children:[t.open," ",s.jsxs("span",{className:"ms-term-link",children:[location.origin,"/#t=•••••••••••"]})]})]})]}),s.jsxs("section",{className:"ms-pairing-card","data-enter":!0,"aria-labelledby":"ms-pairing-lost",children:[s.jsx("b",{id:"ms-pairing-lost",children:t.lostTitle}),s.jsx("span",{className:"ms-pairing-muted",children:t.lostBody}),s.jsxs("div",{className:"ms-pairing-cmd",children:[s.jsx("code",{ref:a,children:_p}),s.jsxs($,{size:"sm",variant:"outline",onClick:()=>{c()},children:[s.jsx(F,{name:r==="copied"?"check":"copy",size:13,strokeWidth:r==="copied"?2:1.4}),r==="copied"?t.copied:t.copy]})]}),s.jsx("p",{className:r==="manual"?"ms-pairing-hint":"ms-pairing-hint ms-sr",role:"status",children:r==="manual"?t.copyFallback({keys:Pt()?"⌘C":"Ctrl+C"}):r==="copied"?t.copiedStatus:""})]}),s.jsx("span",{className:"ms-pairing-desktop","data-enter":!0,children:t.desktopHint})]})})}const Td={height:164,maxWidth:300,gap:10},Rd=3,Md=4,_b=40,qb=(e,t)=>t?qb(t,e%t):e,rP=e=>{const t=qb(e.width,e.height);return`${e.width/t}:${e.height/t}`};function lP({slug:e,live:t}){const n=V(),a=ul(e,t),r=n.web.creatives,[l,o]=i.useState(null),[c,d]=i.useState(null),[m,u]=i.useState(0),[h,f]=i.useState([]),[x,p]=i.useState("all"),[g,b]=i.useState(""),[v,y]=i.useState([]),[w,j]=i.useState(!1),S=i.useMemo(()=>Object.entries(t.creativeTicks).filter(([L])=>L.startsWith(`${e}/`)).reduce((L,[,_])=>L+_,0),[t.creativeTicks,e]);i.useEffect(()=>{let L=!0;return Promise.resolve().then(()=>q.listCreatives(e)).then(_=>{L&&(o(_.filter(X=>!(X.ok&&X.archivedAt))),d(null))}).catch(_=>{L&&d(pe(_))}),Promise.resolve().then(()=>q.listArchivedCreatives(e)).then(_=>{L&&y((_??[]).filter(X=>X.ok&&X.archivedAt))}).catch(()=>{}),()=>{L=!1}},[e,S,m]),i.useEffect(()=>{let L=!0;return Promise.resolve().then(()=>q.getFormats()).then(_=>{L&&f(_.presets)}).catch(()=>{}),()=>{L=!1}},[]);const k=i.useMemo(()=>{const L=new Map;for(const _ of l??[])_.ok&&L.set(_.slug,Ag(_,e,t));return L},[l,e,t]),E=i.useMemo(()=>[...l??[]].sort((L,_)=>(_.ok?_.updatedAt:"").localeCompare(L.ok?L.updatedAt:"")),[l]),N=L=>L==="all"?E.length:E.filter(_=>_.ok&&vf(L,k.get(_.slug).state)).length,C=g.trim().toLocaleLowerCase(),R=E.filter(L=>!L.ok||vf(x,k.get(L.slug).state)&&(!C||L.title.toLocaleLowerCase().includes(C)||L.slug.includes(C))),P=l!==null,z=Ra([P,x]),O=i.useRef(null);i.useLayoutEffect(()=>{l&&(O.current=new Set(l.map(L=>L.slug)))},[l]);const T=()=>{p("all"),b("")},W=()=>{d(null),u(L=>L+1)},Z=()=>u(L=>L+1),A=v.length>0?s.jsxs($,{variant:"ghost",size:"sm",className:"ms-carchived-toggle",onClick:()=>j(!0),children:[s.jsx(F,{name:"folder",size:13}),n.web.removal.archivedCount({n:v.length})]}):null;return w?s.jsx(cP,{slug:e,items:v,onBack:()=>j(!1),onChanged:Z}):l&&l.length===0?s.jsxs("div",{className:"ms-creatives ms-creatives-empty",ref:z,children:[a.state?s.jsx(vr,{slug:e,state:a.state,reload:a.reload}):null,s.jsxs("section",{className:"ms-card ms-cempty","data-enter":!0,"aria-labelledby":"ms-cempty-title",children:[s.jsx("span",{className:"ms-cempty-icon","aria-hidden":"true",children:s.jsx(F,{name:"sparkle",size:18})}),s.jsx("h1",{id:"ms-cempty-title",children:r.emptyTitle}),s.jsx("p",{children:r.emptyBody}),s.jsxs("div",{className:"ms-cempty-actions",children:[s.jsx($,{variant:"outline",onClick:()=>Bs(es.project(e,"brand")),children:r.setUpBrand}),s.jsxs($,{variant:"ink",onClick:()=>Bs(es.newCreative(e)),children:[s.jsx(F,{name:"plus",size:13,strokeWidth:1.8}),r.newCreative]})]}),A]})]}):s.jsxs("div",{className:"ms-creatives",ref:z,children:[s.jsxs("div",{className:"ms-creatives-head",children:[s.jsx("h1",{children:r.title}),P?s.jsx(it,{className:"ms-creatives-seg",label:r.filter,value:x,onChange:p,options:x0.map(L=>({value:L,label:r.filters[L],count:N(L),accent:L==="needs"}))}):null,s.jsx("div",{className:"ms-grow"}),P?s.jsxs("label",{className:"ms-csearch",children:[s.jsx(F,{name:"search",size:14}),s.jsx("input",{type:"search",value:g,onChange:L=>b(L.target.value),placeholder:r.search,"aria-label":r.search})]}):null,A,s.jsxs($,{variant:"ink",onClick:()=>Bs(es.newCreative(e)),children:[s.jsx(F,{name:"plus",size:13,strokeWidth:1.8}),r.newCreative]})]}),a.state?s.jsx(vr,{slug:e,state:a.state,reload:a.reload}):null,c?s.jsxs("div",{className:"ms-creatives-alert",role:"alert",children:[s.jsx(F,{name:"warn",size:16}),s.jsx("span",{children:r.loadFailed({detail:c})}),s.jsx($,{size:"sm",variant:"outline",onClick:W,children:r.tryAgain})]}):null,!P&&!c?s.jsxs("div",{className:"ms-creatives-grid","aria-busy":"true",children:[s.jsx("span",{className:"ms-sr",role:"status",children:r.loading}),[0,1,2].map(L=>s.jsxs("div",{className:"ms-card ms-ccard ms-cskel","aria-hidden":"true",children:[s.jsx("div",{className:"ms-ccard-stage"}),s.jsxs("div",{className:"ms-ccard-body",children:[s.jsx("i",{}),s.jsx("i",{})]})]},L))]}):null,P&&R.length===0?s.jsx(Rt,{icon:"check",title:r.noMatchTitle,sub:r.noMatchBody,action:s.jsx($,{variant:"outline",size:"sm",onClick:T,children:r.showAll})}):null,P&&R.length>0?s.jsx("div",{className:"ms-creatives-grid",children:R.map((L,_)=>L.ok?s.jsx(iP,{slug:e,c:L,info:k.get(L.slug),presets:h,index:_,fresh:O.current!==null&&!O.current.has(L.slug),onChanged:Z},L.slug):s.jsx("article",{className:"ms-card ms-ccard ms-broken","data-enter":!0,"data-delay":_*_b,children:s.jsxs("div",{className:"ms-ccard-body",children:[s.jsxs("div",{className:"ms-ccard-head",children:[s.jsx("h3",{children:L.slug}),s.jsx(Qs,{tone:"warn",dot:!0,children:r.unreadable})]}),s.jsx("code",{className:"ms-ccard-error",children:L.error})]})},L.slug))}):null]})}function iP({slug:e,c:t,info:n,presets:a,index:r,fresh:l,onChanged:o}){const c=V(),d=c.web.creatives,m=rs(),u=i.useRef(null),{state:h,approval:f,job:x,step:p}=n,[g,b]=i.useState(!1),[v,y]=i.useState(null);i.useLayoutEffect(()=>{l&&Gs(u.current,{y:16,scale:.96})},[]),i.useEffect(()=>{b(!1)},[h]),i.useEffect(()=>{if(h!=="failed")return;let N=!0;return Promise.resolve().then(()=>q.getCreative(e,t.slug)).then(C=>{N&&y(C.creative.error)}).catch(()=>{}),()=>{N=!1}},[h,e,t.slug,t.updatedAt]);const w=es.creative(e,t.slug),j=i.useRef(!0);i.useEffect(()=>(j.current=!0,()=>{j.current=!1}),[]);const S=async(N,C)=>{b(!0);try{const R=N==="stay"?Lg(await q.getConversation(e,t.slug),Bl(t.slug)):{};t.variants&&N==="open"?await q.runVariants(e,t.slug,{targets:"all-active",request:null}):await q.sendCreativeTurn(e,t.slug,R),N==="open"&&j.current&&Bs(w)}catch(R){if(!j.current)return;b(!1),Pe.show(C({detail:pe(R)}),{tone:"neutral"})}},k=h==="draft"?d.draft:ll(m,t.updatedAt),E=t.formats.map(N=>({id:N,preset:pt(a,N)}));return s.jsxs("article",{ref:u,className:le("ms-card","ms-ccard",`ms-st-${h}`,h==="needs"&&"ms-needs"),"data-hover-play":!0,"data-enter":l?void 0:"","data-delay":r*_b,children:[s.jsx("div",{className:"ms-ccard-stage",children:s.jsx(oP,{slug:e,c:t,presets:a,state:h})}),s.jsxs("div",{className:"ms-ccard-body",children:[s.jsxs("div",{className:"ms-ccard-head",children:[s.jsx("h3",{children:s.jsx("a",{href:w,className:"ms-ccard-link",children:t.title})}),s.jsx("span",{className:"ms-ccard-when",children:k}),s.jsx(Bv,{slug:e,creative:t.slug,label:c.web.removal.menu({title:t.title}),onDone:o,variant:"ghost",size:"sm",className:"ms-ccard-more"})]}),E.length?s.jsxs("div",{className:"ms-ccard-tags",children:[E.slice(0,Md).map(({id:N,preset:C})=>s.jsxs(tn,{className:"ms-ftag",children:[C?s.jsx(en,{channel:da(C.channel)}):null,s.jsx("span",{className:"ms-ftag-name",children:xn(C,N,m,t.formatLabels)})]},N)),E.length>Md?s.jsx(tn,{className:"ms-ftag",children:d.moreFormats({n:E.length-Md})}):null]}):null,t.variants?s.jsxs("div",{className:"ms-ccard-variants",children:[s.jsx(tn,{className:"ms-ftag",children:c.web.variantGroup.count({count:t.variants.count})}),t.variants.missing.length?s.jsx("span",{className:"ms-ccard-missing",children:c.web.variantGroup.listMissing({letters:U0(t.variants.missing)})}):null]}):null,h==="needs"&&f?s.jsxs("div",{className:"ms-cc-needs",children:[s.jsx("span",{className:"ms-dot","aria-hidden":"true"}),s.jsx("b",{className:"ms-cc-needs-title",children:f.title}),s.jsx(mc,{createdAt:Date.parse(f.createdAt),ttlSec:Math.max(0,(Date.parse(f.expiresAt)-Date.parse(f.createdAt))/1e3)}),s.jsx($,{size:"sm",variant:"ink",className:"ms-cc-act",onClick:()=>Bs(w),children:d.review})]}):null,h==="running"?s.jsxs("div",{className:"ms-cc-run",children:[s.jsx("span",{className:"ms-cc-step",children:x?.state==="queued"?d.queued:p??d.working}),s.jsx("div",{className:"ms-progress ms-indet",role:"progressbar","aria-label":c.web.ui.progress,children:s.jsx("i",{})})]}):null,h==="ready"?s.jsxs("span",{className:"ms-cc-ok",children:[s.jsx("span",{className:"ms-dot","aria-hidden":"true"}),d.readyVersion({n:t.versions})]}):null,h==="incomplete"?s.jsxs("span",{className:"ms-cc-warn",children:[s.jsx(F,{name:"warn",size:13}),d.incomplete({n:t.versions})]}):null,h==="failed"||h==="interrupted"?s.jsxs("div",{className:"ms-cc-fail",children:[s.jsx("span",{className:"ms-cc-fail-text",children:h==="failed"?v??d.failed:d.interrupted}),s.jsxs($,{size:"sm",variant:"outline",className:"ms-cc-act",loading:g,onClick:()=>{S("stay",d.retryFailed)},children:[s.jsx(F,{name:"refresh",size:13}),d.tryAgain]})]}):null,h==="draft"?s.jsxs("div",{className:"ms-cc-draft",children:[s.jsx("span",{className:"ms-cc-note",children:d.draftNote}),s.jsxs($,{size:"sm",variant:"ink",className:"ms-cc-act","aria-label":d.generateOf({title:t.title}),loading:g,onClick:()=>{S("open",d.generateFailed)},children:[s.jsx(F,{name:"sparkle",size:13}),d.generate]})]}):null]})]})}function oP({slug:e,c:t,presets:n,state:a}){const r=V().web.creatives,[l,o]=i.useState(null),{ref:c,seen:d}=zm(),m=!t.cover&&t.coverFrame&&t.versions>0?{...t.coverFrame,slug:e,creative:t.slug}:null,u=Om(m,d);if((t.cover||m&&u.state!=="none"&&u.state!=="failed")&&t.versions>0){const f=t.formats[0]?pt(n,t.formats[0]):null,x=l??(f?f.width/f.height:1),p=Math.min(Td.height,Td.maxWidth/x),g=t.cover?q.fileUrl(e,t.slug,t.cover):u.url,b=t.cover?Ig(t.cover):null,v=b?q.fileUrl(e,t.slug,b):null,y=w=>{const j=w.currentTarget,[S,k]=j instanceof HTMLVideoElement?[j.videoWidth,j.videoHeight]:[j.naturalWidth,j.naturalHeight];S>0&&k>0&&o(S/k)};return s.jsxs(s.Fragment,{children:[s.jsxs("div",{ref:c,className:"ms-ccard-frame ms-ccard-frame-out",style:{width:Math.round(p*x),height:Math.round(p)},children:[g?s.jsx(Yg,{src:g,video:v,onLoad:y}):null,a==="running"?s.jsx("span",{className:"ms-shimmer","aria-hidden":"true"}):null,a==="failed"||a==="interrupted"?s.jsx("span",{className:"ms-ccard-frame-warn","aria-hidden":"true",children:s.jsx(F,{name:"warn",size:16,strokeWidth:1.6})}):null]}),t.formats.length>1?s.jsx("span",{className:"ms-stage-more",children:r.moreFormats({n:t.formats.length-1})}):null]})}const h=g0(t.formats.slice(0,Rd),n,Td);return s.jsxs(s.Fragment,{children:[h.map(f=>s.jsxs("div",{className:le("ms-ccard-frame","ms-ccard-frame-empty",a==="running"&&"ms-ccard-frame-busy"),style:{width:f.width,height:f.height},children:[f.preset?rP(f.preset):null,a==="running"?s.jsx("span",{className:"ms-shimmer","aria-hidden":"true"}):null]},f.id)),t.formats.length>Rd?s.jsx("span",{className:"ms-stage-more",children:r.moreFormats({n:t.formats.length-Rd})}):null]})}function cP({slug:e,items:t,onBack:n,onChanged:a}){const r=V().web.removal;return s.jsxs("div",{className:"ms-creatives ms-carchived",children:[s.jsxs("div",{className:"ms-creatives-head",children:[s.jsxs($,{variant:"ghost",size:"sm",onClick:n,children:[s.jsx(F,{name:"back",size:13}),r.backToCreatives]}),s.jsx("h1",{children:r.archivedTitle})]}),t.length===0?s.jsx(Rt,{icon:"check",title:r.archivedEmpty}):s.jsx("ul",{className:"ms-carchived-list","aria-label":r.archivedTitle,children:t.map(l=>l.ok?s.jsx(dP,{slug:e,c:l,onChanged:a},l.slug):null)})]})}function dP({slug:e,c:t,onChanged:n}){const a=V(),r=a.web.removal,l=rs(),o=Rm(e,t.slug,n),{load:c}=o;i.useEffect(()=>{c()},[c]);const d=o.info?.blocked?.message??null;return s.jsxs("li",{className:"ms-card ms-carchived-row",children:[s.jsxs("div",{className:"ms-carchived-text",children:[s.jsx("b",{children:t.title}),s.jsxs("span",{className:"ms-faint",children:[t.archivedAt?r.archivedOn({when:ll(l,t.archivedAt)}):null,t.variants?` · ${a.web.variantGroup.count({count:t.variants.count})}`:null]})]}),s.jsxs($,{size:"sm",variant:"outline",onClick:o.restore,children:[s.jsx(F,{name:"undo",size:13}),r.restore]}),s.jsxs($,{size:"sm",variant:"ghost",disabled:!o.info||d!==null,title:d??void 0,onClick:o.askDelete,children:[s.jsx(F,{name:"trash",size:13}),t.variants?r.deleteGroup({count:t.variants.count}):r.delete]}),o.dialogs]})}function Vb({slug:e,icon:t,className:n,style:a,children:r}){const l=e&&t?q.projectFileUrl(e,t):null,[o,c]=i.useState(null);return l&&o!==l?s.jsx("span",{className:le(n,"ms-has-icon"),"aria-hidden":"true",children:s.jsx("img",{src:l,alt:"",onError:()=>c(l)})}):s.jsx("span",{className:n,style:a,"aria-hidden":"true",children:r})}const uP=3,mP=3,hP=8,fP=78,Kb=40;function th(e){const t=e.trim().replace(/^#/,"");return/^[0-9a-f]{3}$/i.test(t)?`#${[...t].map(n=>n+n).join("")}`:/^[0-9a-f]{6}([0-9a-f]{2})?$/i.test(t)?`#${t.slice(0,6)}`:null}function ec(e){const t=th(e)??"#000000",[n,a,r]=[1,3,5].map(l=>{const o=parseInt(t.slice(l,l+2),16)/255;return o<=.03928?o/12.92:((o+.055)/1.055)**2.4});return .2126*n+.7152*a+.0722*r}const vo=(e,t)=>{const[n,a]=[ec(e),ec(t)].sort((r,l)=>l-r);return(n+.05)/(a+.05)};function pP(e){const t=e.filter(r=>th(r.hex));if(t.length<2)return null;const n=t.find(r=>r.role==="background")?.hex??[...t].sort((r,l)=>ec(l.hex)-ec(r.hex))[0].hex,a=t.filter(r=>r.hex!==n).sort((r,l)=>vo(l.hex,n)-vo(r.hex,n))[0].hex;return vo(a,n)>=3?{bg:n,fg:a}:null}function xP({live:e}){const n=V().web.projects,a=i.useContext(Mn),[r,l]=i.useState(null),[o,c]=i.useState(null),[d,m]=i.useState(0),[u,h]=i.useState([]),[f,x]=i.useState([]),[p,g]=i.useState("recent"),[b,v]=i.useState(""),[y,w]=i.useState(!1),[j,S]=i.useState(null),[k,E]=i.useState(new Set),[N,C]=i.useState({}),R=i.useCallback((H,de)=>C(J=>J[H]===de?J:{...J,[H]:de}),[]),P=i.useRef(null),z=i.useCallback(()=>{P.current?.focus(),Yi(P.current)},[]);iN(z);const O=i.useMemo(()=>Object.values(e.projectTicks).reduce((H,de)=>H+de,0),[e.projectTicks]);i.useEffect(()=>{let H=!0;return Promise.resolve().then(()=>q.listProjects()).then(de=>{H&&(l(de),c(null))}).catch(de=>{H&&c(pe(de))}),()=>{H=!1}},[d,O]);const T=i.useMemo(()=>Object.values(e.creativeTicks).reduce((H,de)=>H+de,0),[e.creativeTicks]);i.useEffect(()=>{let H=!0;return Promise.resolve().then(()=>q.recentCreatives(uP)).then(de=>{H&&h(de)}).catch(()=>{}),()=>{H=!1}},[T,d]),i.useEffect(()=>{let H=!0;return Promise.resolve().then(()=>q.getFormats()).then(de=>{H&&x(de.presets)}).catch(()=>{}),()=>{H=!1}},[]);const W=i.useMemo(()=>{const H={};for(const de of u)H[de.project.slug]=H[de.project.slug]?nh(H[de.project.slug],de.updatedAt):de.updatedAt;return H},[u]),Z=(r??[]).every(H=>!H.ok||N[H.slug]!==void 0),A=i.useMemo(()=>{const H=[...r??[]],de=se=>se.ok?se.project.name:se.slug;if(p==="name")return H.sort((se,U)=>de(se).localeCompare(de(U)));const J=Z?N:W;return H.sort((se,U)=>qp(U,J).localeCompare(qp(se,J)))},[r,p,N,W,Z]),L=async()=>{const H=b.trim();if(!H){z();return}w(!0),S(null);try{const{slug:de,project:J}=await q.createProject(H);l(se=>[{slug:de,ok:!0,project:J},...(se??[]).filter(U=>U.slug!==de)]),E(se=>new Set(se).add(de)),v(""),a?.catalog.refresh(),Pe.show(n.created({name:J.name}),{tone:"ok",action:{label:n.open,run:()=>Bs(es.project(de))}})}catch(de){S(n.createFailed({detail:pe(de)}))}finally{w(!1)}},_=r!==null,X=Ra([_]),ae=u.length>0,K=i.useRef(null);i.useLayoutEffect(()=>{ae&&Gs(K.current)},[ae]);const I=H=>Object.values(e.approvals).filter(de=>de.projectSlug===H).length;return s.jsxs("div",{className:"ms-projects",ref:X,children:[ae?s.jsxs("section",{className:"ms-jump","aria-labelledby":"ms-jump-title",ref:K,children:[s.jsxs("div",{className:"ms-jump-head",children:[s.jsx("h2",{id:"ms-jump-title",children:n.jumpBackIn}),s.jsx("span",{children:n.recentCreatives})]}),s.jsxs("div",{className:"ms-jump-grid",children:[u.map(H=>s.jsx(gP,{c:H,live:e,presets:f},`${H.project.slug}/${H.slug}`)),s.jsxs("a",{className:"ms-jump-new",href:es.newCreative(u[0].project.slug),children:[s.jsx(F,{name:"plus",size:14}),s.jsx("span",{children:n.newCreativeIn({project:u[0].project.name})})]})]})]}):null,s.jsxs("section",{className:"ms-projects-list","aria-labelledby":"ms-projects-title",children:[s.jsxs("div",{className:"ms-projects-head",children:[s.jsx("h1",{id:"ms-projects-title",children:n.title}),_?s.jsx("span",{className:"ms-projects-count",children:r.length}):null,s.jsx("div",{className:"ms-grow"}),r&&r.length>1?s.jsx(At,{className:"ms-projects-sort",label:n.sort,value:p,onChange:g,options:[{value:"recent",label:n.sortRecent},{value:"name",label:n.sortName}]}):null,s.jsxs($,{variant:"ink",onClick:z,children:[s.jsx(F,{name:"plus",size:13,strokeWidth:1.8}),n.newProject]})]}),o?s.jsxs("div",{className:"ms-projects-alert",role:"alert",children:[s.jsx(F,{name:"warn",size:16}),s.jsx("span",{children:n.loadFailed({detail:o})}),s.jsx($,{size:"sm",variant:"outline",onClick:()=>{c(null),m(H=>H+1)},children:n.tryAgain})]}):null,r?.length===0?s.jsxs("div",{className:"ms-projects-empty","data-enter":!0,children:[s.jsx("b",{children:n.emptyTitle}),s.jsx("span",{children:n.emptyBody})]}):null,s.jsxs("div",{className:"ms-projects-grid","aria-busy":!_&&!o?!0:void 0,children:[!_&&!o?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-sr",role:"status",children:n.loading}),[0,1].map(H=>s.jsxs("div",{className:"ms-card ms-pcard ms-pskel","aria-hidden":"true",children:[s.jsx("div",{className:"ms-pcover"}),s.jsxs("div",{className:"ms-pcard-body",children:[s.jsx("i",{}),s.jsx("i",{})]})]},H))]}):null,A.map((H,de)=>H.ok?s.jsx(bP,{item:H,live:e,waiting:I(H.slug),fresh:k.has(H.slug),index:de,onActivity:R},H.slug):s.jsx("div",{className:"ms-card ms-pcard ms-broken","data-enter":!0,"data-delay":de*Kb,children:s.jsxs("div",{className:"ms-pcard-body",children:[s.jsxs("div",{className:"ms-pcard-row",children:[s.jsx("b",{className:"ms-pcard-name",children:H.slug}),s.jsx(Qs,{tone:"warn",dot:!0,children:n.unreadable})]}),s.jsx("code",{className:"ms-pcard-error",children:H.error})]})},H.slug)),s.jsxs("form",{className:"ms-pnew",onSubmit:H=>{H.preventDefault(),L()},children:[s.jsx("span",{className:"ms-pnew-icon","aria-hidden":"true",children:s.jsx(F,{name:"plus",size:18})}),s.jsxs("div",{className:"ms-pnew-text",children:[s.jsx("b",{children:n.startTitle}),s.jsx("span",{children:n.startBody})]}),s.jsxs("div",{className:"ms-pnew-row",children:[s.jsx("label",{className:"ms-sr",htmlFor:"new-project",children:n.nameLabel}),s.jsx(ms,{id:"new-project",ref:P,value:b,placeholder:n.nameLabel,autoComplete:"off","aria-invalid":j?!0:void 0,"aria-describedby":j?"new-project-error":void 0,onChange:H=>{v(H.target.value),S(null)}}),s.jsx($,{type:"submit",variant:"ink",loading:y,children:n.create})]}),j?s.jsx("p",{className:"ms-pnew-error",id:"new-project-error",role:"alert",children:j}):null]})]})]})]})}function gP({c:e,live:t,presets:n}){const a=V(),r=a.web.projects,l=a.web.creatives,o=rs(),{state:c,job:d,step:m}=Ag(e,e.project.slug,t),u=e.formats[0]?pt(n,e.formats[0])??void 0:void 0,h=Math.round(Math.min(120,Math.max(40,fP*(u?u.width/u.height:1)))),f=e.formats.length===1&&u?xn(u,e.formats[0],o,e.formatLabels):r.formats({n:e.formats.length}),[x,p]=i.useState(null);return s.jsxs("a",{className:"ms-card ms-jump-tile","data-hover-play":!0,href:es.creative(e.project.slug,e.slug),children:[s.jsx("span",{className:"ms-jump-thumb",style:{width:h},children:e.cover||e.coverFrame&&x!==e.coverFrame.hash?s.jsx(Wb,{project:e.project.slug,c:e,onNone:()=>p(e.coverFrame?.hash??null)},e.coverFrame?.hash??"file"):s.jsx(F,{name:u?.kind==="image"?"image":"video",size:16})}),s.jsxs("span",{className:"ms-jump-text",children:[s.jsx("b",{className:"ms-jump-title",children:e.title}),s.jsxs("span",{className:"ms-jump-sub",children:[e.project.name," · ",f]}),s.jsxs("span",{className:"ms-jump-state",children:[c==="needs"?s.jsxs("span",{className:"ms-js ms-js-warn",children:[s.jsx("span",{className:"ms-dot","aria-hidden":"true"}),r.waiting]}):null,c==="running"?s.jsxs("span",{className:"ms-js ms-js-run",children:[s.jsx("span",{className:"ms-js-step",children:d?.state==="queued"?l.queued:m?r.rendering({step:m}):l.working}),s.jsx("span",{className:"ms-progress ms-indet",role:"progressbar","aria-label":a.web.ui.progress,children:s.jsx("i",{})})]}):null,c==="ready"||c==="incomplete"?s.jsxs("span",{className:"ms-js ms-js-ok",children:[s.jsx("span",{className:"ms-dot","aria-hidden":"true"}),r.readyWhen({when:ll(o,e.updatedAt)})]}):null,c==="draft"?s.jsx("span",{className:"ms-js",children:l.draft}):null,c==="failed"?s.jsx("span",{className:"ms-js ms-js-fail",children:l.failed}):null,c==="interrupted"?s.jsx("span",{className:"ms-js ms-js-fail",children:l.interrupted}):null]})]})]})}function Wb({project:e,c:t,onNone:n}){if(!t.cover)return t.coverFrame?s.jsx(wT,{still:{...t.coverFrame,slug:e,creative:t.slug},...n?{onNone:n}:{}}):null;const a=Ig(t.cover);return s.jsx(Yg,{src:q.fileUrl(e,t.slug,t.cover),video:a?q.fileUrl(e,t.slug,a):null})}const nh=(e,t)=>e.localeCompare(t)>=0?e:t;function qp(e,t){if(!e.ok)return"";const n=t[e.slug];return n?nh(n,e.project.updatedAt):e.project.updatedAt}const vP={value:null,done:!1};function $d(e,t){const[n,a]=i.useState(vP);return i.useEffect(()=>{let r=!0;return Promise.resolve().then(e).then(l=>{r&&a({value:l,done:!0})}).catch(()=>{r&&a(l=>({...l,done:!0}))}),()=>{r=!1}},t),n}function bP({item:e,live:t,waiting:n,fresh:a,index:r,onActivity:l}){const c=V().web.projects,d=rs(),{slug:m,project:u}=e,h=i.useRef(null),f=Object.entries(t.creativeTicks).filter(([O])=>O.startsWith(`${m}/`)).reduce((O,[,T])=>O+T,0),x=t.projectTicks[m]??0,p=$d(()=>q.listCreatives(m),[m,f]),g=$d(()=>q.getBrand(m),[m,x]),b=$d(()=>q.listAssets(m).then(O=>O.assets.length),[m,x]);i.useLayoutEffect(()=>{a&&Gs(h.current,{y:16,scale:.96})},[]);const v=(p.value??[]).flatMap(O=>O.ok?[O]:[]),[y,w]=i.useState(new Set),j=O=>`${O.slug}/${O.coverFrame?.hash??""}`,S=v.filter(O=>O.cover||O.coverFrame&&!y.has(j(O))).sort((O,T)=>T.updatedAt.localeCompare(O.updatedAt)).slice(0,mP),k=(g.value?.kit.colors??[]).filter(O=>th(O.hex)),E=g.value?.kit.fonts.length??0,N=pP(k),C=jP(g.value,u),R=v.reduce((O,T)=>nh(O,T.updatedAt),u.updatedAt);i.useEffect(()=>{p.done&&l(m,R)},[l,m,R,p.done]);const P=p.done&&g.done,z={creatives:p.value,assets:b.value};return s.jsxs("a",{ref:h,href:es.project(m),className:"ms-card ms-pcard","data-hover-play":!0,"data-enter":a?void 0:"","data-delay":r*Kb,children:[s.jsxs("div",{className:le("ms-pcover",S.length>0&&`ms-n${S.length}`),style:!S.length&&N?{background:N.bg}:void 0,children:[S.map(O=>s.jsx(Wb,{project:m,c:O,onNone:()=>w(T=>new Set(T).add(j(O)))},j(O))),!S.length&&P?s.jsx("span",{className:le("ms-pcover-word",u.name.length>18&&"ms-long"),style:N?{color:N.fg}:void 0,children:u.name}):null,k.length?s.jsx("div",{className:"ms-pstrip","aria-hidden":"true",children:k.slice(0,hP).map(O=>s.jsx("span",{style:{background:O.hex}},O.id))}):null,n?s.jsxs("span",{className:"ms-pcover-wait",children:[s.jsx("span",{className:"ms-dot","aria-hidden":"true"}),c.approvalsWaiting({n})]}):null]}),s.jsxs("div",{className:"ms-pcard-body",children:[s.jsxs("div",{className:"ms-pcard-row",children:[s.jsx(Vb,{slug:m,icon:e.icon,className:"ms-pmono",style:N?{background:k[0].hex,color:vo(k[0].hex,N.bg)>=3?N.bg:N.fg}:void 0,children:ai(u.name)}),s.jsxs("span",{className:"ms-pcard-id",children:[s.jsx("b",{className:"ms-pcard-name",children:u.name}),C?s.jsx("span",{className:"ms-pcard-site",children:C}):null]}),s.jsx("span",{className:"ms-pcard-when",children:ll(d,R)})]}),s.jsxs("div",{className:"ms-pcard-stats",children:[z.creatives?s.jsxs("span",{children:[s.jsx("b",{children:v.length})," ",c.creatives({n:v.length})]}):null,z.assets!==null?s.jsxs("span",{children:[s.jsx("b",{children:z.assets})," ",c.assets({n:z.assets})]}):null,k.length||E?s.jsxs("span",{children:[s.jsx("b",{children:k.length})," ",c.colors({n:k.length})," · ",s.jsx("b",{children:E})," ",c.fonts({n:E})]}):null]})]})]})}function jP(e,t){const n=e?.sources.find(a=>a.kind==="website"&&a.url)?.url;if(n)try{return new URL(n).host.replace(/^www\./,"")}catch{}return t.description.trim()||null}function Dl({name:e,slug:t,icon:n,size:a="sm"}){return s.jsx(Vb,{slug:t,icon:n,className:`ms-projmark ms-${a}`,children:ai(e)||"·"})}function yP({slug:e}){const n=V().web.shell,{catalog:a}=ol(),r=i.useRef(null),[l,o]=i.useState(!1),c=a.projects??[],d=c.find(h=>h.slug===e),m=d?.name??e,u=h=>{o(!1),Bs(h)};return s.jsxs(s.Fragment,{children:[s.jsxs("button",{ref:r,type:"button",className:"ms-switcher","aria-label":n.switchProject({name:m}),"aria-haspopup":"dialog","aria-expanded":l,onClick:()=>{l||a.refresh(),o(h=>!h)},children:[s.jsx(Dl,{name:m,slug:e,icon:d?.icon}),s.jsx("span",{className:"ms-switcher-name",children:m}),s.jsx(F,{name:"chevron",size:12,className:"ms-faint"})]}),s.jsxs(ot,{open:l,onClose:()=>o(!1),anchor:r,width:260,children:[s.jsx("span",{className:"ms-cap ms-pop-cap",children:n.projects}),c.map(h=>s.jsx(dn,{"data-row":"",on:h.slug===e,onClick:()=>u(es.project(h.slug)),children:s.jsxs("span",{className:"ms-switcher-row",children:[s.jsx(Dl,{name:h.name,slug:h.slug,icon:h.icon}),h.name,h.slug===e?s.jsx(F,{name:"check",size:13,className:"ms-switcher-check"}):null]})},h.slug)),s.jsx("div",{className:"ms-pop-sep",role:"separator"}),s.jsx(dn,{"data-row":"",icon:"plus",onClick:()=>{lN(),u(es.projects())},children:n.newProject})]})]})}const wP=[["general","gear"],["agent","shield"],["internet","globe"],["code","code"]],kP=1,NP=8;function SP(e){const t=e.trim().replace(/^[a-z]+:\/\//i,"").split(/[/?#]/)[0]??"",n=Ny.safeParse(t);return n.success?n.data:null}function CP(e){return/^Bash\b/.test(e)?"terminal":/^(Edit|Write|MultiEdit|NotebookEdit)\b/.test(e)?"edit":/^(WebFetch|WebSearch)\b/.test(e)?"globe":/^Read\b/.test(e)?"eye":/^(provider|mcp)/i.test(e)?"key":"shield"}function EP({slug:e,live:t,settings:n,onSettings:a,checks:r=null}){const l=V(),o=l.web.projectSettings,c=t.projectTicks[e]??0,[d,m]=i.useState(0),[u,h]=i.useState(null),[f,x]=i.useState(null),[p,g]=i.useState([]),[b,v]=i.useState(null),[y,w]=i.useState("agent"),[j,S]=i.useState(null);i.useEffect(()=>{let P=!0;return Promise.resolve().then(()=>q.getProject(e)).then(z=>{P&&(h(z.project),x(z.icon??null),v(null))}).catch(z=>{P&&v(pe(z))}),Promise.resolve().then(()=>q.getCodebases(e)).then(z=>{P&&g(z)}).catch(()=>{}),()=>{P=!1}},[e,c,d]);const k=i.useCallback(async P=>{S(null);try{return a(await q.updateSettings(P)),!0}catch(z){return S(l.web.app.settingsSaveFailed({detail:pe(z)})),!1}},[a,l]);if(!u&&b)return s.jsx("div",{className:"ms-set-center",children:s.jsx(Rt,{icon:"warn",title:l.web.project.loadFailed({detail:b}),action:s.jsx($,{onClick:()=>{v(null),m(P=>P+1)},children:o.retry})})});if(!u)return s.jsx("div",{className:"ms-set-center",children:s.jsx(Ts,{size:20})});const E=r?.find(P=>P.id==="sandbox")??null,N=Object.values(t.jobs).filter(P=>P.state==="running").length,C=s.jsx(LP,{slug:e,linked:u.linkedCodebases,checks:p,onLinked:P=>h(z=>z&&{...z,linkedCodebases:P})}),R=s.jsx(AP,{settings:n,save:k});return s.jsxs("div",{className:"ms-settings",children:[s.jsxs("nav",{className:"ms-set-nav","aria-label":o.sections,children:[s.jsx("span",{className:"ms-set-cap",title:u.name,children:u.name}),wP.map(([P,z])=>s.jsx(dn,{icon:z,on:y===P,count:P==="code"?u.linkedCodebases.length:void 0,onClick:()=>w(P),children:o.nav[P]},P))]}),s.jsxs(dg,{section:y,children:[j?s.jsx(oa,{children:j}):null,y==="general"?s.jsxs(s.Fragment,{children:[s.jsx(TP,{slug:e,project:u,onSaved:P=>h(z=>z&&{...z,...P})}),s.jsx(RP,{slug:e,name:u.name,choice:u.icon??null,shown:f,tick:c,onSaved:(P,z)=>{h(O=>{if(!O)return O;const{icon:T,...W}=O;return P?{...W,icon:P}:W}),x(z)}})]}):y==="agent"?s.jsxs(s.Fragment,{children:[s.jsx(ua,{title:o.agent.title,sub:o.agent.sub}),s.jsxs("div",{className:"ms-set-cols",children:[s.jsxs("div",{className:"ms-set-col",children:[s.jsx(MP,{settings:n,save:k,sandbox:E,running:N}),s.jsx(FP,{slug:e,tick:c}),s.jsx($P,{settings:n,save:k,sandbox:E})]}),s.jsxs("div",{className:"ms-set-col ms-set-side",children:[R,C]})]})]}):y==="internet"?s.jsxs(s.Fragment,{children:[s.jsx(ua,{title:o.nav.internet}),s.jsx("div",{className:"ms-set-narrow",children:R})]}):s.jsxs(s.Fragment,{children:[s.jsx(ua,{title:o.nav.code}),s.jsx("div",{className:"ms-set-narrow",children:C})]})]})]})}function TP({slug:e,project:t,onSaved:n}){const r=V().web.projectSettings.general,[l,o]=i.useState(t.name),[c,d]=i.useState(t.description),[m,u]=i.useState(null),[h,f]=i.useState(!1),x=async p=>{if(p.preventDefault(),!l.trim()){u({ok:!1,text:r.nameRequired});return}f(!0),u(null);try{const g={name:l.trim(),description:c.trim()};await q.updateProject(e,g),o(g.name),d(g.description),n(g),u({ok:!0,text:r.saved})}catch(g){u({ok:!1,text:r.saveFailed({detail:pe(g)})})}finally{f(!1)}};return s.jsxs(s.Fragment,{children:[s.jsx(ua,{title:r.title,sub:r.sub}),s.jsx("form",{className:"ms-set-narrow",onSubmit:p=>{x(p)},"data-enter":!0,children:s.jsxs(Dt,{className:"ms-set-form",children:[s.jsxs("label",{className:"ms-set-field",children:[s.jsx("span",{children:r.name}),s.jsx(ms,{value:l,maxLength:120,onChange:p=>{o(p.target.value),u(null)}})]}),s.jsxs("label",{className:"ms-set-field",children:[s.jsx("span",{children:r.description}),s.jsx(nn,{rows:4,value:c,placeholder:r.descriptionPlaceholder,onChange:p=>{d(p.target.value),u(null)}})]}),m&&!m.ok?s.jsx("p",{className:"ms-set-error",role:"alert",children:m.text}):null,s.jsxs("div",{className:"ms-set-actions",children:[m?.ok?s.jsx("span",{className:"ms-set-saved",role:"status",children:m.text}):null,s.jsx($,{type:"submit",variant:"ink",loading:h,children:r.save})]})]})})]})}function RP({slug:e,name:t,choice:n,shown:a,tick:r,onSaved:l}){const c=V().web.projectSettings.general.icon,d=i.useContext(Mn),[m,u]=i.useState([]),[h,f]=i.useState(null),[x,p]=i.useState(!1);i.useEffect(()=>{let k=!0;return Promise.resolve().then(()=>q.listAssets(e)).then(E=>{k&&u(E.assets.filter(N=>N.kind==="image"||N.kind==="svg").map(N=>N.file))}).catch(()=>{}),()=>{k=!1}},[e,r]);const g=k=>k===null?"auto":k==="initials"?"initials":`a:${k.asset}`,b=g(n),v=async k=>{if(!(x||g(k)===b)){p(!0),f(null);try{const E=await q.updateProject(e,{icon:k});l(k,E.icon??null),d?.catalog.refresh(),f({ok:!0,text:c.saved})}catch(E){f({ok:!1,text:c.failed({detail:pe(E)})})}finally{p(!1)}}},y=["auto","initials",...m.map(k=>`a:${k}`)],w=y.includes(b)?b:"auto",j=k=>{const E=y.indexOf(k.target.dataset.key??""),N=E<0?null:Ma(k.key,E,y.length);N!==null&&(k.preventDefault(),k.currentTarget.querySelectorAll("[data-key]")[N]?.focus())},S=(k,E,N,C)=>s.jsx("button",{type:"button",role:"radio","aria-checked":b===k,"aria-label":E,title:E,"aria-disabled":x||void 0,"data-key":k,tabIndex:k===w?0:-1,className:le("ms-set-icon-opt",b===k&&"ms-on"),onClick:()=>{v(N)},children:C},k);return s.jsx("div",{className:"ms-set-narrow","data-enter":!0,children:s.jsxs(Dt,{className:"ms-set-form",children:[s.jsxs("div",{className:"ms-set-field",children:[s.jsx("span",{children:c.title}),s.jsx("p",{className:"ms-set-icon-sub",children:c.sub})]}),s.jsxs("div",{className:"ms-set-icons",role:"radiogroup","aria-label":c.label,onKeyDown:j,children:[S("auto",c.auto,null,s.jsxs(s.Fragment,{children:[s.jsx(Dl,{name:t,slug:e,icon:n===null?a:null,size:"md"}),s.jsx("span",{children:c.auto})]})),S("initials",c.initials,"initials",s.jsxs(s.Fragment,{children:[s.jsx(Dl,{name:t,size:"md"}),s.jsx("span",{children:c.initials})]})),m.map(k=>S(`a:${k}`,k,{asset:k},s.jsxs(s.Fragment,{children:[s.jsx(Dl,{name:t,slug:e,icon:`assets/${k}`,size:"md"}),s.jsx("span",{className:"ms-set-icon-file",children:k.split("/").pop()})]})))]}),h?s.jsx("p",{className:h.ok?"ms-set-saved":"ms-set-error",role:h.ok?"status":"alert",children:h.text}):null]})})}function MP({settings:e,save:t,sandbox:n,running:a}){const l=V().web.projectSettings,o=l.agent,c=e.maxConcurrentJobs,d=e.sandboxMode!=="off"&&n?.ok!==!1,m=d&&e.autoApproveSandboxed,u=i.useId(),h=async g=>{if(!await t({autoApproveSandboxed:g}))return;const b=g?o.autoOn:o.autoOff;Pe.show(a>0?[b,o.appliesNew,o.runningKeeps({count:a})].join(" · "):b,{tone:"ok"})},[f,x]=i.useState(!1),p=async g=>{x(!0);try{await t({maxConcurrentJobs:g})}finally{x(!1)}};return s.jsxs(Dt,{className:"ms-set-card","data-enter":!0,children:[s.jsx(Xn,{title:o.autoApprove,sub:s.jsxs(s.Fragment,{children:[o.autoApproveSub," ",s.jsx("span",{className:"ms-set-shared",children:l.everyProject}),s.jsx("span",{id:u,className:le("ms-set-status",!d&&"ms-set-warn"),children:d?o.appliesNew:o.needsIsolation})]}),children:s.jsx(Un,{on:m,disabled:!d,describedBy:u,onChange:g=>{h(g)},label:o.autoApprove})}),s.jsx(Xn,{title:l.agent.confirmPaid,sub:s.jsxs(s.Fragment,{children:[l.agent.confirmPaidSub," ",s.jsx("span",{className:"ms-set-shared",children:l.everyProject})]}),children:s.jsx(Un,{on:e.confirmPaidProviders,onChange:g=>{t({confirmPaidProviders:g})},label:l.agent.confirmPaid})}),s.jsx(Xn,{title:l.agent.jobs,sub:s.jsxs(s.Fragment,{children:[l.agent.jobsSub," ",s.jsx("span",{className:"ms-set-shared",children:l.everyProject})]}),children:s.jsxs("div",{className:"ms-stepper",children:[s.jsx("button",{type:"button","aria-label":l.agent.fewer,disabled:f||c<=kP,onClick:()=>{p(c-1)},children:s.jsx(F,{name:"minus",size:12})}),s.jsx("span",{"aria-live":"polite",children:c}),s.jsx("button",{type:"button","aria-label":l.agent.more,disabled:f||c>=NP,onClick:()=>{p(c+1)},children:s.jsx(F,{name:"plus",size:12})})]})})]})}function $P({settings:e,save:t,sandbox:n}){const a=V(),r=a.web.projectSettings.agent,[l,o]=i.useState(e.model??"");i.useEffect(()=>{o(e.model??"")},[e.model]);const c=()=>{const d=l.trim()||null;d!==e.model&&t({model:d})};return s.jsxs(Dt,{className:"ms-set-card","data-enter":!0,children:[s.jsxs("div",{className:"ms-set-cardhead",children:[s.jsx("b",{children:r.advanced}),s.jsx("span",{className:"ms-set-shared",children:a.web.projectSettings.everyProject})]}),s.jsx(Xn,{title:r.isolation,sub:s.jsxs(s.Fragment,{children:[r.isolationSub,e.sandboxMode==="off"?s.jsx("span",{className:"ms-set-status ms-set-warn",children:r.isolationWarning}):n?.ok?s.jsx("span",{className:"ms-set-status ms-set-ok",children:r.sandboxOn}):s.jsx("span",{className:"ms-set-status ms-set-warn",children:n?.message??r.sandboxUnknown})]}),children:s.jsx(At,{label:r.isolation,value:e.sandboxMode,onChange:d=>{t({sandboxMode:d})},options:[{value:"auto",label:r.isolationAuto},{value:"off",label:r.isolationOff}]})}),s.jsx(Xn,{title:r.model,sub:r.modelSub,children:s.jsx(ms,{className:"ms-set-model",value:l,placeholder:r.modelPlaceholder,"aria-label":r.model,onChange:d=>o(d.target.value),onBlur:c,onKeyDown:d=>{d.key==="Enter"&&c()}})})]})}function FP({slug:e,tick:t}){const n=V(),a=rs(),r=n.web.projectSettings.allowed,[l,o]=i.useState(null),[c,d]=i.useState(null),[m,u]=i.useState(0),[h,f]=i.useState(null),[x,p]=i.useState(!1),[g,b]=i.useState({}),v=i.useRef(null),y=i.useRef(!0);i.useEffect(()=>(y.current=!0,()=>{y.current=!1}),[]),i.useEffect(()=>{let S=!0;return Promise.resolve().then(()=>q.getPermissions(e)).then(k=>{S&&(o(k),d(null))}).catch(k=>{S&&d(r.loadFailed({detail:pe(k)}))}),()=>{S=!1}},[e,t,m,r]);const w=l??[],j=async S=>{if(!S.length||x)return;f(null),p(!0),b({});const k=[];let E=null;for(const C of S)try{await q.deletePermission(e,C.rule),k.push(C.rule)}catch(R){E={rule:C.rule,error:R};break}if(!y.current)return;const N=[...v.current?.querySelectorAll("[data-rule]")??[]].filter(C=>k.includes(C.dataset.rule??""));await Promise.all(N.map(C=>il(C))),y.current&&(o(C=>C&&C.filter(R=>!k.includes(R.rule))),k.length&&Pe.show(k.length===1&&S.length===1?r.revoked({label:S[0].label||S[0].rule}):r.revokedAll({count:k.length})),E&&(b({[E.rule]:r.revokeFailed({detail:pe(E.error)})}),u(C=>C+1)),p(!1))};return s.jsxs(Dt,{className:"ms-set-card","data-enter":!0,children:[s.jsxs("div",{className:"ms-set-cardhead",children:[s.jsx("b",{children:r.title}),w.length?s.jsx("span",{className:"ms-set-faint",children:r.count({count:w.length})}):null,w.length&&h!=="all"?s.jsx($,{size:"sm",variant:"ghost",className:"ms-set-link",disabled:x,onClick:()=>f("all"),children:r.revokeAll}):null,w.length&&h==="all"?s.jsx(Hb,{question:r.confirmAll({count:w.length}),confirmLabel:r.confirmAllLabel({count:w.length}),onConfirm:()=>{j(w)},onCancel:()=>f(null)}):null]}),c?s.jsx("div",{className:"ms-set-pad",children:s.jsx("p",{className:"ms-set-error",role:"alert",children:c})}):null,!l&&!c?s.jsx("div",{className:"ms-set-pad",children:s.jsx(Ts,{size:16})}):null,l&&w.length===0?s.jsx(Rt,{icon:"shield",title:r.emptyTitle,sub:r.emptySub}):null,s.jsx("div",{ref:v,children:w.map(S=>s.jsx(PP,{rule:S,date:$u(a,S.addedAt),confirming:h===S.rule,busy:x,error:g[S.rule],onAsk:()=>{b({}),f(S.rule)},onCancel:()=>f(null),onRevoke:()=>{j([S])}},S.rule))})]})}function Hb({question:e,confirmLabel:t,onConfirm:n,onCancel:a}){const l=V().web.projectSettings.allowed,o=i.useRef(null);return i.useLayoutEffect(()=>{o.current?.focus()},[]),s.jsxs("span",{className:"ms-perm-confirm",role:"group","aria-label":e,children:[s.jsx("span",{className:"ms-perm-ask",children:e}),s.jsx($,{ref:o,size:"sm",variant:"danger","aria-label":t,onClick:n,children:l.revoke}),s.jsx($,{size:"sm",variant:"ghost",onClick:a,children:l.cancel})]})}function PP({rule:e,date:t,confirming:n,busy:a,error:r,onAsk:l,onCancel:o,onRevoke:c}){const m=V().web.projectSettings.allowed,u=i.useRef(null),h=i.useRef(!0);i.useLayoutEffect(()=>{h.current&&(h.current=!1,Gs(u.current,{y:6}))},[]);const f=e.label||e.rule;return s.jsxs("div",{ref:u,className:"ms-perm","data-rule":e.rule,children:[s.jsx("span",{className:"ms-perm-icon","aria-hidden":"true",children:s.jsx(F,{name:CP(e.rule),size:13})}),s.jsxs("div",{className:"ms-perm-text",children:[s.jsx("b",{children:f}),s.jsx("span",{className:"ms-perm-rule",title:e.rule,children:e.rule}),r?s.jsx("span",{className:"ms-perm-error",role:"alert",children:r}):null]}),n?s.jsx(Hb,{question:m.confirm,confirmLabel:m.revokeLabel({label:f}),onConfirm:c,onCancel:o}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-set-faint ms-perm-date",children:t}),s.jsx($,{size:"sm","aria-label":m.revokeLabel({label:f}),disabled:a,onClick:l,children:m.revoke})]})]})}function AP({settings:e,save:t}){const a=V().web.projectSettings,r=a.internet,[l,o]=i.useState(""),[c,d]=i.useState(null),m=e.extraAllowedDomains,u=async h=>{if(h.preventDefault(),!l.trim())return;const f=SP(l);if(!f){d(r.invalid);return}if(m.includes(f)){d(r.exists);return}d(null),await t({extraAllowedDomains:[...m,f]})&&o("")};return s.jsxs(Dt,{className:"ms-set-card ms-set-pad ms-set-stack","data-enter":!0,children:[s.jsxs("div",{className:"ms-set-cardhead ms-set-flat",children:[s.jsx("b",{children:r.title}),s.jsx("span",{className:"ms-set-shared",children:a.everyProject})]}),s.jsx("span",{className:"ms-set-sub",children:r.sub}),s.jsx("span",{className:"ms-set-faint ms-set-small",children:r.defaults}),e.droppedDomains?.length?s.jsx("p",{className:"ms-set-warn",role:"status",children:r.dropped({list:e.droppedDomains.join(", ")})}):null,s.jsxs("div",{className:"ms-set-domains",children:[m.length===0?s.jsx("span",{className:"ms-set-faint ms-set-small",children:r.none}):null,m.map(h=>s.jsxs("span",{className:"ms-domain",children:[s.jsx("span",{className:"ms-domain-name",title:h,children:h}),s.jsx("button",{type:"button","aria-label":r.remove({domain:h}),onClick:()=>{t({extraAllowedDomains:m.filter(f=>f!==h)})},children:s.jsx(F,{name:"close",size:9})})]},h))]}),s.jsxs("form",{className:"ms-set-inline",onSubmit:h=>{u(h)},children:[s.jsx(ms,{value:l,onChange:h=>{o(h.target.value),d(null)},placeholder:r.placeholder,"aria-label":r.addLabel,"aria-invalid":c?!0:void 0}),s.jsx($,{type:"submit",size:"sm",variant:"ink",disabled:!l.trim(),children:r.add})]}),c?s.jsx("p",{className:"ms-set-error",role:"alert",children:c}):null]})}function LP({slug:e,linked:t,checks:n,onLinked:a}){const r=V(),l=r.web.projectSettings.code,o=xt(),[c,d]=i.useState(!1),[m,u]=i.useState(""),[h,f]=i.useState(""),[x,p]=i.useState(null),g=i.useRef(t);g.current=t;const b=i.useRef(null);i.useLayoutEffect(()=>{c&&Gs(b.current,{y:-6})},[c]);const v=async k=>{try{return await q.updateProject(e,{linkedCodebases:k}),a(k),!0}catch(E){return p(l.saveFailed({detail:pe(E)})),!1}},y=async(k,E="")=>{const N=k.trim();if(!N||!(N.startsWith("/")||N.startsWith("~"))){p(l.needAbsolute);return}if(g.current.some(R=>R.path===N)){p(l.alreadyLinked);return}p(null);const C=E.trim()?{path:N,note:E.trim()}:{path:N};await v([...g.current,C])&&(u(""),f(""),d(!1))},w=async()=>{if(!o){d(!0);return}try{const k=await o.pickFolder(l.pickTitle);k&&await y(k)}catch(k){p(pe(k))}},j=async k=>{const E=g.current;await v(E.filter(N=>N.path!==k.path))&&Pe.show(l.unlinked({name:k.path.split("/").filter(Boolean).pop()??k.path}),{action:{label:r.web.projectSettings.undo,run:()=>{v(E)}}})},S=(k,E)=>{const N=E.trim();(k.note??"")!==N&&v(g.current.map(C=>C.path===k.path?N?{path:C.path,note:N}:{path:C.path}:C))};return s.jsxs(Dt,{className:"ms-set-card ms-set-pad ms-set-stack","data-enter":!0,children:[s.jsx("div",{className:"ms-set-cardhead ms-set-flat",children:s.jsx("b",{children:l.title})}),s.jsx("span",{className:"ms-set-sub",children:l.sub}),t.length===0?s.jsx("span",{className:"ms-set-faint ms-set-small",children:l.empty}):null,t.map(k=>{const E=n.find(N=>N.path===k.path)?.exists===!1;return s.jsxs("div",{className:"ms-code",children:[s.jsx("span",{className:"ms-code-icon","aria-hidden":"true",children:s.jsx(F,{name:"code",size:13})}),s.jsxs("div",{className:"ms-code-text",children:[s.jsx("b",{title:k.path,children:k.path.split("/").filter(Boolean).pop()??k.path}),s.jsx("span",{className:"ms-code-path",children:k.path}),s.jsx(IP,{note:k.note??"",placeholder:l.notePlaceholder,label:l.noteFor({path:k.path}),onSave:N=>S(k,N)})]}),E?s.jsx(Qs,{tone:"warn",children:l.notFound}):s.jsx(tn,{children:l.readOnly}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":l.unlink({path:k.path}),title:l.unlink({path:k.path}),onClick:()=>{j(k)},children:s.jsx(F,{name:"close",size:11})})]},k.path)}),c?s.jsxs("form",{ref:b,className:"ms-code-form",onSubmit:k=>{k.preventDefault(),y(m,h)},children:[s.jsx(ms,{autoFocus:!0,value:m,onChange:k=>{u(k.target.value),p(null)},placeholder:l.pathPlaceholder,"aria-label":l.pathLabel,className:"ms-set-mono"}),s.jsx(ms,{value:h,onChange:k=>f(k.target.value),placeholder:l.notePlaceholder,"aria-label":l.notePlaceholder}),s.jsxs("div",{className:"ms-set-inline",children:[s.jsx($,{size:"sm",variant:"ghost",onClick:()=>{d(!1),p(null)},children:l.cancel}),s.jsx($,{type:"submit",size:"sm",variant:"ink",disabled:!m.trim(),children:l.add})]})]}):s.jsxs($,{size:"sm",variant:"outline",className:le("ms-code-add"),onClick:()=>{w()},children:[s.jsx(F,{name:"plus",size:12}),l.link]}),x?s.jsx("p",{className:"ms-set-error",role:"alert",children:x}):null]})}function IP({note:e,placeholder:t,label:n,onSave:a}){const[r,l]=i.useState(null);return s.jsx("input",{className:"ms-code-note",value:r??e,placeholder:t,"aria-label":n,onChange:o=>l(o.target.value),onBlur:()=>{r!==null&&a(r),l(null)},onKeyDown:o=>{o.key==="Enter"&&o.currentTarget.blur(),o.key==="Escape"&&(l(null),o.currentTarget.blur())}})}const Fd=e=>Array.from(e.dataTransfer?.types??[]).includes("Files");function zP({slug:e,live:t}){const a=V().web.library.references,r=t.projectTicks[e]??0,[l,o]=i.useState(0),c=i.useCallback(()=>o(f=>f+1),[]),[d,m]=i.useState(null),[u,h]=i.useState(null);return i.useEffect(()=>{let f=!0;return Promise.resolve().then(()=>q.listReferences(e)).then(x=>{f&&(m(x),h(null))}).catch(x=>{f&&h(pe(x))}),()=>{f=!1}},[e,r,l]),!d&&u?s.jsx("div",{className:"ms-lib-center",children:s.jsx(Rt,{icon:"warn",title:a.loadFailed({detail:u}),action:s.jsx($,{onClick:()=>{h(null),c()},children:a.retry})})}):d?s.jsx(OP,{slug:e,listing:d,setListing:m,reload:c}):s.jsx("div",{className:"ms-lib-center",children:s.jsx(Ts,{size:20})})}function OP({slug:e,listing:t,setListing:n,reload:a}){const l=V().web.library.references,o=Ra([]),[c,d]=i.useState(()=>new Set),[m,u]=i.useState({}),[h,f]=i.useState(0),[x,p]=i.useState(()=>new Set),[g,b]=i.useState(!1),[v,y]=i.useState(!1),w=i.useRef(0),j=i.useRef(null),S=i.useRef(!0);i.useEffect(()=>{S.current=!1},[]),Yu(ae=>{n(K=>K&&{...K,references:K.references.filter(I=>!ae.includes(Oa("reference",e,I.file)))})});const k=t.references.filter(ae=>!c.has(ae.file)&&!Ju(Oa("reference",e,ae.file))),E=ae=>m[ae.file]??ae.useForBrand,N=k.filter(E).length,C=i.useCallback(ae=>{n(K=>K&&{...K,references:K.references.map(I=>I.file===ae.file?ae:I)})},[n]),R=async(ae,K)=>{u(I=>({...I,[ae.file]:K}));try{C(await q.updateReference(e,ae.file,{useForBrand:K}))}catch(I){Pe.show(l.saveFailed({detail:pe(I)}))}finally{u(I=>{const{[ae.file]:H,...de}=I;return de})}},P=async(ae,K)=>{try{return C(await q.updateReference(e,ae.file,{note:K})),!0}catch(I){return Pe.show(l.saveFailed({detail:pe(I)})),!1}},z=async(ae,K)=>{if(!await il(K))return;d(H=>new Set(H).add(ae.file));const I=()=>d(H=>{const de=new Set(H);return de.delete(ae.file),de});Qu({text:l.removed,undoLabel:l.undo,ms:cg,keys:[Oa("reference",e,ae.file)],commit:async()=>{await q.deleteReference(e,ae.file,Zu),n(H=>H&&{...H,references:H.references.filter(de=>de.file!==ae.file)}),I(),a()},restore:I,onError:H=>{Pe.show(l.removeFailed({detail:pe(H)})),a()}})},O=async ae=>{if(!(ae.length===0||t.error)){f(K=>K+ae.length);try{const I=(await q.uploadFiles(e,"references",ae)).references??[];p(H=>new Set([...H,...I.map(de=>de.file)])),n(H=>H&&{...H,references:[...H.references.filter(de=>!I.some(J=>J.file===de.file)),...I]}),Pe.show(l.uploaded({count:I.length}),{tone:"ok"}),a()}catch(K){Pe.show(l.uploadFailed({detail:pe(K)}))}finally{f(K=>Math.max(0,K-ae.length))}}},T=async()=>{b(!0);try{await xc(),await q.analyzeBrand(e),Bs(es.project(e,"brand"))}catch(ae){Pe.show(l.analyzeFailed({detail:pe(ae)}))}finally{b(!1)}},W=!t.error,Z=ae=>{!W||!Fd(ae)||(ae.preventDefault(),w.current+=1,y(!0))},A=ae=>{W&&Fd(ae)&&ae.preventDefault()},L=ae=>{!W||!Fd(ae)||(w.current=Math.max(0,w.current-1),w.current===0&&y(!1))},_=ae=>{ae.preventDefault(),w.current=0,y(!1),W&&O(Array.from(ae.dataTransfer?.files??[]))},X=()=>j.current?.click();return s.jsxs("div",{className:"ms-refs",onDragEnter:Z,onDragOver:A,onDragLeave:L,onDrop:_,children:[s.jsx("input",{ref:j,type:"file",accept:"image/*",multiple:!0,hidden:!0,"aria-label":l.addImages,onChange:ae=>{O(Array.from(ae.target.files??[])),ae.target.value=""}}),s.jsxs("div",{ref:o,className:"ms-refs-inner",children:[s.jsxs("div",{className:"ms-refs-head","data-enter":!0,children:[s.jsxs("div",{className:"ms-refs-title",children:[s.jsx("h1",{children:l.title}),s.jsx("span",{children:l.sub})]}),h>0?s.jsxs("span",{className:"ms-refs-uploading",children:[s.jsx(Ts,{decorative:!0,size:12}),l.uploading]}):null,s.jsxs($,{variant:"ink",disabled:!W,onClick:X,children:[s.jsx(F,{name:"upload",size:13,strokeWidth:1.7}),l.addImages]})]}),t.error?s.jsx(oa,{children:l.listUnreadable({detail:t.error})}):null,k.length>0?s.jsxs(Dt,{className:"ms-refs-brand","data-enter":!0,children:[s.jsx("span",{className:"ms-dot","aria-hidden":"true"}),s.jsx("b",{children:l.feeding({count:N})}),s.jsxs("span",{className:"ms-lib-muted",children:["· ",l.feedingHint]}),s.jsxs($,{size:"sm",variant:"ghost",className:"ms-accent-link",loading:g,disabled:N===0||g,onClick:()=>{T()},children:[s.jsx(F,{name:"sparkle",size:12}),l.analyze]})]}):null,k.length===0?s.jsx("div",{className:"ms-lib-empty",children:s.jsx(Rt,{icon:"image",title:l.emptyTitle,sub:l.emptyBody,action:s.jsxs($,{variant:"ink",disabled:!W,onClick:X,children:[s.jsx(F,{name:"upload",size:13}),l.addImages]})})}):s.jsx("div",{className:"ms-refs-board",children:k.map((ae,K)=>s.jsx(DP,{slug:e,entry:ae,on:E(ae),index:K,cascade:S.current,fresh:x.has(ae.file),onToggle:I=>{R(ae,I)},onNote:I=>P(ae,I),onRemove:I=>{z(ae,I)}},ae.file))})]}),v&&W?s.jsx("div",{className:"ms-lib-dropzone","aria-hidden":"true",children:s.jsx("span",{children:l.dropOverlay})}):null]})}function DP({slug:e,entry:t,on:n,index:a,cascade:r,fresh:l,onToggle:o,onNote:c,onRemove:d}){const u=V().web.library.references,h=i.useRef(null),[f,x]=i.useState(null);i.useLayoutEffect(()=>{Gs(h.current,l?{y:14,scale:.96}:{y:8,delay:r?Math.min(a,12)*30:0})},[]);const p=async()=>{if(f===null)return;const g=f.trim();if(g===t.note){x(null);return}await c(g)&&x(null)};return s.jsxs("div",{ref:h,className:le("ms-rcard",n&&"ms-on"),children:[s.jsx(li,{src:q.projectFileUrl(e,`references/${t.file}`),alt:t.file,loading:"lazy",fallbackClassName:"ms-rcard-none"}),s.jsxs("div",{className:"ms-rcard-body",children:[f!==null?s.jsx(nn,{autoFocus:!0,rows:3,value:f,"aria-label":u.noteFor({name:t.file}),placeholder:u.notePlaceholder,onChange:g=>x(g.target.value),onBlur:()=>{p()},onKeyDown:g=>{g.key==="Escape"&&(g.stopPropagation(),x(null))}}):s.jsx("button",{type:"button",className:le("ms-rcard-note",!t.note&&"ms-empty-note"),"aria-label":u.noteFor({name:t.file}),onClick:()=>x(t.note),children:t.note||u.notePlaceholder}),s.jsxs("div",{className:"ms-rcard-foot",children:[s.jsx("span",{className:"ms-rcard-file",title:t.file,children:t.file}),s.jsxs("span",{className:"ms-rcard-switch",children:[u.brandAnalysis,s.jsx(Un,{size:"sm",on:n,onChange:o,label:u.useForBrand({name:t.file})})]})]})]}),s.jsx($,{size:"sm",variant:"ghost",icon:!0,className:"ms-rcard-remove","aria-label":u.remove({name:t.file}),onClick:()=>d(h.current),children:s.jsx(F,{name:"trash",size:12})})]})}const bo=200,BP=100,Vp=2e3,Gb="…",Tl=e=>Array.from(e).length,UP=["zh-Hans","zh-Hant","ja","th"],sc=e=>UP.includes(e)?"":" ";function nl(e,t){let n=e.split(/\r\n|[\r\n]/).map(l=>l.trim()).filter(l=>l!==""),a=n.join(`
|
|
29
|
+
`);if(Tl(a)>Br.text&&(a=Array.from(a).slice(0,Br.text).join(""),n=a.split(`
|
|
30
|
+
`).map(l=>l.trim()).filter(l=>l!=="")),n.length<=Ga.maxLines)return n.join(`
|
|
31
|
+
`);const r=Cy(n.join(sc(t)),t);return r.length<=Ga.maxLines?r.join(`
|
|
32
|
+
`):[...r.slice(0,Ga.maxLines-1),r.slice(Ga.maxLines-1).join(sc(t))].join(`
|
|
33
|
+
`)}const Kp=(e,t)=>e.replace(/\s*\n\s*/g,sc(t)),Dr=e=>e.replace(/\s+/g,""),Ua=(e,t)=>e.start-t.start||e.end-t.end;function Xb(e){let t=0;for(const n of e){const a=/^u(\d+)$/.exec(n.id);a&&(t=Math.max(t,Number(a[1])))}return`u${t+1}`}function Zb(e,t){const n={...e,text:t,edited:!0};return e.words&&Dr(e.words.map(a=>a.text).join(""))!==Dr(t)&&delete n.words,n}function yr(e,t,n=e.selected){return{...e,cues:[...t].sort(Ua),past:[...e.past,e.cues].slice(-200),future:[],selected:n,dirty:!0,typing:null,dragging:null}}function _P(e,t){const n=e.cues.findIndex(f=>f.id===t.id);if(n<0)return e;const a=e.cues[n],r=e.cues[n-1],l=e.cues[n+1],o=r?r.end:0,c=l?l.start:e.durationMs,d=(f,x)=>x!==void 0&&Math.abs(f-x)<=BP?x:f;let m=a.start,u=a.end;if(t.start!==void 0&&t.end!==void 0){const f=Math.max(bo,t.end-t.start),x=d(t.start,r?.end);m=x!==t.start?x:d(t.end,l?.start)-f,m=Math.min(Math.max(m,o),Math.max(o,c-f)),u=Math.min(m+f,c)}else t.start!==void 0?m=Math.min(Math.max(d(t.start,r?.end),o),a.end-bo):t.end!==void 0&&(u=Math.max(Math.min(d(t.end,l?.start),c),a.start+bo));if(m=Math.round(m),u=Math.round(u),m===a.start&&u===a.end)return e;const h=e.cues.slice();return h[n]={...a,start:m,end:u,edited:!0},t.drag&&e.dragging===t.id&&e.past.length>0?{...e,cues:h.sort(Ua),future:[],dirty:!0}:{...yr(e,h),dragging:t.drag?t.id:null}}function qP(e,t){const n=e.cues.findIndex(b=>b.id===t.id);if(n<0)return e;const a=e.cues[n],r=Math.max(0,Math.min(t.at,a.text.length)),l=nl(a.text.slice(0,r),e.lang),o=nl(a.text.slice(r),e.lang);if(l===""||o==="")return e;let c,d,m,u,h,f=-1;if(a.words&&a.words.length>1){const b=Tl(Dr(a.text.slice(0,r)));let v=0;for(let y=0;y<a.words.length;y++){if(v+=Tl(Dr(a.words[y].text)),v===b){f=y+1;break}if(v>b)break}(f<=0||f>=a.words.length)&&(f=-1)}if(f>0&&a.words)u=a.words.slice(0,f),h=a.words.slice(f),d=Math.max(u[f-1].end,a.start+1),m=Math.min(h[0].start,a.end-1),m<d&&(m=d);else{const b=Tl(Dr(l)),v=Tl(Dr(o));c=a.start+Math.round((a.end-a.start)*b/(b+v)),c=Math.min(Math.max(c,a.start+1),a.end-1),d=c,m=c}if(d<=a.start||m>=a.end)return e;const x={...a,text:l,end:d,edited:!0},p={id:Xb(e.cues),start:m,end:a.end,text:o,edited:!0};a.source&&(x.source=a.source),delete x.words,u&&(x.words=u),h&&(p.words=h);const g=e.cues.slice();return g.splice(n,1,x,p),yr(e,g)}function VP(e,t){const n=e.cues.findIndex(d=>d.id===t),a=e.cues[n],r=e.cues[n+1];if(!a||!r)return e;const l=nl(`${Kp(a.text,e.lang)}${sc(e.lang)}${Kp(r.text,e.lang)}`,e.lang),o={...a,text:l,end:r.end,edited:!0};delete o.words,a.words&&r.words&&a.words.length+r.words.length<=Br.words&&(o.words=[...a.words,...r.words]);const c=e.cues.slice();return c.splice(n,2,o),yr(e,c,e.selected===r.id?a.id:e.selected)}function KP(e,t){if(t<0||t>e.durationMs||e.cues.some(m=>t>=m.start&&t<m.end))return e;const n=[...e.cues].reverse().find(m=>m.end<=t),a=e.cues.find(m=>m.start>=t),r=n?n.end:0,l=a?a.start:e.durationMs;if(l-r<bo)return e;const o=Math.max(r,Math.min(t,l-Vp)),c=Math.min(o+Vp,l),d={id:Xb(e.cues),start:o,end:c,text:Gb,edited:!0};return yr(e,[...e.cues,d],d.id)}function WP(e,t){if(t.find==="")return e;const n=new RegExp(t.find.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),t.caseSensitive?"gu":"giu");let a=!1;const r=e.cues.map(l=>{const o=nl(l.text.replace(n,()=>t.with),e.lang);return o===""||o===l.text?l:(a=!0,Zb(l,o))});return a?yr(e,r):e}function Wp(e,t){switch(t.type){case"load":return{cues:[...t.cues].sort(Ua),past:[],future:[],selected:null,durationMs:t.durationMs,dirty:!1,lang:t.lang,typing:null,dragging:null};case"select":return t.id===e.selected&&e.typing===null&&e.dragging===null?e:{...e,selected:t.id,typing:null,dragging:null};case"endTyping":return e.typing===null?e:{...e,typing:null};case"endDrag":return e.dragging===null?e:{...e,dragging:null};case"duration":return t.ms===e.durationMs||!(t.ms>0)?e:{...e,durationMs:Math.round(t.ms)};case"undo":{const n=e.past[e.past.length-1];return n?{...e,cues:n,past:e.past.slice(0,-1),future:[e.cues,...e.future],selected:n.some(a=>a.id===e.selected)?e.selected:null,dirty:!0,typing:null,dragging:null}:e}case"redo":{const n=e.future[0];return n?{...e,cues:n,past:[...e.past,e.cues].slice(-200),future:e.future.slice(1),selected:n.some(a=>a.id===e.selected)?e.selected:null,dirty:!0,typing:null,dragging:null}:e}case"text":{const n=e.cues.findIndex(l=>l.id===t.id);if(n<0)return e;const a=nl(t.text,e.lang);if(a===""||a===e.cues[n].text)return e;const r=e.cues.slice();return r[n]=Zb(e.cues[n],a),e.typing===t.id&&e.past.length>0?{...e,cues:r,future:[],dirty:!0,dragging:null}:{...yr(e,r),typing:t.id}}case"times":return _P(e,t);case"split":return qP(e,t);case"merge":return VP(e,t.id);case"add":return KP(e,t.at);case"delete":return e.cues.some(n=>n.id===t.id)?yr(e,e.cues.filter(n=>n.id!==t.id),e.selected===t.id?null:e.selected):e;case"replace":return WP(e,t)}}function HP(){return{cues:[],past:[],future:[],selected:null,durationMs:0,dirty:!1,lang:"en",typing:null,dragging:null}}function GP(e,t){const n=[...e].sort(Ua),a=new Map;return n.forEach((r,l)=>{const o=Sy(r,n[l+1],t);o.length>0&&a.set(r.id,o)}),a}function Pd(e,t){let n=null;for(const a of e)t>=a.start&&t<a.end&&(n===null||Ua(a,n)>=0)&&(n=a);return n}function XP(e,t,n){const a=[];for(const r of[...t].sort(Ua).slice(0,Br.cues)){const l=n>0?Math.min(r.end,n):r.end;if(!(l>r.start))continue;const o=r.words?.filter(c=>c.start<l).slice(0,Br.words).map(c=>({start:c.start,end:Math.min(c.end,l),text:c.text}));a.push({start:r.start,end:l,text:r.text.slice(0,Br.text),...o?{words:o}:{}})}return{lang:e,cues:a}}function Ql(e){const t=Math.max(0,Math.round(e)),n=Math.floor(t/6e4),a=Math.floor(t%6e4/1e3);return`${String(n).padStart(2,"0")}:${String(a).padStart(2,"0")}.${String(t%1e3).padStart(3,"0")}`}function Hp(e){const t=/^\s*(?:(\d{1,4}):)?(\d{1,5})(?:[.,](\d{1,3}))?\s*$/.exec(e);if(!t)return null;const n=t[1]!==void 0?Number(t[1]):0,a=Number(t[2]);if(t[1]!==void 0&&a>=60)return null;const r=t[3]!==void 0?Number(t[3].padEnd(3,"0")):0;return n*6e4+a*1e3+r}const ZP=e=>`[data-cue="${e}"]`;function JP({cues:e,lang:t,warnings:n,selected:a,now:r,dispatch:l,onPick:o,sources:c,sourceLang:d,retranslating:m,onRetranslate:u}){const h=V();return s.jsx("ol",{className:"ms-subs-list","aria-label":h.subtitles.listLabel,children:e.map((f,x)=>s.jsx(YP,{cue:f,n:x+1,last:x===e.length-1,lang:t,selected:f.id===a,now:f.id===r,warnings:[...n.get(f.id)??[],...f.text===Gb?["placeholder"]:[]],dispatch:l,onPick:o,source:c?.get(f.id),sourceLang:d,retranslating:m===!0,onRetranslate:u},f.id))})}function YP({cue:e,n:t,last:n,lang:a,selected:r,now:l,warnings:o,dispatch:c,onPick:d,source:m,sourceLang:u,retranslating:h,onRetranslate:f}){const p=V().subtitles,g=i.useRef(null),[b,v]=i.useState(null);i.useEffect(()=>{if(b===null)return;const S=nl(b,a);S!==""&&S!==e.text&&v(null)},[e.text]);const y=S=>{S.target.closest("button")||d(e)},w=()=>{const S=g.current,k=S?Math.min(S.selectionStart??0,e.text.length):0;c({type:"split",id:e.id,at:k})},j=S=>{const k=p.warningHints;switch(S){case"tooLong":return k.tooLong({lines:Ga.maxLines});case"tooFast":return k.tooFast({cps:Ga.maxCps});case"tooShort":return k.tooShort({seconds:Ga.minMs/1e3});case"tooLongOnScreen":return k.tooLongOnScreen({seconds:Ga.maxMs/1e3});case"overlap":return k.overlap;case"placeholder":return k.placeholder}};return s.jsxs("li",{className:le("ms-subs-row",r&&"ms-on",l&&"ms-now"),"data-cue":e.id,"aria-current":r||void 0,onClick:y,children:[s.jsxs("div",{className:"ms-subs-row-head",children:[s.jsx("span",{className:"ms-subs-num","aria-hidden":"true",children:t}),s.jsx(Gp,{label:p.start({n:t}),value:e.start,onCommit:S=>c({type:"times",id:e.id,start:S})}),s.jsx("span",{className:"ms-subs-arrow","aria-hidden":"true",children:"→"}),s.jsx(Gp,{label:p.end({n:t}),value:e.end,onCommit:S=>c({type:"times",id:e.id,end:S})}),s.jsxs("span",{className:"ms-subs-row-actions",children:[s.jsx(pn,{label:p.split,children:s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":p.split,onClick:w,children:s.jsx(F,{name:"scissors",size:13})})}),s.jsx(pn,{label:p.merge,children:s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":p.merge,disabled:n,onClick:()=>c({type:"merge",id:e.id}),children:s.jsx(F,{name:"link",size:13})})}),s.jsx(pn,{label:p.remove,children:s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":p.remove,onClick:()=>c({type:"delete",id:e.id}),children:s.jsx(F,{name:"trash",size:13})})})]})]}),s.jsx("textarea",{ref:g,className:"ms-input ms-textarea ms-subs-text",rows:2,"aria-label":p.text({n:t}),spellCheck:!0,lang:a,value:b??e.text,onChange:S=>{v(S.target.value),c({type:"text",id:e.id,text:S.target.value})},onFocus:()=>{r||d(e)},onBlur:()=>{v(null),c({type:"endTyping"})}}),m?s.jsx("p",{className:le("ms-subs-source",m.state!=="current"&&"ms-stale"),"aria-label":p.sourceText,lang:u,children:m.text}):null,m&&m.state!=="current"?s.jsxs("div",{className:"ms-subs-chips ms-subs-stale",children:[s.jsx(sn,{icon:"warn",className:"ms-subs-warn",title:m.state==="changed"?p.staleHint:p.goneHint,children:m.state==="changed"?p.staleMark:p.goneMark}),m.state==="changed"&&f?s.jsxs($,{size:"sm",variant:"outline",disabled:h,onClick:()=>f(e.id),children:[s.jsx(F,{name:"refresh",size:12}),p.retranslate]}):null]}):null,o.length?s.jsx("div",{className:"ms-subs-chips",children:o.map(S=>s.jsx(sn,{icon:"warn",className:"ms-subs-warn",title:j(S),children:p.warnings[S]},S))}):null]})}function Gp({label:e,value:t,onCommit:n}){const a=V(),[r,l]=i.useState(null);i.useEffect(()=>{l(null)},[t]);const o=()=>{if(r===null)return;const d=Hp(r);l(null),d!==null&&d!==t&&n(d)},c=d=>{d.key==="Enter"&&(d.preventDefault(),o()),d.key==="Escape"&&r!==null&&(d.preventDefault(),l(null))};return s.jsx(ms,{className:"ms-subs-time","aria-label":e,title:a.subtitles.timeHint,inputMode:"decimal",spellCheck:!1,value:r??Ql(t),"aria-invalid":r!==null&&Hp(r)===null?!0:void 0,onChange:d=>l(d.target.value),onBlur:o,onKeyDown:c})}function QP({cues:e,dispatch:t}){const a=V().subtitles,[r,l]=i.useState(""),[o,c]=i.useState(""),[d,m]=i.useState(!1),u=d?r:r.toLocaleLowerCase(),h=r===""?0:e.filter(f=>(d?f.text:f.text.toLocaleLowerCase()).includes(u)).length;return s.jsxs("div",{className:"ms-subs-find",role:"search","aria-label":a.findReplace,children:[s.jsx(ms,{"aria-label":a.find,placeholder:a.find,value:r,onChange:f=>l(f.target.value)}),s.jsx(ms,{"aria-label":a.replaceWith,placeholder:a.replaceWith,value:o,onChange:f=>c(f.target.value)}),s.jsxs("div",{className:"ms-subs-find-row",children:[s.jsx(sn,{on:d,onClick:()=>m(f=>!f),children:a.matchCase}),s.jsx("span",{className:"ms-subs-find-count",role:"status",children:r===""?"":a.matches({count:h})}),s.jsx($,{size:"sm",variant:"outline",disabled:h===0,onClick:()=>t({type:"replace",find:r,with:o,caseSensitive:d}),children:a.replaceAll})]})]})}const eA=1,sA=20,tA=100,nA=1e3,aA=1e3,rA=3,Ad=(e,t,n)=>Math.min(n,Math.max(t,e));function lA(e,t){const n=e.getContext("2d");if(!n)return;const a=window.devicePixelRatio||1,r=e.clientHeight||1;if(e.width=Math.round(t.viewW*a),e.height=Math.round(r*a),n.setTransform(a,0,0,a,0,0),n.clearRect(0,0,t.viewW,r),!(t.peaks.length===0||t.trackW<=0)){n.fillStyle=getComputedStyle(e).color,n.globalAlpha=.8;for(let l=0;l<t.viewW;l+=2){const o=(t.scrollX+l)/t.trackW*t.span,c=(t.scrollX+l+2)/t.trackW*t.span;if(o>=t.cover)break;const d=Math.floor(o/t.cover*t.peaks.length),m=Math.max(d+1,Math.ceil(c/t.cover*t.peaks.length));let u=0;for(let f=d;f<Math.min(m,t.peaks.length);f++)u=Math.max(u,t.peaks[f]??0);const h=Math.max(.04,u)*(r-8);n.fillRect(l,(r-h)/2,1.2,h)}}}function iA({cues:e,durationMs:t,peaks:n,peaksMs:a,time:r,selected:l,dragging:o=null,dispatch:c,onSeek:d}){const u=V().subtitles,h=i.useRef(null),f=i.useRef(null),x=i.useRef(null),p=i.useRef(null),g=i.useRef(null),b=i.useRef(null),v=()=>{b.current&&(clearTimeout(b.current),b.current=null),g.current!==null&&(g.current=null,c({type:"endDrag"}))},y=i.useRef(v);y.current=v,i.useEffect(()=>()=>{b.current&&clearTimeout(b.current)},[]);const w=i.useRef(o);w.current=o;const[j,S]=i.useState(1),[k,E]=i.useState(0),[N,C]=i.useState(0),[R,P]=i.useState(0),z=Math.max(1,t),O=K=>{const I=f.current?.getBoundingClientRect();return!I||!I.width?null:Math.round(Ad((K-I.left)/I.width*z,0,z))};i.useLayoutEffect(()=>{const K=h.current;if(!K)return;const I=()=>{E(K.clientWidth),C(K.scrollLeft)};I();const H=typeof ResizeObserver<"u"?new ResizeObserver(I):null;return H?.observe(K),K.addEventListener("scroll",I,{passive:!0}),()=>{H?.disconnect(),K.removeEventListener("scroll",I)}},[]),i.useEffect(()=>{const K=()=>P(de=>de+1),I=typeof MutationObserver<"u"?new MutationObserver(K):null;I?.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme","class","style"]});const H=typeof matchMedia=="function"?matchMedia("(prefers-color-scheme: dark)"):null;return H?.addEventListener?.("change",K),()=>{I?.disconnect(),H?.removeEventListener?.("change",K)}},[]);const T=i.useRef(j);T.current=j,i.useEffect(()=>{const K=h.current;if(!K)return;const I=H=>{if(!(H.metaKey||H.ctrlKey))return;H.preventDefault();const de=T.current,J=Ad(de*Math.exp(-H.deltaY*.002),eA,sA);if(J===de)return;const se=K.getBoundingClientRect(),U=H.clientX-se.left,te=(K.scrollLeft+U)/(K.clientWidth*de);S(J),requestAnimationFrame(()=>{K.scrollLeft=te*K.clientWidth*J-U})};return K.addEventListener("wheel",I,{passive:!1}),()=>K.removeEventListener("wheel",I)},[]);const W=i.useRef(!1);i.useEffect(()=>{const K=x.current,I=n!==null&&n.length>0;!K||k<=0||!I&&!W.current||(W.current=I,lA(K,{peaks:n??[],cover:Math.max(1,a??z),span:z,trackW:k*j,scrollX:N,viewW:k}))},[n,a,z,j,k,N,R]),i.useEffect(()=>{const K=h.current;if(!K||j<=1||p.current||k<=0)return;const I=r/z*k*j;(I<K.scrollLeft||I>K.scrollLeft+k)&&(K.scrollLeft=Math.max(0,I-k*.1))},[r,j,z,k]);const Z=K=>{if(K.button!==0)return;v();const I=K.target,H=I.closest(".ms-subtl-cue"),de=H?e.find(U=>U.id===H.dataset.cue):void 0;if(K.currentTarget.setPointerCapture?.(K.pointerId),!de){p.current={kind:"seek"};const U=O(K.clientX);U!==null&&d(U);return}const J=I.closest(".ms-subtl-edge"),se=f.current?.getBoundingClientRect().width??0;p.current={kind:J?J.classList.contains("ms-start")?"start":"end":"move",id:de.id,x0:K.clientX,start0:de.start,end0:de.end,moved:!1,width:se,held:!1},de.id!==l&&c({type:"select",id:de.id})},A=K=>{const I=p.current;if(!I)return;if((K.buttons&1)===0){_();return}if(I.kind==="seek"){const J=O(K.clientX);J!==null&&d(J);return}if(w.current===I.id)I.held=!0;else if(I.held){p.current=null;return}const H=K.clientX-I.x0;if(!I.moved&&Math.abs(H)<rA||!I.width)return;I.moved=!0;const de=Math.round(H/I.width*z);I.kind==="start"?c({type:"times",id:I.id,start:I.start0+de,drag:!0}):I.kind==="end"?c({type:"times",id:I.id,end:I.end0+de,drag:!0}):c({type:"times",id:I.id,start:I.start0+de,end:I.end0+de,drag:!0})},L=K=>{const I=p.current;if(p.current=null,!I||I.kind==="seek")return;if(I.moved){c({type:"endDrag"});return}const H=O(K.clientX);H!==null&&d(H)},_=()=>{const K=p.current;p.current=null,K&&K.kind!=="seek"&&K.moved&&c({type:"endDrag"})},X=l!==null&&e.some(K=>K.id===l)?l:e[0]?.id??null,ae=i.useMemo(()=>e.map((K,I)=>{const H=se=>U=>{if(U.metaKey||U.ctrlKey||U.altKey||U.key!=="ArrowLeft"&&U.key!=="ArrowRight")return;U.preventDefault(),U.stopPropagation();const te=`${K.id}:${se}`;g.current!==te?y.current():b.current&&(clearTimeout(b.current),b.current=null),g.current=te;const G=(U.key==="ArrowRight"?1:-1)*(U.shiftKey?nA:tA);c(se==="start"?{type:"times",id:K.id,start:Math.max(0,K.start+G),drag:!0}:{type:"times",id:K.id,end:K.end+G,drag:!0})},de=se=>{se.key!=="ArrowLeft"&&se.key!=="ArrowRight"||g.current===null||(b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{b.current=null,y.current()},aA))},J=se=>{const U=se==="start"?K.start:K.end;return s.jsx("span",{className:le("ms-subtl-edge",se==="start"?"ms-start":"ms-end"),role:"slider",tabIndex:K.id===X?0:-1,"aria-label":se==="start"?u.start({n:I+1}):u.end({n:I+1}),"aria-valuemin":0,"aria-valuemax":z,"aria-valuenow":U,"aria-valuetext":Ql(U),onKeyDown:H(se),onKeyUp:de,onBlur:()=>y.current()})};return s.jsxs("div",{className:le("ms-subtl-cue",K.id===l&&"ms-on"),"data-cue":K.id,style:{left:`${K.start/z*100}%`,width:`${Math.max(0,K.end-K.start)/z*100}%`},children:[J("start"),s.jsx("span",{className:"ms-subtl-text","aria-hidden":"true",children:K.text.split(`
|
|
34
|
+
`)[0]}),J("end")]},K.id)}),[e,l,X,z,c,u]);return s.jsxs("section",{className:"ms-subs-timeline","aria-label":u.timeline,children:[s.jsxs("div",{className:"ms-subtl-head",children:[s.jsx("span",{className:"ms-subtl-hint",children:u.timelineHint({mod:Pt()?"⌘":"Ctrl"})}),n===null?s.jsx("span",{className:"ms-subtl-loading",role:"status",children:u.waveformLoading}):null,j>1?s.jsx("span",{className:"ms-subtl-zoom",children:`${Math.round(j*10)/10}×`}):null]}),s.jsx("div",{ref:h,className:"ms-subtl-view",children:s.jsxs("div",{ref:f,className:"ms-subtl-track",style:{width:`${j*100}%`},onPointerDown:Z,onPointerMove:A,onPointerUp:L,onPointerCancel:_,onLostPointerCapture:_,children:[s.jsx("canvas",{ref:x,className:"ms-subtl-wave","aria-hidden":"true",style:{left:N,width:k||"100%"}}),ae,s.jsx("span",{className:"ms-subtl-playhead","aria-hidden":"true",style:{left:`${Ad(r/z,0,1)*100}%`}})]})})]})}const oA=800,Xp=6e4,Nu=e=>JSON.stringify([e.id,e.start,e.end,e.text,e.edited??null,e.source?.text??null,e.words?.map(t=>[t.start,t.end,t.text])??null]),Ea=e=>JSON.stringify(e.map(Nu)),Ld=(e,t)=>t!==void 0&&Nu(e)===Nu(t);function cA(e,t,n,a){const r=new Map(e.map(p=>[p.id,p])),l=new Set(t.map(p=>p.id));let o=t.filter(p=>!Ld(p,r.get(p.id)));a&&o.length>0&&(o=Ey(o,[...n]));const c=new Set(o.map(p=>p.id)),d=[],m=new Set;for(const p of n){const g=r.get(p.id),b=Ld(p,g);if(!(b&&!l.has(p.id))){if(c.has(p.id)){if(g&&(b||p.edited))continue;m.add(p.id)}d.push(p)}}const u=new Set([...d,...o].map(p=>p.id));let h=0;const f=o.map(p=>{if(!m.has(p.id))return p;do h++;while(u.has(`u${h}`));return u.add(`u${h}`),{...p,id:`u${h}`}}),x=d.filter(p=>p.edited||Ld(p,r.get(p.id))||!f.some(g=>p.start<g.end&&p.end>g.start));return[...f,...x]}function dA(e,t,n,a,r){const[l,o]=i.useState("saved"),[c,d]=i.useState(!1),[,m]=i.useState(0),u=i.useRef({slug:e,creative:t,lang:n});u.current={slug:e,creative:t,lang:n};const h=i.useRef(a);h.current=a;const f=i.useRef(r.dispatch);f.current=r.dispatch;const x=i.useRef(r.hash);x.current=r.hash;const p=i.useRef(r.fingerprint??null);p.current=r.fingerprint??null;const g=i.useRef(a.dirty?null:r.hash),b=i.useRef(r.fingerprint??null),v=i.useRef({cues:a.cues,text:Ea(a.cues)}),y=i.useRef(a.cues),w=i.useRef(null),j=i.useRef(0),S=i.useRef(null),k=i.useRef(!0),E=i.useRef(!1),N=i.useRef(Promise.resolve()),C=i.useRef([]),R=()=>{const L=C.current;C.current=[];for(const _ of L)_()},P=()=>Ea(h.current.cues)!==v.current.text,z=async()=>{const{slug:L,creative:_,lang:X}=u.current;let ae;try{ae=await q.subtitleSet(L,_,X)}catch{o("error");return}const K=ae.set.timing?.fingerprint??null,I=cA(v.current.cues,h.current.cues,ae.set.cues,K!==b.current).sort(Ua);S.current&&(clearTimeout(S.current),S.current=null),g.current=ae.hash,b.current=K;const H=[...ae.set.cues].sort(Ua);v.current={cues:H,text:Ea(H)};const de=Ea(I)!==v.current.text;if((!k.current||E.current)&&de){const J={baseHash:ae.hash,cues:I},se=new TextEncoder().encode(JSON.stringify(J)).length<=Xp;try{const U=await(se?q.saveSubtitleSet(L,_,X,J,{keepalive:!0}):q.saveSubtitleSet(L,_,X,J));g.current=U.hash,v.current={cues:I,text:Ea(I)}}catch{}}w.current=Ea(I),k.current&&(d(!0),o(de?"conflict":"saved"),f.current({type:"load",cues:I,durationMs:h.current.durationMs,lang:h.current.lang}))},O=async L=>{if(w.current!==null)return;if(!P()){o(de=>de==="saving"?"saved":de);return}if(g.current===null)return;const{slug:_,creative:X,lang:ae}=u.current,K=h.current.cues,I={baseHash:g.current,cues:K},H=L&&new TextEncoder().encode(JSON.stringify(I)).length<=Xp;try{const de=await(H?q.saveSubtitleSet(_,X,ae,I,{keepalive:!0}):q.saveSubtitleSet(_,X,ae,I));g.current=de.hash,v.current={cues:K,text:Ea(K)},o(P()?"saving":"saved")}catch(de){de instanceof lt&&de.status===409?await z():o("error")}},T=i.useCallback(L=>{S.current&&(clearTimeout(S.current),S.current=null),j.current++;const _=N.current.then(()=>O(L)).finally(()=>{--j.current===0&&m(X=>X+1)});return N.current=_,_},[]);i.useEffect(()=>{if(a.cues===y.current)return;y.current=a.cues;const L=Ea(a.cues);if(w.current!==null)if(a.dirty?a.past.length>0&&Ea(a.past[0])===w.current:L===w.current){if(w.current=null,R(),!a.dirty){L!==v.current.text?T(!1):o(X=>X==="conflict"?"saved":X);return}}else{if(a.dirty)return;w.current=null,R(),v.current={cues:a.cues,text:L},g.current=x.current,b.current=p.current;return}else if(!a.dirty){v.current={cues:a.cues,text:L},g.current=x.current,b.current=p.current;return}if(d(!1),S.current&&(clearTimeout(S.current),S.current=null),L===v.current.text){o(_=>_==="saving"?"saved":_);return}o("saving"),S.current=setTimeout(()=>{S.current=null,T(!1)},oA)},[a.cues,a.dirty,a.past,T]),i.useEffect(()=>{const L=()=>{E.current=!0,T(!0)};return window.addEventListener("beforeunload",L),window.addEventListener("pagehide",L),k.current=!0,()=>{window.removeEventListener("beforeunload",L),window.removeEventListener("pagehide",L),k.current=!1,T(!1),R()}},[T]);const W=i.useCallback(async()=>{for(let L=0;L<5&&(await T(!1),!(w.current===null||!k.current));L++)await new Promise(_=>{C.current.push(_)});for(let L=null;L!==N.current;)L=N.current,await L;return k.current&&w.current===null&&!P()},[T]),Z=i.useCallback(L=>j.current===0&&S.current===null&&w.current===null&&g.current!==null&&Ea(L)===v.current.text,[]),A=i.useCallback(async()=>{if(!await W())throw new Error("not saved");const{slug:L,creative:_,lang:X}=u.current;let ae=null;j.current++;const K=N.current.then(async()=>{if(g.current!==null)try{const I=await q.subtitleTimingChecked(L,_,X,{baseHash:g.current});g.current=I.hash,b.current=I.timing.fingerprint}catch(I){ae=I}}).finally(()=>{--j.current===0&&m(I=>I+1)});if(N.current=K,await K,ae)throw ae},[W]);return{status:l,notice:c,flush:W,isSaved:Z,timingChecked:A}}const uA=["srt","vtt"],mA=150,Zp=e=>Pt()?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey,Jp=e=>JSON.stringify(e),Yp=e=>{e?.scrollIntoView?.({block:"nearest"})};function hA(e){const t=`${e.slug}/${e.creative}`,[n]=i.useState(()=>mN(t));return i.useEffect(()=>{vg(t)},[t]),s.jsx(Jb.Provider,{value:n,children:s.jsx(fA,{...e})})}function fA({slug:e,creative:t,lang:n}){const a=V(),r=i.useContext(Mn),l=r?.live.creativeTicks[`${e}/${t}`]??0,[o,c]=i.useState(null),[d,m]=i.useState(null);i.useEffect(()=>{let x=!0;return Promise.resolve().then(()=>q.getCreative(e,t)).then(p=>{x&&(IR(e,t,p.subtitles??[]),c(p),m(null))},p=>{x&&m(pe(p))}),()=>{x=!1}},[e,t,l]);const u=o?.subtitles??[],h=o?.creative.brief??null,f=n??Xm(u,Ht(h??{})?.primary);return f&&o&&!u.some(x=>x.lang===f)?s.jsx(pA,{slug:e,creative:t,lang:f,detail:o,jobs:r?.live.jobs??{}}):f&&!o&&!d?s.jsxs("main",{className:"ms-subs",children:[s.jsx(tc,{slug:e,creative:t}),s.jsx("div",{className:"ms-subs-empty ms-subs-alone",children:s.jsx(Ts,{size:16,label:a.subtitles.loading})})]}):f?s.jsx(xA,{slug:e,creative:t,lang:f,detail:o,tick:l},`${e}/${t}/${f}`):s.jsxs("main",{className:"ms-subs",children:[s.jsx(tc,{slug:e,creative:t}),s.jsx("div",{className:"ms-subs-empty ms-subs-alone",children:d?s.jsx("p",{role:"alert",children:a.subtitles.loadFailed({detail:d})}):o?s.jsx("p",{children:a.subtitles.noSets}):s.jsx(Ts,{size:16,label:a.subtitles.loading})})]})}const Jb=i.createContext(null);function tc({slug:e,creative:t,langs:n,children:a}){const r=V(),l=i.useContext(Jb);return s.jsxs("header",{className:"ms-subs-head",children:[s.jsxs($,{variant:"ghost",size:"sm",onClick:()=>{Bs(l??es.creative(e,t))},children:[s.jsx(F,{name:"back",size:13}),l?r.subtitles.backToEditor:r.subtitles.backToCreative]}),s.jsx("h1",{className:"ms-subs-title",children:r.subtitles.editorTitle}),n,s.jsx("span",{className:"ms-subs-grow"}),a]})}function pA({slug:e,creative:t,lang:n,detail:a,jobs:r}){const l=V().subtitles,o=rs(),c=OR(r,e,t,n),d=xb(n,o),m=u=>Bs(es.subtitles(e,t,u??void 0));return s.jsxs("main",{className:"ms-subs","data-lang":n,children:[s.jsx(tc,{slug:e,creative:t,langs:s.jsx(gb,{slug:e,creative:t,lang:n,sets:a.subtitles??[],brief:a.creative.brief,edited:0,onSwitch:m,onLeave:m})}),s.jsx("div",{className:"ms-subs-empty ms-subs-alone",children:c&&(c.state==="queued"||c.state==="running")?s.jsxs("p",{role:"status",children:[s.jsx(Ts,{decorative:!0,size:14})," ",l.pendingLanguage({lang:d})]}):c?.state==="failed"?s.jsx("p",{role:"alert",children:l.pendingFailed({lang:d,detail:c.error??""})}):s.jsx("p",{children:l.noLanguage({lang:d})})})]})}function xA({slug:e,creative:t,lang:n,detail:a,tick:r}){const l=V(),o=l.subtitles,c=i.useRef(null),d=i.useRef(null),[m,u]=i.useReducer(Wp,void 0,HP),[h,f]=i.useState(null),[x,p]=i.useState(null),[g,b]=i.useState(null),[v,y]=i.useState(!1),[w,j]=i.useState(null),[S,k]=i.useState(0),E=dA(e,t,n,m,{hash:h,fingerprint:x,dispatch:u}),[N,C]=i.useState(null),R=i.useRef(!1),P=i.useRef(0),z=i.useRef(m.cues);z.current=m.cues,i.useEffect(()=>{let ge=!0;return Promise.resolve().then(()=>q.subtitleSet(e,t,n)).then(({set:qe,hash:Ye})=>{ge&&(j(null),b(qe.timing.format),C({cues:[...qe.cues].sort(Ua),hash:Ye,fingerprint:qe.timing.fingerprint}))},qe=>{ge&&!v&&j(pe(qe))}),()=>{ge=!1}},[e,t,n,r,S]),i.useEffect(()=>{if(N){if(C(null),v){if(!E.isSaved(m.cues)){R.current=!0;return}if(R.current=!1,Jp(N.cues)===Jp(m.cues))return}y(!0),f(N.hash),p(N.fingerprint),u({type:"load",cues:N.cues,durationMs:Math.max(P.current,...N.cues.map(ge=>ge.end)),lang:n})}},[N]),i.useEffect(()=>{R.current&&E.isSaved(z.current)&&(R.current=!1,k(ge=>ge+1))});const O=a?.versions.at(-1)??null,T=O?.compositions??[],W=g===null?null:T.find(ge=>ge.format===g)?.format??T.find(ge=>!ge.followsFormat)?.format??null,Z=el({slug:e,creative:t,n:O?.n??null,format:W??"",enabled:O!==null&&W!==null}),A=Z.state.kind==="ready"?Z.state.session:null,[L,_]=i.useState(null),X=zb(L,`${O?.n??0}/${W??""}`,A?.fps??30),[ae,K]=i.useState(null),I=O!==null&&W!==null?{n:O.n,format:W}:null;i.useEffect(()=>{if(K(null),!I)return;let ge=!0;return Promise.resolve().then(()=>q.getEditorComposition(e,t,I.n,I.format)).then(qe=>{ge&&K(Ty(qe.composition))},()=>{ge&&K(!1)}),()=>{ge=!1}},[e,t,I?.n,I?.format]);const H=A?Math.round(A.duration*1e3):0,de=i.useMemo(()=>ae?XP(n,m.cues,H):void 0,[ae,n,m.cues,H]),J=SA(de,mA);i.useEffect(()=>{A&&(P.current=Math.round(A.duration*1e3),u({type:"duration",ms:Math.max(P.current,...z.current.map(ge=>ge.end))}))},[A]);const se=i.useRef(m.cues);se.current=m.cues;const U=i.useSyncExternalStore(X.clock.subscribe,()=>Pd(se.current,Math.round(X.clock.get().time*1e3))?.id??null),te=U?m.cues.find(ge=>ge.id===U)??null:null,G=i.useMemo(()=>GP(m.cues,m.lang),[m.cues,m.lang]),[re,oe]=i.useState(null),[Ne,Q]=i.useState(!1),Re=O?.n??null,Ue=a?.subtitles?.find(ge=>ge.lang===n),is=Ue?.timing.locale;i.useEffect(()=>{if(Re===null)return;let ge=!0;return oe(null),Q(!1),(is?q.subtitleWaveform(e,t,Re,is):q.subtitleWaveform(e,t,Re)).then(qe=>{ge&&(oe(qe),Q(!0))},()=>{ge&&Q(!0)}),()=>{ge=!1}},[e,t,Re,is]);const Qe=i.useCallback(ge=>X.seek(ge/1e3),[X]),gs=ge=>d.current?.querySelector(ZP(ge));i.useEffect(()=>{!U||!X.playing||d.current?.contains(document.activeElement)||Yp(gs(U))},[U,X.playing]),i.useEffect(()=>{m.selected&&Yp(gs(m.selected))},[m.selected]);const As=i.useCallback(ge=>{u({type:"select",id:ge.id});const qe=Math.round(X.clock.get().time*1e3);qe>=ge.start&&qe<ge.end||X.seek(ge.start/1e3)},[X]),hs=ge=>{const qe=m.cues,Ye=qe.findIndex(et=>et.id===m.selected);let Ls;if(Ye>=0)Ls=qe[Math.min(qe.length-1,Math.max(0,Ye+ge))];else{const et=Math.round(X.clock.get().time*1e3);Ls=Pd(qe,et)??(ge===1?qe.find(bs=>bs.start>=et)??qe.at(-1):[...qe].reverse().find(bs=>bs.end<=et)??qe[0])}Ls&&(u({type:"select",id:Ls.id}),X.seek(Ls.start/1e3))},[Oe,be]=i.useState(null),[Fe,je]=i.useState(!1),he=()=>{const ge=Math.round(X.clock.get().time*1e3),qe=m.cues.find(Ye=>Ye.id===m.selected);for(const Ye of[ge,Pd(m.cues,ge)?.end,qe?.end]){if(Ye===void 0)continue;const Ls={type:"add",at:Ye},et=Wp(m,Ls);if(et!==m){u(Ls),be(et.selected),je(!1);return}}je(!0)};i.useEffect(()=>{if(!Oe)return;const ge=gs(Oe)?.querySelector("textarea");ge&&(be(null),ge.focus(),ge.select())},[Oe,m.cues]),i.useEffect(()=>{je(!1)},[U,m.cues]);const Ke=ge=>!ge.isComposing&&!ge.altKey&&!pr(ge);i.useEffect(()=>{const ge=(Ye,Ls)=>Ye.key.toLowerCase()===Ls,qe=Ye=>{if(Ye.defaultPrevented||!Ke(Ye)||!Ou(c.current)||Ye.target instanceof Element&&Ye.target.closest(".ms-subs-find"))return;const Ls=Zp(Ye)&&!Ye.shiftKey&&ge(Ye,"z"),et=Zp(Ye)&&Ye.shiftKey&&ge(Ye,"z")||!Pt()&&Ye.ctrlKey&&!Ye.metaKey&&!Ye.shiftKey&&ge(Ye,"y");!Ls&&!et||(Ye.preventDefault(),u({type:Ls?"undo":"redo"}))};return window.addEventListener("keydown",qe),()=>window.removeEventListener("keydown",qe)},[]);const we=ge=>Ke(ge)&&ui(ge)&&!ge.shiftKey&&!jr(ge);qt(c,ge=>we(ge)&&(ge.key===" "||ge.code==="Space")&&!za(ge,".ms-subs-play"),()=>X.toggle()),qt(c,ge=>we(ge)&&(ge.key==="ArrowDown"||ge.key==="ArrowUp"),ge=>hs(ge.key==="ArrowDown"?1:-1)),qt(c,ge=>we(ge)&&ge.key==="Enter"&&!za(ge)&&m.selected!==null,()=>{const ge=m.selected?gs(m.selected)?.querySelector("textarea"):null;ge&&(ge.focus(),ge.setSelectionRange(ge.value.length,ge.value.length))});const[ze,We]=i.useState(null),[Rs,us]=i.useState(null),fs=async ge=>{We(ge),us(null);try{if(!await E.flush()){us(o.downloadFailed({detail:o.notSaved}));return}kv(await q.subtitleFile(e,t,n,ge),`${t}.${n}.${ge}`)}catch(qe){us(o.downloadFailed({detail:pe(qe)}))}finally{We(null)}},[fe,Ge]=i.useState(!1),De=A?A.width/A.height:16/9,os=l.web.render.playerFrame({label:a&&O?`${a.creative.title} v${O.n}`:t}),Ze=Z.state.kind==="loading"||Z.state.kind==="busy"||Z.state.kind==="idle"&&W!==null,vs=Z.state.kind==="legacy"||v&&a!==null&&W===null,Le=Ue?.timingChanged===!0,ne=Ue?.origin==="translation",[Ee,Ce]=i.useState(!1),Xe=async ge=>{if(ge!==n){if(Ce(!1),!await E.flush()){Ce(!0);return}Bs(es.subtitles(e,t,ge))}},ue=i.useMemo(()=>m.cues.filter(ge=>ge.edited).length,[m.cues]),xe=gA(e,t,ne?Ue?.sourceLang??null:null,r),Be=i.useMemo(()=>vA(m.cues,xe,!Le),[m.cues,xe,Le]),_e=jA(e,t,n,E.flush);return s.jsxs("main",{ref:c,className:"ms-subs","data-lang":n,children:[s.jsxs(tc,{slug:e,creative:t,langs:s.jsx(gb,{slug:e,creative:t,lang:n,sets:a?.subtitles??[],brief:a?.creative.brief??null,edited:ue,onSwitch:Xe,onLeave:ge=>Bs(es.subtitles(e,t,ge??void 0))}),children:[s.jsx(NA,{status:E.status,notice:E.notice,retry:()=>{E.flush()}}),ne?null:s.jsx(wA,{slug:e,creative:t}),s.jsxs("span",{className:"ms-subs-undo",children:[s.jsx(pn,{label:o.undo,children:s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":o.undo,disabled:m.past.length===0,onClick:()=>u({type:"undo"}),children:s.jsx(F,{name:"undo",size:14})})}),s.jsx(pn,{label:o.redo,children:s.jsx($,{size:"sm",variant:"ghost",icon:!0,"aria-label":o.redo,disabled:m.future.length===0,onClick:()=>u({type:"redo"}),children:s.jsx(F,{name:"redo",size:14})})})]}),uA.map(ge=>s.jsxs($,{size:"sm",variant:"outline",disabled:ze!==null||!v,"aria-busy":ze===ge||void 0,"aria-label":o.download({ext:`.${ge}`}),onClick:()=>{fs(ge)},children:[s.jsx(F,{name:"download",size:13}),".",ge]},ge)),ne&&(Be.size>0||Be.actionable>0)?s.jsx(yA,{count:Be.actionable,busy:_e.busy,run:()=>{_e.run()}}):null,Rs?s.jsx("span",{className:"ms-subs-head-error",role:"alert",children:Rs}):null,Ee?s.jsx("span",{className:"ms-subs-head-error",role:"alert",children:o.notSavedSwitch}):null,_e.note?s.jsx("span",{className:_e.note.ok?"ms-subs-head-note":"ms-subs-head-error",role:_e.note.ok?"status":"alert",children:_e.note.text}):null]}),Le?s.jsxs("section",{className:"ms-subs-banner","aria-label":o.timingChanged,children:[s.jsx(F,{name:"warn",size:14}),s.jsx("span",{className:"ms-subs-banner-text",children:ne?o.translationTimingChanged:o.timingChanged}),ne?null:s.jsx(Nv,{slug:e,creative:t,lang:n,className:"ms-subs-banner-note"}),ne?null:s.jsx(kA,{mark:E.timingChecked})]}):null,s.jsxs("section",{className:"ms-subs-player","aria-label":os,children:[s.jsx("div",{className:"ms-subs-stage",children:s.jsxs("div",{className:"ms-subs-frame",style:{"--ar":De},children:[A?s.jsx(di,{session:A,title:os,onMedia:_,onStall:Z.stalled,onShowing:Z.showing,...J?{subtitles:J}:{}}):null,Ze?s.jsx("span",{className:"ms-cplayer-state",role:"status",children:Z.state.kind==="busy"?l.web.render.busy:l.web.render.loading}):null,Z.state.kind==="failed"?s.jsxs("span",{className:"ms-subs-frame-note",role:"alert",children:[s.jsx("span",{children:l.web.render.failed({detail:Z.state.message})}),s.jsxs($,{size:"sm",variant:"outline",onClick:Z.retry,children:[s.jsx(F,{name:"refresh",size:12}),l.web.render.retry]})]}):null,vs?s.jsx("span",{className:"ms-subs-frame-note",children:o.noPreview}):null,te&&ae===!1?s.jsx("p",{className:"ms-subs-caption","data-testid":"subs-caption",children:s.jsx("span",{className:le(te.id===m.selected&&"ms-on"),children:te.text})}):null]})}),s.jsxs("div",{className:"ms-subs-transport",children:[s.jsx($,{size:"sm",variant:"ghost",icon:!0,className:"ms-subs-play","aria-label":X.playing?o.pause:o.play,disabled:!X.ready,onClick:X.toggle,children:s.jsx(F,{name:X.playing?"pause":"play",size:14})}),s.jsx(EA,{clock:X.clock,duration:X.duration})]})]}),s.jsxs("section",{className:"ms-subs-side","aria-label":o.lines,children:[s.jsxs("div",{className:"ms-subs-side-head",children:[s.jsxs("h2",{className:"ms-subs-side-title",children:[o.lines,s.jsx("span",{className:"ms-subs-count",children:m.cues.length})]}),s.jsx("span",{className:"ms-subs-grow"}),s.jsx(pn,{label:o.findReplace,children:s.jsx($,{size:"sm",variant:fe?"default":"ghost",icon:!0,"aria-label":o.findReplace,"aria-expanded":fe,onClick:()=>Ge(ge=>!ge),children:s.jsx(F,{name:"search",size:14})})}),s.jsx($,{size:"sm",variant:"outline",disabled:!v,onClick:he,children:o.addLine})]}),Fe?s.jsx("p",{className:"ms-subs-note",role:"status",children:o.noRoom}):null,ne&&Be.missing.length>0?s.jsx(bA,{lines:Be.missing,sourceLang:Ue?.sourceLang}):null,fe?s.jsx(QP,{cues:m.cues,dispatch:u}):null,s.jsx("div",{ref:d,className:"ms-subs-scroll",children:w?s.jsxs("div",{className:"ms-subs-empty",children:[s.jsx("p",{role:"alert",children:o.loadFailed({detail:w})}),s.jsxs($,{size:"sm",variant:"outline",onClick:()=>k(ge=>ge+1),children:[s.jsx(F,{name:"refresh",size:12}),o.retry]})]}):v?s.jsx(JP,{cues:m.cues,lang:m.lang,warnings:G,selected:m.selected,now:U,dispatch:u,onPick:As,...ne?{sources:Be.rows,sourceLang:Ue?.sourceLang,retranslating:_e.busy,onRetranslate:ge=>{_e.run([ge])}}:{}}):s.jsx("div",{className:"ms-subs-empty",children:s.jsx(Ts,{size:16,label:o.loading})})})]}),s.jsx(CA,{clock:X.clock,cues:m.cues,durationMs:m.durationMs,peaks:Ne?re?.peaks??[]:null,peaksMs:re?.durationMs,selected:m.selected,dragging:m.dragging,dispatch:u,onSeek:Qe})]})}function gA(e,t,n,a){const[r,l]=i.useState(null);return i.useEffect(()=>{l(null)},[n]),i.useEffect(()=>{if(!n)return;let o=!0;return Promise.resolve().then(()=>q.subtitleSet(e,t,n)).then(({set:c})=>{o&&l(c.cues)},()=>{}),()=>{o=!1}},[e,t,n,a]),r}function vA(e,t,n=!0){const a=new Map;if(!t)return{rows:a,size:0,actionable:0,missing:[]};const r=new Set(Ry({cues:[...e]},{cues:[...t]})),l=My(e,t,n);let o=0;for(const d of e){if(!d.source)continue;if(!r.has(d.id)){a.set(d.id,{state:"current",text:d.source.text});continue}const m=$y(d,t);if(!m){a.set(d.id,{state:"gone",text:d.source.text});continue}a.set(d.id,{state:"changed",text:m.text}),d.edited||o++}let c=o+l.length;if(!n){const d=Fy(e,t,!1),m=new Set(e.filter(u=>u.edited).map(u=>d.get(u.id)?.id));c=t.filter(u=>!m.has(u.id)).length}return{rows:a,size:r.size,actionable:c,missing:l}}function bA({lines:e,sourceLang:t}){const n=V().subtitles;return s.jsxs("section",{className:"ms-subs-missing","aria-label":n.missingTranslation,children:[s.jsxs("p",{className:"ms-subs-missing-head",children:[s.jsx(F,{name:"warn",size:12}),n.missingTranslation,s.jsx("span",{className:"ms-subs-count",children:e.length})]}),s.jsx("p",{className:"ms-subs-missing-hint",children:n.missingTranslationHint}),s.jsx("ul",{className:"ms-subs-missing-list",children:e.map(a=>s.jsxs("li",{children:[s.jsx("span",{className:"ms-subs-missing-at",children:Ql(a.start)}),s.jsx("span",{className:"ms-subs-missing-text",lang:t,children:a.text})]},a.id))})]})}function jA(e,t,n,a){const r=V().subtitles,[l,o]=i.useState(!1),[c,d]=i.useState(null);return{busy:l,note:c,run:async u=>{o(!0),d(null);try{if(!await a()){d({ok:!1,text:r.retranslateFailed({detail:r.notSaved})});return}const h=await q.retranslateSubtitles(e,t,n,u?{ids:u}:{}),f=h.dropped?` ${r.retranslateDropped({count:h.dropped})}`:"";d({ok:!0,text:h.job?`${r.retranslateStarted}${f}`:f.trim()})}catch(h){const f=h instanceof lt&&h.dropped?` ${r.retranslateDropped({count:h.dropped})}`:"",x=h instanceof lt&&h.code==="subtitles-nothing-stale";d({ok:!1,text:`${x?pe(h):r.retranslateFailed({detail:pe(h)})}${f}`})}finally{o(!1)}}}}function yA({count:e,busy:t,run:n}){const a=V().subtitles;return s.jsx(pn,{label:a.retranslateAllHint,children:s.jsxs($,{size:"sm",variant:"outline",disabled:t,"aria-busy":t||void 0,onClick:n,children:[s.jsx(F,{name:"refresh",size:13}),a.retranslateAll,e>0?s.jsx("span",{className:"ms-subs-count",children:e}):null]})})}function wA({slug:e,creative:t}){const n=V().subtitles,a=rs(),r=i.useRef(null),[l,o]=i.useState(!1),[c,d]=i.useState("auto"),[m,u]=i.useState(!1),[h,f]=i.useState(null),x=i.useMemo(()=>[{value:"auto",label:n.redoAuto},...ei.map(g=>({value:g.tag,label:Js(g.tag,a)})).sort((g,b)=>g.label.localeCompare(b.label,a))],[n,a]),p=async()=>{u(!0),f(null);try{await q.startSubtitles(e,t,{mode:"new",...c!=="auto"?{lang:c}:{}}),o(!1),f({ok:!0,text:n.redoStarted})}catch(g){f({ok:!1,text:n.redoFailed({detail:pe(g)})})}finally{u(!1)}};return s.jsxs(s.Fragment,{children:[s.jsx($,{ref:r,size:"sm",variant:"ghost","aria-haspopup":"dialog","aria-expanded":l,onClick:()=>{f(null),o(g=>!g)},children:n.redoMenu}),s.jsx(ot,{open:l,onClose:()=>o(!1),anchor:r,placement:"bottom-end",width:300,label:n.redoTitle,children:s.jsxs("div",{className:"ms-subs-redo",children:[s.jsx("b",{className:"ms-subs-redo-title",children:n.redoTitle}),s.jsx(At,{label:n.redoLanguage,value:c,options:x,onChange:d}),s.jsx("p",{className:"ms-subs-redo-hint",children:n.redoHint}),s.jsx("p",{className:"ms-subs-redo-hint",children:n.redoOtherLanguage}),h&&!h.ok?s.jsx("p",{className:"ms-subs-redo-error",role:"alert",children:h.text}):null,s.jsx($,{size:"sm",variant:"ink",loading:m,onClick:()=>{p()},children:n.redoStart})]})}),h?.ok?s.jsx("span",{className:"ms-subs-head-note",role:"status",children:h.text}):null]})}function kA({mark:e}){const t=V().subtitles,[n,a]=i.useState(!1),[r,l]=i.useState(null),o=async()=>{a(!0),l(null);try{await e()}catch(c){l(t.timingCheckedFailed({detail:pe(c)}))}finally{a(!1)}};return s.jsxs(s.Fragment,{children:[s.jsx(pn,{label:t.timingCheckedHint,children:s.jsxs($,{size:"sm",variant:"ghost",disabled:n,"aria-busy":n||void 0,onClick:()=>{o()},children:[s.jsx(F,{name:"check",size:13}),t.timingChecked]})}),r?s.jsx("span",{role:"alert",className:"ms-subs-banner-note",children:r}):null]})}function NA({status:e,notice:t,retry:n}){const a=V().subtitles,r=e==="conflict"||e==="saved"&&t;return s.jsxs("span",{className:"ms-subs-save",children:[s.jsxs("span",{role:"status","aria-label":a.saveState,className:le("ms-subs-save-text",`ms-${r?"conflict":e}`),children:[e==="saving"?s.jsx(Ts,{decorative:!0,size:11}):s.jsx(F,{name:e==="saved"&&!r?"check":"warn",size:12}),e==="saving"?a.saving:r?a.savedElsewhere:e==="saved"?a.saved:a.saveFailed]}),e==="error"?s.jsx($,{size:"sm",variant:"ghost",onClick:n,children:a.retry}):null]})}function SA(e,t){const[n,a]=i.useState(e);return i.useEffect(()=>{const r=window.setTimeout(()=>a(e),t);return()=>window.clearTimeout(r)},[e,t]),n}function CA({clock:e,...t}){const{time:n}=Jn(e);return s.jsx(iA,{...t,time:n*1e3})}function EA({clock:e,duration:t}){const{time:n}=Jn(e);return s.jsxs("span",{className:"ms-subs-tc",children:[Ql(n*1e3),s.jsxs("span",{className:"ms-subs-tc-total",children:[" / ",Ql(t*1e3)]})]})}const TA=e=>e.flatMap(t=>t.ok?[{slug:t.slug,name:t.project.name,icon:t.icon??null}]:[]);function RA(e,t){const[n,a]=i.useState(null),[r,l]=i.useState({}),o=i.useRef(new Set),c=i.useRef(!0);i.useEffect(()=>(c.current=!0,()=>{c.current=!1}),[]);const d=i.useCallback(()=>{Promise.resolve().then(()=>q.listProjects()).then(h=>{c.current&&a(TA(h))}).catch(()=>{})},[]),m=i.useCallback(h=>{Promise.resolve().then(()=>q.listCreatives(h)).then(f=>{c.current&&l(x=>({...x,[h]:f.flatMap(p=>p.ok?[p]:[])}))}).catch(()=>{})},[]);i.useEffect(()=>{d()},[d,e]),i.useEffect(()=>{e&&(o.current.add(e),m(e))},[m,e,t]);const u=i.useCallback(()=>{d();for(const h of o.current)m(h)},[d,m]);return i.useMemo(()=>({projects:n,creatives:r,refresh:u}),[n,r,u])}const MA=50,$A=[["creatives","grid"],["brand","drop"],["assets","image"],["references","link"],["settings","gear"]],Qp=e=>e.normalize("NFD").replace(new RegExp("\\p{M}","gu"),"").toLowerCase();function FA(e,t){const n=Qp(`${e.label} ${e.sub??""}`);return Qp(t).split(/\s+/).filter(Boolean).every(a=>n.includes(a))}function PA({open:e,onClose:t,catalog:n,route:a}){const r=V(),l=r.web.shell,o=i.useId(),[c,d]=i.useState(""),[m,u]=i.useState(0),h=i.useRef(null);i.useEffect(()=>{e&&(d(""),u(0),n.refresh())},[e]);const f=S=>n.projects?.find(k=>k.slug===S)?.name??S,x=zx(a),p=i.useMemo(()=>{const S=[{id:"p:projects",group:"pages",label:l.projects,icon:"grid",hash:es.projects()},{id:"p:settings",group:"pages",label:l.settings,icon:"gear",hash:es.settings("general")},{id:"p:system",group:"pages",label:l.systemCheck,icon:"shield",hash:es.settings("system")},{id:"p:welcome",group:"pages",label:l.replaySetup,icon:"sparkle",hash:es.welcome()}];if(x){const N=l.palette.inProject({project:f(x)});for(const[C,R]of $A)S.push({id:`p:${x}:${C}`,group:"pages",label:r.web.project.tabs[C],sub:N,icon:R,hash:es.project(x,C)});S.push({id:`p:${x}:new`,group:"pages",label:l.newCreative,sub:N,icon:"plus",hash:es.newCreative(x)})}const k=(n.projects??[]).map(N=>({id:`pr:${N.slug}`,group:"projects",label:N.name,sub:N.slug,icon:"folder",hash:es.project(N.slug)})),E=Object.entries(n.creatives).flatMap(([N,C])=>C.map(R=>({id:`c:${N}/${R.slug}`,group:"creatives",label:R.title||R.slug,sub:l.palette.inProject({project:f(N)}),icon:"video",hash:es.creative(N,R.slug)})));return[...S,...k,...E]},[n.projects,n.creatives,x,r]),g=i.useMemo(()=>p.filter(S=>FA(S,c)).slice(0,MA),[p,c]),b=Math.min(m,Math.max(0,g.length-1)),v=S=>`${o}-o${S}`;i.useEffect(()=>{u(0)},[c]),i.useLayoutEffect(()=>{h.current?.querySelector(`[data-index="${b}"]`)?.scrollIntoView?.({block:"nearest"})},[b]);const y=S=>{S&&(t(),Bs(S.hash))},w=S=>{if(S.key==="ArrowDown"||S.key==="ArrowUp"){if(S.preventDefault(),!g.length)return;const k=S.key==="ArrowDown"?1:-1;u((b+k+g.length)%g.length)}else S.key==="Enter"&&(S.preventDefault(),y(g[b]))},j=[["pages",l.palette.pages],["projects",l.palette.projects],["creatives",l.palette.creatives]];return s.jsx(rt,{open:e,onClose:t,label:l.palette.label,width:600,children:s.jsxs("div",{className:"ms-palette",children:[s.jsxs("label",{className:"ms-palette-field",children:[s.jsx(F,{name:"search",size:16}),s.jsx("input",{className:"ms-palette-input",role:"combobox","aria-label":l.palette.label,"aria-expanded":g.length>0,"aria-controls":`${o}-list`,"aria-autocomplete":"list","aria-activedescendant":g.length?v(b):void 0,placeholder:l.palette.placeholder,value:c,autoFocus:!0,spellCheck:!1,autoComplete:"off",onChange:S=>d(S.target.value),onKeyDown:w}),s.jsx("kbd",{className:"ms-kbd",children:"esc"})]}),s.jsx("div",{ref:h,id:`${o}-list`,role:"listbox","aria-label":l.palette.label,className:"ms-palette-list",children:g.length===0?s.jsx("div",{className:"ms-palette-empty",role:"presentation",children:l.palette.empty({query:c.trim()})}):j.map(([S,k])=>{const E=g.map((N,C)=>({item:N,i:C})).filter(({item:N})=>N.group===S);return E.length?s.jsxs("div",{role:"presentation",className:"ms-palette-group",children:[s.jsx("span",{className:"ms-cap ms-palette-cap",role:"presentation",children:k}),E.map(({item:N,i:C})=>s.jsxs("div",{id:v(C),"data-index":C,role:"option","aria-selected":C===b,className:le("ms-option","ms-palette-row",C===b&&"ms-active"),onMouseMove:()=>{C!==b&&u(C)},onClick:()=>y(N),children:[s.jsx(F,{name:N.icon,size:14}),s.jsx("span",{className:"ms-option-label",children:N.label}),N.sub?s.jsx("span",{className:"ms-palette-sub",children:N.sub}):null,C===b?s.jsx(F,{name:"forward",size:12,className:"ms-palette-go"}):null]},N.id))]},S):null})}),s.jsx("div",{className:"ms-palette-foot","aria-hidden":"true",children:l.palette.hint})]})})}function ex(){const e=_u();return e?s.jsx("div",{className:le("ms-drag-strip",e),"aria-hidden":"true"}):null}const AA=["creatives","brand","assets","references","settings"];function LA(){const e=V();return s.jsxs("a",{className:"ms-logo-link",href:es.projects(),"aria-label":e.web.shell.home,children:[s.jsx(Hr,{variant:"horizontal",height:22,className:"ms-logo-full",decorative:!0}),s.jsx(Hr,{variant:"mark",height:24,className:"ms-logo-mark",decorative:!0})]})}function IA(){const e=V(),{openPalette:t}=ol();return s.jsxs("button",{type:"button",className:"ms-search",onClick:t,"aria-keyshortcuts":Pt()?"Meta+K":"Control+K",children:[s.jsx(F,{name:"search",size:14}),s.jsx("span",{className:"ms-search-text",children:e.web.shell.search}),s.jsx("kbd",{className:"ms-kbd",children:Pt()?"⌘K":"Ctrl K"})]})}function zA(){const e=V(),{live:t,activity:n}=ol(),a=Object.values(t.jobs).filter(r=>r.state==="queued"||r.state==="running").length;return a?s.jsxs($,{variant:"ghost",className:"ms-running",onClick:()=>n.show("running"),children:[s.jsx(Ts,{decorative:!0}),e.web.shell.running({count:a})]}):null}function OA(){const e=V(),{live:t,activity:n,catalog:a}=ol(),r=i.useRef(null),l=i.useRef(null),o=Object.keys(t.approvals).length,c=i.useRef(o);i.useLayoutEffect(()=>{o>c.current&&ti(l.current??r.current),c.current=o},[o]);const d=(m,u)=>{const h=a.projects?.find(x=>x.slug===m)?.name??m;if(!u)return h;const f=a.creatives[m]?.find(x=>x.slug===u)?.title||u;return`${h} · ${f}`};return s.jsxs(s.Fragment,{children:[s.jsxs("button",{ref:r,type:"button",className:le("ms-btn ms-icon ms-bell",!n.open&&"ms-ghost"),"aria-label":e.web.shell.bell({count:o}),"aria-haspopup":"dialog","aria-expanded":n.open,onClick:n.toggle,children:[s.jsx(F,{name:"bell",size:16}),o?s.jsx("span",{ref:l,className:"ms-count ms-bell-count","aria-hidden":"true",children:o>99?"99+":o}):null]}),s.jsx(ot,{open:n.open,onClose:n.hide,anchor:r,placement:"bottom-end",width:440,children:s.jsx(dS,{live:t,initialTab:n.tab,request:n.seq,where:d})})]})}function DA(){const{live:e}=ol();return s.jsx(Qw,{tokens:Fg(e)})}function BA(){const t=V().web.shell,n=i.useRef(null),[a,r]=i.useState(!1),l=o=>{r(!1),Bs(o)};return s.jsxs(s.Fragment,{children:[s.jsx("button",{ref:n,type:"button",className:"ms-avatar","aria-label":t.account,"aria-haspopup":"dialog","aria-expanded":a,onClick:()=>r(o=>!o),children:ai("Motion Studio")}),s.jsxs(ot,{open:a,onClose:()=>r(!1),anchor:n,placement:"bottom-end",width:220,children:[s.jsx(dn,{"data-row":"",icon:"gear",onClick:()=>l(es.settings("general")),children:t.settings}),s.jsx(dn,{"data-row":"",icon:"shield",onClick:()=>l(es.settings("system")),children:t.systemCheck}),s.jsx("div",{className:"ms-pop-sep",role:"separator"}),s.jsx(dn,{"data-row":"",icon:"sparkle",onClick:()=>l(es.welcome()),children:t.replaySetup})]})]})}function ah({running:e=!0}){return s.jsxs("div",{className:"ms-topbar-end",children:[e?s.jsx(zA,{}):null,s.jsx(OA,{}),s.jsx(DA,{}),s.jsx(BA,{})]})}function sx({title:e}){return s.jsxs(s.Fragment,{children:[s.jsx("a",{className:"ms-brand-logo",href:es.projects(),children:s.jsx(Hr,{variant:"horizontal",height:22})}),e?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ms-faint","aria-hidden":"true",children:"/"}),s.jsx("b",{className:"ms-topbar-title",children:e})]}):null,s.jsx("div",{className:"ms-topbar-center",children:s.jsx(IA,{})}),s.jsx(ah,{})]})}function UA({slug:e,tab:t}){const n=V();return s.jsxs(s.Fragment,{children:[s.jsx(LA,{}),s.jsx(yP,{slug:e}),s.jsx("nav",{className:"ms-tabs ms-bar ms-topbar-tabs","aria-label":n.web.project.sections,children:AA.map(a=>s.jsx("a",{href:es.project(e,a),className:le("ms-tab",t===a&&"ms-on"),"aria-current":t===a?"page":void 0,children:n.web.project.tabs[a]},a))}),s.jsx("div",{className:"ms-grow"}),s.jsx(ah,{})]})}const _A=e=>zv("title",e),qA=e=>zv("end",e);function VA(e){const t=lc(e).replace(/^\d{4}-\d{2}-\d{2}-?/,"").replace(/-+/g," ").trim();return t?t[0].toLocaleUpperCase()+t.slice(1):e}const KA=e=>e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey;function Id({links:e,current:t,slots:n}){const a=V();return s.jsxs(s.Fragment,{children:[s.jsxs("nav",{className:"ms-crumbs","aria-label":a.web.shell.breadcrumb,children:[s.jsx("a",{className:"ms-logo-link ms-bar-home",href:es.projects(),"aria-label":a.web.shell.home,title:a.web.shell.home,children:s.jsx(Hr,{variant:"mark",height:22,decorative:!0})}),e.map((r,l)=>s.jsxs("span",{className:le("ms-crumb",r.className),children:[l>0?s.jsx("span",{className:"ms-crumb-sep","aria-hidden":"true",children:"/"}):null,s.jsxs("a",{className:"ms-crumb-link",href:r.hash,title:r.title??r.label,onClick:r.onOpen?o=>{KA(o.nativeEvent)&&(o.preventDefault(),r.onOpen())}:void 0,children:[s.jsx("span",{className:"ms-crumb-text",children:r.label}),r.tag?s.jsx("span",{className:"ms-crumb-tag",children:r.tag}):null]})]},l)),t!==void 0?s.jsxs("span",{className:"ms-crumb ms-last",children:[s.jsx("span",{className:"ms-crumb-sep","aria-hidden":"true",children:"/"}),s.jsx("b",{"aria-current":"page",children:t})]}):null,n?s.jsx("span",{className:"ms-bar-slot ms-bar-title",ref:_A}):null]}),s.jsx("div",{className:"ms-grow"}),n?s.jsx("span",{className:"ms-bar-slot ms-bar-end",ref:qA}):null,n?s.jsx("span",{className:"ms-bar-sep","aria-hidden":"true"}):null,s.jsx(ah,{running:!1})]})}function WA(e){switch(e.name){case"project":return`project:${e.slug}`;case"new-creative":case"creative":case"format":return`creative:${e.slug}`;default:return"global"}}function HA(){const e=V(),{route:t,catalog:n}=ol(),{owner:a,crumb:r}=Ov(),l=_u(),o=i.useRef(null),c=WA(t),d=i.useRef(c);i.useLayoutEffect(()=>{d.current!==c&&(d.current=c,Gs(o.current,{y:0,ms:qs.s}))},[c]);const m=g=>n.projects?.find(b=>b.slug===g)?.name??g,u=(g,b)=>{const v=n.creatives[g];return v?.find(y=>y.slug===b)?.title||v?.find(y=>y.slug===lc(b))?.title||null};let h,f=!1;const x=g=>({label:m(g),hash:es.project(g),className:"ms-crumb-project"}),p=(g,b)=>{const v=r&&r.key===a?r:null,y=v?.title||u(g,b)||VA(b),w=v?.variant??/~([a-z])$/.exec(b)?.[1]?.toUpperCase()??null;return{label:y,title:w?`${y} · ${w}`:y,tag:w,hash:es.creative(g,b),onOpen:v?.open??null,className:"ms-crumb-creative"}};switch(t.name){case"project":h=s.jsx(UA,{slug:t.slug,tab:t.tab});break;case"new-creative":h=s.jsx(Id,{links:[x(t.slug)],current:e.web.shell.newCreative,slots:!0});break;case"creative":{const g=a===Zn(t);h=s.jsx(Id,{links:[x(t.slug)],slots:!0,current:g?void 0:p(t.slug,t.creative).label});break}case"format":{const g=a===Zn(t);f=g,h=s.jsx(Id,{links:[x(t.slug),p(t.slug,t.creative)],slots:!0,current:g?void 0:s.jsx("span",{className:"ms-mono",children:t.format})});break}case"settings":h=s.jsx(sx,{title:e.web.shell.settings});break;default:h=s.jsx(sx,{})}return s.jsx("header",{ref:o,className:le("ms-topbar",f&&"ms-bar-fv",l),children:h})}function GA(e,t){const n=(a,r)=>a.name==="creative"&&r.name==="format"&&a.slug===r.slug&&a.creative===r.creative;if(n(e,t)||n(t,e)||e.name==="new-creative"&&t.name==="creative"&&e.slug===t.slug&&dN(`brief-panel:${t.slug}/${t.creative}`))return"shared"}function XA(e,t,n={}){const a=V(),r=i.useRef(n.onReview);r.current=n.onReview;const l=n.snapshot;i.useEffect(()=>{document.title=e>0?`(${e}) ${Kc}`:Kc,Sh(e)},[e]),i.useEffect(()=>()=>{document.title=Kc,Sh(0)},[]);const o=i.useRef(null),c=i.useRef(t);c.current=t,i.useEffect(()=>mw(()=>{const u=c.current,h=u.find(f=>f.id===o.current)??[...u].sort((f,x)=>f.createdAt.localeCompare(x.createdAt))[0];h&&r.current?.(h)}),[]);const d=i.useRef(new Map),m=i.useRef(l);i.useEffect(()=>{const u=l!==void 0&&l!==m.current;m.current=l;const h=new Set(t.map(y=>y.id));for(const[y,w]of d.current)h.has(y)||(w!==null&&Pe.dismiss(w),d.current.delete(y));const f=u&&d.current.size===0,x=t.filter(y=>!d.current.has(y.id));if(x.length===0)return;const p=Bx(),g=x[0],b={label:a.web.shell.attention.review,run:()=>r.current?.(g)};let v=null;if(f)p&&(v=Pe.show(a.web.shell.attention.waiting({count:x.length}),{sticky:!0,action:b}));else{const y=x.length===1?g.title:a.web.shell.attention.many({count:x.length});p&&(To({title:a.web.app.approvalNotificationTitle,body:y}),o.current=g.id,v=Pe.show(y,{sticky:!0,action:b}))}for(const y of x)d.current.set(y.id,y===g?v:null)},[t,l,a])}function ZA(e){const t=V(),n=i.useRef(new Set);i.useEffect(()=>{for(const a of Object.values(e))if(a.kind==="creative"){if(a.state==="queued"||a.state==="running"){n.current.add(a.id);continue}n.current.delete(a.id)&&a.state==="succeeded"&&_x()&&_d()&&To({title:t.web.app.readyNotificationTitle,body:a.label})}},[e,t])}function JA(e){const t=V(),n=i.useRef(new Set);i.useEffect(()=>{const a=t.web.exportUi;for(const r of Object.values(e)){if(r.kind!=="export")continue;if(r.state==="queued"||r.state==="running"){n.current.add(r.id);continue}if(!n.current.delete(r.id))continue;const l=r.export,o=r.state==="failed"?Ml.takeRetry(r.id):(Ml.forget(r.id),null);if(r.state==="succeeded"&&l){const c=l.files??[],d=(l.skipped?.length??0)+(l.excluded?.length??0),m=a.doneToast({count:c.length,folder:l.destination}),u=d>0?`${m}. ${a.doneLeftOut({count:d})}`:m,h=xt(),f=h?{label:Pt()?a.showInFinder:a.showInFolder,run:()=>{Du(h,l.destination,c).catch(()=>{})}}:void 0;Pe.show(u,{tone:d>0?"neutral":"ok",...d>0?{sticky:!0}:{},...f?{action:f}:{}}),_d()&&To({title:a.doneNotification,body:u})}else if(r.state==="failed"&&l?.refusal?.code==="localization-needs-force"){if(Ml.watched(r.id))continue;const c=a.needsForceToast({list:(l.refusal.problems??[]).join(", ")}),d=Gg(r),m=o?{label:t.web.languages.renderAnyway,run:()=>{o().catch(u=>Pe.show(a.failed({detail:pe(u)})))}}:d?{label:t.web.shell.activity.open,run:()=>Bs(d)}:void 0;Pe.show(c,{sticky:!0,...m?{action:m}:{}}),_d()&&To({title:a.doneNotification,body:c})}else r.state==="failed"&&Pe.show(a.failed({detail:r.error??t.web.jobState.failed}))}},[e,t])}function YA(e){const t=Object.values(e).filter(n=>(n.kind==="render"||n.kind==="export")&&(n.state==="queued"||n.state==="running")).length;i.useEffect(()=>{Ch(t)},[t]),i.useEffect(()=>()=>Ch(0),[])}function QA(e){i.useEffect(()=>{Eh(e)},[e]),i.useEffect(()=>()=>Eh(0),[]),i.useEffect(()=>{if(e===0)return;const t=n=>{n.preventDefault(),n.returnValue=""};return addEventListener("beforeunload",t),()=>removeEventListener("beforeunload",t)},[e])}function zd(e){const t=document.documentElement;e==="system"?t.removeAttribute("data-theme"):t.setAttribute("data-theme",e)}const eL=5e3;function sL(){const[e,t]=i.useReducer(iC,Nm);return i.useEffect(()=>{let n=null,a=!1,r,l,o=0,c;const d=(h=!1)=>{const f=++o,x=new Date,p=Mg(x);clearTimeout(c),Promise.resolve().then(()=>q.getUsage({from:l0(x)})).then(g=>{!a&&f===o&&t({type:"usage-today",day:p,tokens:_n(g.total.tokens),billing:g.billing})}).catch(()=>{!a&&f===o&&!h&&(c=setTimeout(()=>d(!0),eL))}),clearTimeout(l),l=setTimeout(()=>d(),i0(x)+1e3)},m=()=>{const h=location.protocol==="https:"?"wss":"ws",f=Pu(),x=new WebSocket(`${h}://${location.host}/api/events${f?`?t=${encodeURIComponent(f)}`:""}`);n=x,x.onmessage=p=>{let g;try{g=JSON.parse(String(p.data))}catch{return}t(g),g.type==="snapshot"&&d()},x.onerror=()=>x.close(),x.onclose=()=>{!a&&n===x&&Ex(f),!a&&n===x&&!Tx()&&(r=setTimeout(m,1e3))}};m();const u=Dy(()=>{if(a)return;clearTimeout(r);const h=n;n=null,h?.close(),m()});return()=>{a=!0,u(),clearTimeout(r),clearTimeout(l),clearTimeout(c),n?.close()}},[]),e}function tx(){const e=location.hash||"#/",t=ew(e);return t?(history.replaceState(history.state,"",t),t):e}function tL(){const[e,t]=i.useState(tx),n=i.useRef(e);return n.current=e,i.useEffect(()=>{const a=()=>{const r=tx();if(r!==n.current&&MM(r)){history.replaceState(history.state,"",n.current);return}t(r)};return addEventListener("hashchange",a),()=>removeEventListener("hashchange",a)},[]),e}function nL(){const e=sL(),[t,n]=i.useState(null);i.useEffect(()=>{e.language&&n(e.language)},[e.language]);const a=t??e.language,r=a?.locale??bh();return s.jsxs(Py,{locale:r,children:[s.jsx(aL,{live:e,language:a?.setting??"system",systemLocale:a?.systemLocale??bh(),onLanguage:n}),s.jsx(Xw,{})]})}function aL({live:e,language:t,systemLocale:n,onLanguage:a}){const r=rs(),[l,o]=i.useState(null),[c,d]=i.useState(null),[m,u]=i.useState(null),h=tL(),f=i.useMemo(()=>Ix(h),[h]),x=By(),[p,g]=i.useState({open:!1,tab:null,seq:0}),b=i.useMemo(()=>Object.values(e.approvals),[e.approvals]),v=i.useCallback(_=>{const X=_.creativeSlug?es.creative(_.projectSlug,_.creativeSlug):null;X&&location.hash!==X?Bs(X):g(ae=>({open:!0,tab:"needs",seq:ae.seq+1}))},[]);XA(b.length,b,{onReview:v,snapshot:e.snapshots??0}),ZA(e.jobs),JA(e.jobs),YA(e.jobs),i.useEffect(()=>jR(),[]),QA(TM());const[y,w]=i.useState(!1),[j,S]=i.useState(0),k=i.useCallback(()=>{w(!0);const _=X=>u(pe(X));q.getDoctor().then(X=>{o(X),u(null),S(ae=>ae+1)}).catch(_).finally(()=>w(!1)),q.getWorkspace().then(X=>{d(X),X.settings&&zd(X.settings.theme)}).catch(_)},[]);i.useEffect(k,[k]);const E=i.useRef(r);i.useEffect(()=>{if(E.current===r)return;E.current=r;let _=!1;return q.getDoctor().then(X=>{_||o(X)}).catch(()=>{}),()=>{_=!0}},[r]);const N=i.useRef(x);i.useEffect(()=>{N.current&&!x&&k(),N.current=x},[x,k]);const C=l!==null&&c!==null,R=l?.some(_=>_.required&&!_.ok)??!0,P=!c||!c.settings||R,[z,O]=i.useState(!1);i.useEffect(()=>{C&&P&&O(!0)},[C,P]);const T=i.useCallback(_=>{O(!1),location.hash!==_&&Bs(_)},[]),W=z||C&&P||!!m,Z=i.useMemo(()=>W&&f.name!=="welcome"?rL:f,[W,f]),A=i.useCallback(_=>{zd(_.settings.theme),d({path:_.path,settings:_.settings,error:null}),q.getDoctor().then(o).catch(()=>{})},[]),L={checks:l,checking:y,checksRun:j,loadError:m,workspace:c,canLeave:C&&!P,language:t,systemLocale:n,onLanguage:a,onRecheck:k,onWorkspace:A,onFinish:T};return x?s.jsxs(s.Fragment,{children:[s.jsx(ex,{}),s.jsx(aP,{})]}):Z.name!=="welcome"&&(!l||!c?.settings)?s.jsxs(s.Fragment,{children:[s.jsx(ex,{}),s.jsx("div",{className:"ms-boot",children:s.jsx(Ts,{size:18})})]}):s.jsx(zu.Provider,{value:c?.path??null,children:s.jsx(lL,{route:Z,live:e,settings:c?.settings??null,checks:l,activity:p,setActivity:g,language:t,systemLocale:n,onLanguage:a,setup:L,onSettings:_=>{zd(_.theme),d(X=>X&&{...X,settings:_})}})})}const rL={name:"welcome"};function lL({route:e,live:t,settings:n,checks:a,activity:r,setActivity:l,language:o,systemLocale:c,onLanguage:d,onSettings:m,setup:u}){const h=zx(e),f=h?(t.projectTicks[h]??0)+Object.entries(t.creativeTicks).filter(([k])=>k.startsWith(`${h}/`)).reduce((k,[,E])=>k+E,0):0,x=RA(h,f),[p,g]=i.useState(!1),b=e.name==="welcome",v=i.useRef(b);i.useEffect(()=>{v.current=b},[b]);const y=i.useRef(b);i.useEffect(()=>{y.current&&!b&&x.refresh(),y.current=b},[b,x]),i.useEffect(()=>{const k=E=>{if(v.current||E.isComposing||E.repeat||E.altKey||E.shiftKey||E.key.toLowerCase()!=="k")return;(Pt()?E.metaKey&&!E.ctrlKey:E.ctrlKey&&!E.metaKey)&&(E.preventDefault(),g(C=>!C))};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[]);const w=Zn(e);i.useEffect(()=>{l(k=>k.open?{...k,open:!1}:k)},[w,l]);const j=i.useMemo(()=>({route:e,live:t,catalog:x,activity:{...r,show:k=>l(E=>({open:!0,tab:k??null,seq:E.seq+1})),hide:()=>l(k=>({...k,open:!1})),toggle:()=>l(k=>({open:!k.open,tab:null,seq:k.seq}))},openPalette:()=>g(!0)}),[e,t,x,r,l]),S=k=>{switch(k.name){case"projects":return s.jsx(xP,{live:t});case"project":return s.jsx(iL,{route:k,live:t,settings:n,checks:a,onSettings:m});case"new-creative":return s.jsx(ZF,{slug:k.slug,live:t},k.slug);case"creative":return s.jsx(wR,{slug:k.slug,creative:k.creative,live:t,exportNamePattern:n?.exportNamePattern,onSettings:m},`${k.slug}/${k.creative}`);case"format":return s.jsx(hF,{slug:k.slug,creative:k.creative,format:k.format,live:t,exportNamePattern:n?.exportNamePattern,onSettings:m},`${k.slug}/${k.creative}/${k.format}`);case"subtitles":return s.jsx(hA,{slug:k.slug,creative:k.creative,...k.lang?{lang:k.lang}:{}},`${k.slug}/${k.creative}`);case"settings":return n?s.jsx(_k,{section:k.section,settings:n,checks:a,checking:!!u.checking,checksRun:u.checksRun??0,loadError:u.loadError??null,onRecheck:u.onRecheck,language:o,systemLocale:c,onLanguage:d,onSettings:m}):null;case"welcome":return s.jsx(Sk,{...u,step:k.step})}};return s.jsx(Mn.Provider,{value:j,children:s.jsxs(MS,{live:t,enabled:!b,children:[s.jsxs("div",{className:b?"ms-app ms-bare":"ms-app",children:[b?null:s.jsx(HA,{}),s.jsx("div",{className:"ms-main",children:s.jsx(Px,{route:e,keyOf:Zn,depthOf:tw,modeOf:GA,render:S})})]}),s.jsx(PA,{open:p,onClose:()=>g(!1),catalog:x,route:e})]})})}function iL({route:e,...t}){return s.jsx(Px,{route:e,keyOf:n=>n.tab,soft:!0,render:n=>s.jsx(oL,{route:n,...t})})}function oL({route:{slug:e,tab:t},live:n,settings:a,checks:r,onSettings:l}){switch(t){case"creatives":return s.jsx(lP,{slug:e,live:n},e);case"brand":return s.jsx(mE,{slug:e,live:n},e);case"assets":return s.jsx(c1,{slug:e,live:n},e);case"references":return s.jsx(zP,{slug:e,live:n},e);case"settings":return a?s.jsx(EP,{slug:e,live:n,settings:a,checks:r,onSettings:l},e):null}}Nx();zy();uk();sj.createRoot(document.getElementById("root")).render(s.jsx(i.StrictMode,{children:s.jsx(nL,{})}));
|