@reshotdev/screenshot 0.0.1-beta.4 → 0.0.1-beta.6

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.
@@ -504,4 +504,4 @@ Error generating stack: `+a.message+`
504
504
  *
505
505
  * This source code is licensed under the ISC license.
506
506
  * See the LICENSE file in the root directory of this source tree.
507
- */const l0=H("ZoomOut",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]);function sm(e){var t,s,r="";if(typeof e=="string"||typeof e=="number")r+=e;else if(typeof e=="object")if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(s=sm(e[t]))&&(r&&(r+=" "),r+=s)}else for(s in e)e[s]&&(r&&(r+=" "),r+=s);return r}function nm(){for(var e,t,s=0,r="",i=arguments.length;s<i;s++)(e=arguments[s])&&(t=sm(e))&&(r&&(r+=" "),r+=t);return r}const td="-",c0=e=>{const t=u0(e),{conflictingClassGroups:s,conflictingClassGroupModifiers:r}=e;return{getClassGroupId:o=>{const l=o.split(td);return l[0]===""&&l.length!==1&&l.shift(),rm(l,t)||d0(o)},getConflictingClassGroupIds:(o,l)=>{const c=s[o]||[];return l&&r[o]?[...c,...r[o]]:c}}},rm=(e,t)=>{var o;if(e.length===0)return t.classGroupId;const s=e[0],r=t.nextPart.get(s),i=r?rm(e.slice(1),r):void 0;if(i)return i;if(t.validators.length===0)return;const a=e.join(td);return(o=t.validators.find(({validator:l})=>l(a)))==null?void 0:o.classGroupId},lh=/^\[(.+)\]$/,d0=e=>{if(lh.test(e)){const t=lh.exec(e)[1],s=t==null?void 0:t.substring(0,t.indexOf(":"));if(s)return"arbitrary.."+s}},u0=e=>{const{theme:t,prefix:s}=e,r={nextPart:new Map,validators:[]};return f0(Object.entries(e.classGroups),s).forEach(([a,o])=>{Kl(o,r,a,t)}),r},Kl=(e,t,s,r)=>{e.forEach(i=>{if(typeof i=="string"){const a=i===""?t:ch(t,i);a.classGroupId=s;return}if(typeof i=="function"){if(h0(i)){Kl(i(r),t,s,r);return}t.validators.push({validator:i,classGroupId:s});return}Object.entries(i).forEach(([a,o])=>{Kl(o,ch(t,a),s,r)})})},ch=(e,t)=>{let s=e;return t.split(td).forEach(r=>{s.nextPart.has(r)||s.nextPart.set(r,{nextPart:new Map,validators:[]}),s=s.nextPart.get(r)}),s},h0=e=>e.isThemeGetter,f0=(e,t)=>t?e.map(([s,r])=>{const i=r.map(a=>typeof a=="string"?t+a:typeof a=="object"?Object.fromEntries(Object.entries(a).map(([o,l])=>[t+o,l])):a);return[s,i]}):e,p0=e=>{if(e<1)return{get:()=>{},set:()=>{}};let t=0,s=new Map,r=new Map;const i=(a,o)=>{s.set(a,o),t++,t>e&&(t=0,r=s,s=new Map)};return{get(a){let o=s.get(a);if(o!==void 0)return o;if((o=r.get(a))!==void 0)return i(a,o),o},set(a,o){s.has(a)?s.set(a,o):i(a,o)}}},im="!",m0=e=>{const{separator:t,experimentalParseClassName:s}=e,r=t.length===1,i=t[0],a=t.length,o=l=>{const c=[];let u=0,m=0,f;for(let j=0;j<l.length;j++){let p=l[j];if(u===0){if(p===i&&(r||l.slice(j,j+a)===t)){c.push(l.slice(m,j)),m=j+a;continue}if(p==="/"){f=j;continue}}p==="["?u++:p==="]"&&u--}const g=c.length===0?l:l.substring(m),R=g.startsWith(im),k=R?g.substring(1):g,C=f&&f>m?f-m:void 0;return{modifiers:c,hasImportantModifier:R,baseClassName:k,maybePostfixModifierPosition:C}};return s?l=>s({className:l,parseClassName:o}):o},x0=e=>{if(e.length<=1)return e;const t=[];let s=[];return e.forEach(r=>{r[0]==="["?(t.push(...s.sort(),r),s=[]):s.push(r)}),t.push(...s.sort()),t},g0=e=>({cache:p0(e.cacheSize),parseClassName:m0(e),...c0(e)}),v0=/\s+/,y0=(e,t)=>{const{parseClassName:s,getClassGroupId:r,getConflictingClassGroupIds:i}=t,a=[],o=e.trim().split(v0);let l="";for(let c=o.length-1;c>=0;c-=1){const u=o[c],{modifiers:m,hasImportantModifier:f,baseClassName:g,maybePostfixModifierPosition:R}=s(u);let k=!!R,C=r(k?g.substring(0,R):g);if(!C){if(!k){l=u+(l.length>0?" "+l:l);continue}if(C=r(g),!C){l=u+(l.length>0?" "+l:l);continue}k=!1}const j=x0(m).join(":"),p=f?j+im:j,h=p+C;if(a.includes(h))continue;a.push(h);const x=i(C,k);for(let w=0;w<x.length;++w){const N=x[w];a.push(p+N)}l=u+(l.length>0?" "+l:l)}return l};function j0(){let e=0,t,s,r="";for(;e<arguments.length;)(t=arguments[e++])&&(s=am(t))&&(r&&(r+=" "),r+=s);return r}const am=e=>{if(typeof e=="string")return e;let t,s="";for(let r=0;r<e.length;r++)e[r]&&(t=am(e[r]))&&(s&&(s+=" "),s+=t);return s};function w0(e,...t){let s,r,i,a=o;function o(c){const u=t.reduce((m,f)=>f(m),e());return s=g0(u),r=s.cache.get,i=s.cache.set,a=l,l(c)}function l(c){const u=r(c);if(u)return u;const m=y0(c,s);return i(c,m),m}return function(){return a(j0.apply(null,arguments))}}const ze=e=>{const t=s=>s[e]||[];return t.isThemeGetter=!0,t},om=/^\[(?:([a-z-]+):)?(.+)\]$/i,N0=/^\d+\/\d+$/,k0=new Set(["px","full","screen"]),b0=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,S0=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,C0=/^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/,E0=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,R0=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,ys=e=>er(e)||k0.has(e)||N0.test(e),Ms=e=>gr(e,"length",M0),er=e=>!!e&&!Number.isNaN(Number(e)),Uo=e=>gr(e,"number",er),Er=e=>!!e&&Number.isInteger(Number(e)),_0=e=>e.endsWith("%")&&er(e.slice(0,-1)),xe=e=>om.test(e),Is=e=>b0.test(e),P0=new Set(["length","size","percentage"]),T0=e=>gr(e,P0,lm),A0=e=>gr(e,"position",lm),O0=new Set(["image","url"]),z0=e=>gr(e,O0,D0),L0=e=>gr(e,"",I0),Rr=()=>!0,gr=(e,t,s)=>{const r=om.exec(e);return r?r[1]?typeof t=="string"?r[1]===t:t.has(r[1]):s(r[2]):!1},M0=e=>S0.test(e)&&!C0.test(e),lm=()=>!1,I0=e=>E0.test(e),D0=e=>R0.test(e),F0=()=>{const e=ze("colors"),t=ze("spacing"),s=ze("blur"),r=ze("brightness"),i=ze("borderColor"),a=ze("borderRadius"),o=ze("borderSpacing"),l=ze("borderWidth"),c=ze("contrast"),u=ze("grayscale"),m=ze("hueRotate"),f=ze("invert"),g=ze("gap"),R=ze("gradientColorStops"),k=ze("gradientColorStopPositions"),C=ze("inset"),j=ze("margin"),p=ze("opacity"),h=ze("padding"),x=ze("saturate"),w=ze("scale"),N=ze("sepia"),S=ze("skew"),P=ze("space"),b=ze("translate"),O=()=>["auto","contain","none"],D=()=>["auto","hidden","clip","visible","scroll"],v=()=>["auto",xe,t],L=()=>[xe,t],V=()=>["",ys,Ms],y=()=>["auto",er,xe],_=()=>["bottom","center","left","left-bottom","left-top","right","right-bottom","right-top","top"],F=()=>["solid","dashed","dotted","double","none"],$=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],E=()=>["start","end","center","between","around","evenly","stretch"],A=()=>["","0",xe],z=()=>["auto","avoid","all","avoid-page","page","left","right","column"],W=()=>[er,xe];return{cacheSize:500,separator:":",theme:{colors:[Rr],spacing:[ys,Ms],blur:["none","",Is,xe],brightness:W(),borderColor:[e],borderRadius:["none","","full",Is,xe],borderSpacing:L(),borderWidth:V(),contrast:W(),grayscale:A(),hueRotate:W(),invert:A(),gap:L(),gradientColorStops:[e],gradientColorStopPositions:[_0,Ms],inset:v(),margin:v(),opacity:W(),padding:L(),saturate:W(),scale:W(),sepia:A(),skew:W(),space:L(),translate:L()},classGroups:{aspect:[{aspect:["auto","square","video",xe]}],container:["container"],columns:[{columns:[Is]}],"break-after":[{"break-after":z()}],"break-before":[{"break-before":z()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:[..._(),xe]}],overflow:[{overflow:D()}],"overflow-x":[{"overflow-x":D()}],"overflow-y":[{"overflow-y":D()}],overscroll:[{overscroll:O()}],"overscroll-x":[{"overscroll-x":O()}],"overscroll-y":[{"overscroll-y":O()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:[C]}],"inset-x":[{"inset-x":[C]}],"inset-y":[{"inset-y":[C]}],start:[{start:[C]}],end:[{end:[C]}],top:[{top:[C]}],right:[{right:[C]}],bottom:[{bottom:[C]}],left:[{left:[C]}],visibility:["visible","invisible","collapse"],z:[{z:["auto",Er,xe]}],basis:[{basis:v()}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["wrap","wrap-reverse","nowrap"]}],flex:[{flex:["1","auto","initial","none",xe]}],grow:[{grow:A()}],shrink:[{shrink:A()}],order:[{order:["first","last","none",Er,xe]}],"grid-cols":[{"grid-cols":[Rr]}],"col-start-end":[{col:["auto",{span:["full",Er,xe]},xe]}],"col-start":[{"col-start":y()}],"col-end":[{"col-end":y()}],"grid-rows":[{"grid-rows":[Rr]}],"row-start-end":[{row:["auto",{span:[Er,xe]},xe]}],"row-start":[{"row-start":y()}],"row-end":[{"row-end":y()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":["auto","min","max","fr",xe]}],"auto-rows":[{"auto-rows":["auto","min","max","fr",xe]}],gap:[{gap:[g]}],"gap-x":[{"gap-x":[g]}],"gap-y":[{"gap-y":[g]}],"justify-content":[{justify:["normal",...E()]}],"justify-items":[{"justify-items":["start","end","center","stretch"]}],"justify-self":[{"justify-self":["auto","start","end","center","stretch"]}],"align-content":[{content:["normal",...E(),"baseline"]}],"align-items":[{items:["start","end","center","baseline","stretch"]}],"align-self":[{self:["auto","start","end","center","stretch","baseline"]}],"place-content":[{"place-content":[...E(),"baseline"]}],"place-items":[{"place-items":["start","end","center","baseline","stretch"]}],"place-self":[{"place-self":["auto","start","end","center","stretch"]}],p:[{p:[h]}],px:[{px:[h]}],py:[{py:[h]}],ps:[{ps:[h]}],pe:[{pe:[h]}],pt:[{pt:[h]}],pr:[{pr:[h]}],pb:[{pb:[h]}],pl:[{pl:[h]}],m:[{m:[j]}],mx:[{mx:[j]}],my:[{my:[j]}],ms:[{ms:[j]}],me:[{me:[j]}],mt:[{mt:[j]}],mr:[{mr:[j]}],mb:[{mb:[j]}],ml:[{ml:[j]}],"space-x":[{"space-x":[P]}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":[P]}],"space-y-reverse":["space-y-reverse"],w:[{w:["auto","min","max","fit","svw","lvw","dvw",xe,t]}],"min-w":[{"min-w":[xe,t,"min","max","fit"]}],"max-w":[{"max-w":[xe,t,"none","full","min","max","fit","prose",{screen:[Is]},Is]}],h:[{h:[xe,t,"auto","min","max","fit","svh","lvh","dvh"]}],"min-h":[{"min-h":[xe,t,"min","max","fit","svh","lvh","dvh"]}],"max-h":[{"max-h":[xe,t,"min","max","fit","svh","lvh","dvh"]}],size:[{size:[xe,t,"auto","min","max","fit"]}],"font-size":[{text:["base",Is,Ms]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:["thin","extralight","light","normal","medium","semibold","bold","extrabold","black",Uo]}],"font-family":[{font:[Rr]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:["tighter","tight","normal","wide","wider","widest",xe]}],"line-clamp":[{"line-clamp":["none",er,Uo]}],leading:[{leading:["none","tight","snug","normal","relaxed","loose",ys,xe]}],"list-image":[{"list-image":["none",xe]}],"list-style-type":[{list:["none","disc","decimal",xe]}],"list-style-position":[{list:["inside","outside"]}],"placeholder-color":[{placeholder:[e]}],"placeholder-opacity":[{"placeholder-opacity":[p]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"text-color":[{text:[e]}],"text-opacity":[{"text-opacity":[p]}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...F(),"wavy"]}],"text-decoration-thickness":[{decoration:["auto","from-font",ys,Ms]}],"underline-offset":[{"underline-offset":["auto",ys,xe]}],"text-decoration-color":[{decoration:[e]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:L()}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",xe]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",xe]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-opacity":[{"bg-opacity":[p]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:[..._(),A0]}],"bg-repeat":[{bg:["no-repeat",{repeat:["","x","y","round","space"]}]}],"bg-size":[{bg:["auto","cover","contain",T0]}],"bg-image":[{bg:["none",{"gradient-to":["t","tr","r","br","b","bl","l","tl"]},z0]}],"bg-color":[{bg:[e]}],"gradient-from-pos":[{from:[k]}],"gradient-via-pos":[{via:[k]}],"gradient-to-pos":[{to:[k]}],"gradient-from":[{from:[R]}],"gradient-via":[{via:[R]}],"gradient-to":[{to:[R]}],rounded:[{rounded:[a]}],"rounded-s":[{"rounded-s":[a]}],"rounded-e":[{"rounded-e":[a]}],"rounded-t":[{"rounded-t":[a]}],"rounded-r":[{"rounded-r":[a]}],"rounded-b":[{"rounded-b":[a]}],"rounded-l":[{"rounded-l":[a]}],"rounded-ss":[{"rounded-ss":[a]}],"rounded-se":[{"rounded-se":[a]}],"rounded-ee":[{"rounded-ee":[a]}],"rounded-es":[{"rounded-es":[a]}],"rounded-tl":[{"rounded-tl":[a]}],"rounded-tr":[{"rounded-tr":[a]}],"rounded-br":[{"rounded-br":[a]}],"rounded-bl":[{"rounded-bl":[a]}],"border-w":[{border:[l]}],"border-w-x":[{"border-x":[l]}],"border-w-y":[{"border-y":[l]}],"border-w-s":[{"border-s":[l]}],"border-w-e":[{"border-e":[l]}],"border-w-t":[{"border-t":[l]}],"border-w-r":[{"border-r":[l]}],"border-w-b":[{"border-b":[l]}],"border-w-l":[{"border-l":[l]}],"border-opacity":[{"border-opacity":[p]}],"border-style":[{border:[...F(),"hidden"]}],"divide-x":[{"divide-x":[l]}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":[l]}],"divide-y-reverse":["divide-y-reverse"],"divide-opacity":[{"divide-opacity":[p]}],"divide-style":[{divide:F()}],"border-color":[{border:[i]}],"border-color-x":[{"border-x":[i]}],"border-color-y":[{"border-y":[i]}],"border-color-s":[{"border-s":[i]}],"border-color-e":[{"border-e":[i]}],"border-color-t":[{"border-t":[i]}],"border-color-r":[{"border-r":[i]}],"border-color-b":[{"border-b":[i]}],"border-color-l":[{"border-l":[i]}],"divide-color":[{divide:[i]}],"outline-style":[{outline:["",...F()]}],"outline-offset":[{"outline-offset":[ys,xe]}],"outline-w":[{outline:[ys,Ms]}],"outline-color":[{outline:[e]}],"ring-w":[{ring:V()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:[e]}],"ring-opacity":[{"ring-opacity":[p]}],"ring-offset-w":[{"ring-offset":[ys,Ms]}],"ring-offset-color":[{"ring-offset":[e]}],shadow:[{shadow:["","inner","none",Is,L0]}],"shadow-color":[{shadow:[Rr]}],opacity:[{opacity:[p]}],"mix-blend":[{"mix-blend":[...$(),"plus-lighter","plus-darker"]}],"bg-blend":[{"bg-blend":$()}],filter:[{filter:["","none"]}],blur:[{blur:[s]}],brightness:[{brightness:[r]}],contrast:[{contrast:[c]}],"drop-shadow":[{"drop-shadow":["","none",Is,xe]}],grayscale:[{grayscale:[u]}],"hue-rotate":[{"hue-rotate":[m]}],invert:[{invert:[f]}],saturate:[{saturate:[x]}],sepia:[{sepia:[N]}],"backdrop-filter":[{"backdrop-filter":["","none"]}],"backdrop-blur":[{"backdrop-blur":[s]}],"backdrop-brightness":[{"backdrop-brightness":[r]}],"backdrop-contrast":[{"backdrop-contrast":[c]}],"backdrop-grayscale":[{"backdrop-grayscale":[u]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[m]}],"backdrop-invert":[{"backdrop-invert":[f]}],"backdrop-opacity":[{"backdrop-opacity":[p]}],"backdrop-saturate":[{"backdrop-saturate":[x]}],"backdrop-sepia":[{"backdrop-sepia":[N]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":[o]}],"border-spacing-x":[{"border-spacing-x":[o]}],"border-spacing-y":[{"border-spacing-y":[o]}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["none","all","","colors","opacity","shadow","transform",xe]}],duration:[{duration:W()}],ease:[{ease:["linear","in","out","in-out",xe]}],delay:[{delay:W()}],animate:[{animate:["none","spin","ping","pulse","bounce",xe]}],transform:[{transform:["","gpu","none"]}],scale:[{scale:[w]}],"scale-x":[{"scale-x":[w]}],"scale-y":[{"scale-y":[w]}],rotate:[{rotate:[Er,xe]}],"translate-x":[{"translate-x":[b]}],"translate-y":[{"translate-y":[b]}],"skew-x":[{"skew-x":[S]}],"skew-y":[{"skew-y":[S]}],"transform-origin":[{origin:["center","top","top-right","right","bottom-right","bottom","bottom-left","left","top-left",xe]}],accent:[{accent:["auto",e]}],appearance:[{appearance:["none","auto"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",xe]}],"caret-color":[{caret:[e]}],"pointer-events":[{"pointer-events":["none","auto"]}],resize:[{resize:["none","y","x",""]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scroll-m":[{"scroll-m":L()}],"scroll-mx":[{"scroll-mx":L()}],"scroll-my":[{"scroll-my":L()}],"scroll-ms":[{"scroll-ms":L()}],"scroll-me":[{"scroll-me":L()}],"scroll-mt":[{"scroll-mt":L()}],"scroll-mr":[{"scroll-mr":L()}],"scroll-mb":[{"scroll-mb":L()}],"scroll-ml":[{"scroll-ml":L()}],"scroll-p":[{"scroll-p":L()}],"scroll-px":[{"scroll-px":L()}],"scroll-py":[{"scroll-py":L()}],"scroll-ps":[{"scroll-ps":L()}],"scroll-pe":[{"scroll-pe":L()}],"scroll-pt":[{"scroll-pt":L()}],"scroll-pr":[{"scroll-pr":L()}],"scroll-pb":[{"scroll-pb":L()}],"scroll-pl":[{"scroll-pl":L()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",xe]}],fill:[{fill:[e,"none"]}],"stroke-w":[{stroke:[ys,Ms,Uo]}],stroke:[{stroke:[e,"none"]}],sr:["sr-only","not-sr-only"],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","start","end","top","right","bottom","left"],"inset-x":["right","left"],"inset-y":["top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pt","pr","pb","pl"],px:["pr","pl"],py:["pt","pb"],m:["mx","my","ms","me","mt","mr","mb","ml"],mx:["mr","ml"],my:["mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-s","border-w-e","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-r","border-w-l"],"border-w-y":["border-w-t","border-w-b"],"border-color":["border-color-s","border-color-e","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-r","border-color-l"],"border-color-y":["border-color-t","border-color-b"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-mr","scroll-ml"],"scroll-my":["scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-pr","scroll-pl"],"scroll-py":["scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]}}},$0=w0(F0);function Y(...e){return $0(nm(e))}const cm=d.createContext(void 0);function V0({children:e}){const[t,s]=d.useState([]),r=d.useCallback(a=>{const o=Math.random().toString(36).substring(2,9),l={...a,id:o};s(u=>[...u,l]);const c=a.duration??5e3;c>0&&setTimeout(()=>{s(u=>u.filter(m=>m.id!==o))},c)},[]),i=d.useCallback(a=>{s(o=>o.filter(l=>l.id!==a))},[]);return n.jsxs(cm.Provider,{value:{toasts:t,toast:r,dismiss:i},children:[e,n.jsx(U0,{toasts:t,dismiss:i})]})}function Pt(){const e=d.useContext(cm);if(!e)throw new Error("useToast must be used within ToastProvider");return e}function U0({toasts:e,dismiss:t}){return n.jsx("div",{className:"fixed bottom-0 right-0 z-[100] flex flex-col-reverse gap-2 p-4 max-w-sm w-full",children:e.map(s=>n.jsx(B0,{toast:s,onDismiss:()=>t(s.id)},s.id))})}function B0({toast:e,onDismiss:t}){const s={default:"bg-background border-border",destructive:"bg-destructive text-destructive-foreground border-destructive",success:"bg-green-600 text-white border-green-700"},r={default:"text-muted-foreground",destructive:"text-destructive-foreground/90",success:"text-white/90"},i={default:"text-muted-foreground hover:text-foreground",destructive:"text-destructive-foreground hover:text-destructive-foreground/80",success:"text-white/70 hover:text-white"},a=e.variant||"default";return n.jsx("div",{className:Y("rounded-lg border p-4 shadow-lg transition-all",s[a]),children:n.jsxs("div",{className:"flex items-start justify-between gap-4",children:[n.jsxs("div",{className:"flex-1",children:[e.title&&n.jsx("div",{className:"font-semibold",children:e.title}),e.description&&n.jsx("div",{className:Y("text-sm",r[a]),children:e.description})]}),n.jsx("button",{onClick:t,className:i[a],children:"×"})]})})}const vs=Object.create(null);vs.open="0";vs.close="1";vs.ping="2";vs.pong="3";vs.message="4";vs.upgrade="5";vs.noop="6";const ia=Object.create(null);Object.keys(vs).forEach(e=>{ia[vs[e]]=e});const Hl={type:"error",data:"parser error"},dm=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",um=typeof ArrayBuffer=="function",hm=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,sd=({type:e,data:t},s,r)=>dm&&t instanceof Blob?s?r(t):dh(t,r):um&&(t instanceof ArrayBuffer||hm(t))?s?r(t):dh(new Blob([t]),r):r(vs[e]+(t||"")),dh=(e,t)=>{const s=new FileReader;return s.onload=function(){const r=s.result.split(",")[1];t("b"+(r||""))},s.readAsDataURL(e)};function uh(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}let Bo;function W0(e,t){if(dm&&e.data instanceof Blob)return e.data.arrayBuffer().then(uh).then(t);if(um&&(e.data instanceof ArrayBuffer||hm(e.data)))return t(uh(e.data));sd(e,!1,s=>{Bo||(Bo=new TextEncoder),t(Bo.encode(s))})}const hh="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Lr=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let e=0;e<hh.length;e++)Lr[hh.charCodeAt(e)]=e;const K0=e=>{let t=e.length*.75,s=e.length,r,i=0,a,o,l,c;e[e.length-1]==="="&&(t--,e[e.length-2]==="="&&t--);const u=new ArrayBuffer(t),m=new Uint8Array(u);for(r=0;r<s;r+=4)a=Lr[e.charCodeAt(r)],o=Lr[e.charCodeAt(r+1)],l=Lr[e.charCodeAt(r+2)],c=Lr[e.charCodeAt(r+3)],m[i++]=a<<2|o>>4,m[i++]=(o&15)<<4|l>>2,m[i++]=(l&3)<<6|c&63;return u},H0=typeof ArrayBuffer=="function",nd=(e,t)=>{if(typeof e!="string")return{type:"message",data:fm(e,t)};const s=e.charAt(0);return s==="b"?{type:"message",data:J0(e.substring(1),t)}:ia[s]?e.length>1?{type:ia[s],data:e.substring(1)}:{type:ia[s]}:Hl},J0=(e,t)=>{if(H0){const s=K0(e);return fm(s,t)}else return{base64:!0,data:e}},fm=(e,t)=>{switch(t){case"blob":return e instanceof Blob?e:new Blob([e]);case"arraybuffer":default:return e instanceof ArrayBuffer?e:e.buffer}},pm="",q0=(e,t)=>{const s=e.length,r=new Array(s);let i=0;e.forEach((a,o)=>{sd(a,!1,l=>{r[o]=l,++i===s&&t(r.join(pm))})})},G0=(e,t)=>{const s=e.split(pm),r=[];for(let i=0;i<s.length;i++){const a=nd(s[i],t);if(r.push(a),a.type==="error")break}return r};function Q0(){return new TransformStream({transform(e,t){W0(e,s=>{const r=s.length;let i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);const a=new DataView(i.buffer);a.setUint8(0,126),a.setUint16(1,r)}else{i=new Uint8Array(9);const a=new DataView(i.buffer);a.setUint8(0,127),a.setBigUint64(1,BigInt(r))}e.data&&typeof e.data!="string"&&(i[0]|=128),t.enqueue(i),t.enqueue(s)})}})}let Wo;function Vi(e){return e.reduce((t,s)=>t+s.length,0)}function Ui(e,t){if(e[0].length===t)return e.shift();const s=new Uint8Array(t);let r=0;for(let i=0;i<t;i++)s[i]=e[0][r++],r===e[0].length&&(e.shift(),r=0);return e.length&&r<e[0].length&&(e[0]=e[0].slice(r)),s}function Y0(e,t){Wo||(Wo=new TextDecoder);const s=[];let r=0,i=-1,a=!1;return new TransformStream({transform(o,l){for(s.push(o);;){if(r===0){if(Vi(s)<1)break;const c=Ui(s,1);a=(c[0]&128)===128,i=c[0]&127,i<126?r=3:i===126?r=1:r=2}else if(r===1){if(Vi(s)<2)break;const c=Ui(s,2);i=new DataView(c.buffer,c.byteOffset,c.length).getUint16(0),r=3}else if(r===2){if(Vi(s)<8)break;const c=Ui(s,8),u=new DataView(c.buffer,c.byteOffset,c.length),m=u.getUint32(0);if(m>Math.pow(2,21)-1){l.enqueue(Hl);break}i=m*Math.pow(2,32)+u.getUint32(4),r=3}else{if(Vi(s)<i)break;const c=Ui(s,i);l.enqueue(nd(a?c:Wo.decode(c),t)),r=0}if(i===0||i>e){l.enqueue(Hl);break}}}})}const mm=4;function He(e){if(e)return X0(e)}function X0(e){for(var t in He.prototype)e[t]=He.prototype[t];return e}He.prototype.on=He.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this};He.prototype.once=function(e,t){function s(){this.off(e,s),t.apply(this,arguments)}return s.fn=t,this.on(e,s),this};He.prototype.off=He.prototype.removeListener=He.prototype.removeAllListeners=He.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var s=this._callbacks["$"+e];if(!s)return this;if(arguments.length==1)return delete this._callbacks["$"+e],this;for(var r,i=0;i<s.length;i++)if(r=s[i],r===t||r.fn===t){s.splice(i,1);break}return s.length===0&&delete this._callbacks["$"+e],this};He.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),s=this._callbacks["$"+e],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(s){s=s.slice(0);for(var r=0,i=s.length;r<i;++r)s[r].apply(this,t)}return this};He.prototype.emitReserved=He.prototype.emit;He.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]};He.prototype.hasListeners=function(e){return!!this.listeners(e).length};const oo=typeof Promise=="function"&&typeof Promise.resolve=="function"?t=>Promise.resolve().then(t):(t,s)=>s(t,0),Wt=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),Z0="arraybuffer";function xm(e,...t){return t.reduce((s,r)=>(e.hasOwnProperty(r)&&(s[r]=e[r]),s),{})}const ej=Wt.setTimeout,tj=Wt.clearTimeout;function lo(e,t){t.useNativeTimers?(e.setTimeoutFn=ej.bind(Wt),e.clearTimeoutFn=tj.bind(Wt)):(e.setTimeoutFn=Wt.setTimeout.bind(Wt),e.clearTimeoutFn=Wt.clearTimeout.bind(Wt))}const sj=1.33;function nj(e){return typeof e=="string"?rj(e):Math.ceil((e.byteLength||e.size)*sj)}function rj(e){let t=0,s=0;for(let r=0,i=e.length;r<i;r++)t=e.charCodeAt(r),t<128?s+=1:t<2048?s+=2:t<55296||t>=57344?s+=3:(r++,s+=4);return s}function gm(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function ij(e){let t="";for(let s in e)e.hasOwnProperty(s)&&(t.length&&(t+="&"),t+=encodeURIComponent(s)+"="+encodeURIComponent(e[s]));return t}function aj(e){let t={},s=e.split("&");for(let r=0,i=s.length;r<i;r++){let a=s[r].split("=");t[decodeURIComponent(a[0])]=decodeURIComponent(a[1])}return t}class oj extends Error{constructor(t,s,r){super(t),this.description=s,this.context=r,this.type="TransportError"}}class rd extends He{constructor(t){super(),this.writable=!1,lo(this,t),this.opts=t,this.query=t.query,this.socket=t.socket,this.supportsBinary=!t.forceBase64}onError(t,s,r){return super.emitReserved("error",new oj(t,s,r)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(t){this.readyState==="open"&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const s=nd(t,this.socket.binaryType);this.onPacket(s)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}createUri(t,s={}){return t+"://"+this._hostname()+this._port()+this.opts.path+this._query(s)}_hostname(){const t=this.opts.hostname;return t.indexOf(":")===-1?t:"["+t+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(t){const s=ij(t);return s.length?"?"+s:""}}class lj extends rd{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(t){this.readyState="pausing";const s=()=>{this.readyState="paused",t()};if(this._polling||!this.writable){let r=0;this._polling&&(r++,this.once("pollComplete",function(){--r||s()})),this.writable||(r++,this.once("drain",function(){--r||s()}))}else s()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){const s=r=>{if(this.readyState==="opening"&&r.type==="open"&&this.onOpen(),r.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(r)};G0(t,this.socket.binaryType).forEach(s),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this._poll())}doClose(){const t=()=>{this.write([{type:"close"}])};this.readyState==="open"?t():this.once("open",t)}write(t){this.writable=!1,q0(t,s=>{this.doWrite(s,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const t=this.opts.secure?"https":"http",s=this.query||{};return this.opts.timestampRequests!==!1&&(s[this.opts.timestampParam]=gm()),!this.supportsBinary&&!s.sid&&(s.b64=1),this.createUri(t,s)}}let vm=!1;try{vm=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const cj=vm;function dj(){}class uj extends lj{constructor(t){if(super(t),typeof location<"u"){const s=location.protocol==="https:";let r=location.port;r||(r=s?"443":"80"),this.xd=typeof location<"u"&&t.hostname!==location.hostname||r!==t.port}}doWrite(t,s){const r=this.request({method:"POST",data:t});r.on("success",s),r.on("error",(i,a)=>{this.onError("xhr post error",i,a)})}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",(s,r)=>{this.onError("xhr poll error",s,r)}),this.pollXhr=t}}class gs extends He{constructor(t,s,r){super(),this.createRequest=t,lo(this,r),this._opts=r,this._method=r.method||"GET",this._uri=s,this._data=r.data!==void 0?r.data:null,this._create()}_create(){var t;const s=xm(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");s.xdomain=!!this._opts.xd;const r=this._xhr=this.createRequest(s);try{r.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let i in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(i)&&r.setRequestHeader(i,this._opts.extraHeaders[i])}}catch{}if(this._method==="POST")try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{r.setRequestHeader("Accept","*/*")}catch{}(t=this._opts.cookieJar)===null||t===void 0||t.addCookies(r),"withCredentials"in r&&(r.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(r.timeout=this._opts.requestTimeout),r.onreadystatechange=()=>{var i;r.readyState===3&&((i=this._opts.cookieJar)===null||i===void 0||i.parseCookies(r.getResponseHeader("set-cookie"))),r.readyState===4&&(r.status===200||r.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof r.status=="number"?r.status:0)},0))},r.send(this._data)}catch(i){this.setTimeoutFn(()=>{this._onError(i)},0);return}typeof document<"u"&&(this._index=gs.requestsCount++,gs.requests[this._index]=this)}_onError(t){this.emitReserved("error",t,this._xhr),this._cleanup(!0)}_cleanup(t){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=dj,t)try{this._xhr.abort()}catch{}typeof document<"u"&&delete gs.requests[this._index],this._xhr=null}}_onLoad(){const t=this._xhr.responseText;t!==null&&(this.emitReserved("data",t),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}gs.requestsCount=0;gs.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",fh);else if(typeof addEventListener=="function"){const e="onpagehide"in Wt?"pagehide":"unload";addEventListener(e,fh,!1)}}function fh(){for(let e in gs.requests)gs.requests.hasOwnProperty(e)&&gs.requests[e].abort()}const hj=function(){const e=ym({xdomain:!1});return e&&e.responseType!==null}();class fj extends uj{constructor(t){super(t);const s=t&&t.forceBase64;this.supportsBinary=hj&&!s}request(t={}){return Object.assign(t,{xd:this.xd},this.opts),new gs(ym,this.uri(),t)}}function ym(e){const t=e.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!t||cj))return new XMLHttpRequest}catch{}if(!t)try{return new Wt[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}const jm=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class pj extends rd{get name(){return"websocket"}doOpen(){const t=this.uri(),s=this.opts.protocols,r=jm?{}:xm(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,s,r)}catch(i){return this.emitReserved("error",i)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let s=0;s<t.length;s++){const r=t[s],i=s===t.length-1;sd(r,this.supportsBinary,a=>{try{this.doWrite(r,a)}catch{}i&&oo(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",s=this.query||{};return this.opts.timestampRequests&&(s[this.opts.timestampParam]=gm()),this.supportsBinary||(s.b64=1),this.createUri(t,s)}}const Ko=Wt.WebSocket||Wt.MozWebSocket;class mj extends pj{createSocket(t,s,r){return jm?new Ko(t,s,r):s?new Ko(t,s):new Ko(t)}doWrite(t,s){this.ws.send(s)}}class xj extends rd{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(t){return this.emitReserved("error",t)}this._transport.closed.then(()=>{this.onClose()}).catch(t=>{this.onError("webtransport error",t)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(t=>{const s=Y0(Number.MAX_SAFE_INTEGER,this.socket.binaryType),r=t.readable.pipeThrough(s).getReader(),i=Q0();i.readable.pipeTo(t.writable),this._writer=i.writable.getWriter();const a=()=>{r.read().then(({done:l,value:c})=>{l||(this.onPacket(c),a())}).catch(l=>{})};a();const o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this._writer.write(o).then(()=>this.onOpen())})})}write(t){this.writable=!1;for(let s=0;s<t.length;s++){const r=t[s],i=s===t.length-1;this._writer.write(r).then(()=>{i&&oo(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var t;(t=this._transport)===null||t===void 0||t.close()}}const gj={websocket:mj,webtransport:xj,polling:fj},vj=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,yj=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function Jl(e){if(e.length>8e3)throw"URI too long";const t=e,s=e.indexOf("["),r=e.indexOf("]");s!=-1&&r!=-1&&(e=e.substring(0,s)+e.substring(s,r).replace(/:/g,";")+e.substring(r,e.length));let i=vj.exec(e||""),a={},o=14;for(;o--;)a[yj[o]]=i[o]||"";return s!=-1&&r!=-1&&(a.source=t,a.host=a.host.substring(1,a.host.length-1).replace(/;/g,":"),a.authority=a.authority.replace("[","").replace("]","").replace(/;/g,":"),a.ipv6uri=!0),a.pathNames=jj(a,a.path),a.queryKey=wj(a,a.query),a}function jj(e,t){const s=/\/{2,9}/g,r=t.replace(s,"/").split("/");return(t.slice(0,1)=="/"||t.length===0)&&r.splice(0,1),t.slice(-1)=="/"&&r.splice(r.length-1,1),r}function wj(e,t){const s={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(r,i,a){i&&(s[i]=a)}),s}const ql=typeof addEventListener=="function"&&typeof removeEventListener=="function",aa=[];ql&&addEventListener("offline",()=>{aa.forEach(e=>e())},!1);class en extends He{constructor(t,s){if(super(),this.binaryType=Z0,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,t&&typeof t=="object"&&(s=t,t=null),t){const r=Jl(t);s.hostname=r.host,s.secure=r.protocol==="https"||r.protocol==="wss",s.port=r.port,r.query&&(s.query=r.query)}else s.host&&(s.hostname=Jl(s.host).host);lo(this,s),this.secure=s.secure!=null?s.secure:typeof location<"u"&&location.protocol==="https:",s.hostname&&!s.port&&(s.port=this.secure?"443":"80"),this.hostname=s.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=s.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},s.transports.forEach(r=>{const i=r.prototype.name;this.transports.push(i),this._transportsByName[i]=r}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},s),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=aj(this.opts.query)),ql&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},aa.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(t){const s=Object.assign({},this.opts.query);s.EIO=mm,s.transport=t,this.id&&(s.sid=this.id);const r=Object.assign({},this.opts,{query:s,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this._transportsByName[t](r)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}const t=this.opts.rememberUpgrade&&en.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";const s=this.createTransport(t);s.open(),this.setTransport(s)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",s=>this._onClose("transport close",s))}onOpen(){this.readyState="open",en.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(t){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const s=new Error("server error");s.code=t.data,this._onError(s);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data);break}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this._pingInterval=t.pingInterval,this._pingTimeout=t.pingTimeout,this._maxPayload=t.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const t=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+t,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},t),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this._getWritablePackets();this.transport.send(t),this._prevBufferLen=t.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let s=1;for(let r=0;r<this.writeBuffer.length;r++){const i=this.writeBuffer[r].data;if(i&&(s+=nj(i)),r>0&&s>this._maxPayload)return this.writeBuffer.slice(0,r);s+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const t=Date.now()>this._pingTimeoutTime;return t&&(this._pingTimeoutTime=0,oo(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),t}write(t,s,r){return this._sendPacket("message",t,s,r),this}send(t,s,r){return this._sendPacket("message",t,s,r),this}_sendPacket(t,s,r,i){if(typeof s=="function"&&(i=s,s=void 0),typeof r=="function"&&(i=r,r=null),this.readyState==="closing"||this.readyState==="closed")return;r=r||{},r.compress=r.compress!==!1;const a={type:t,data:s,options:r};this.emitReserved("packetCreate",a),this.writeBuffer.push(a),i&&this.once("flush",i),this.flush()}close(){const t=()=>{this._onClose("forced close"),this.transport.close()},s=()=>{this.off("upgrade",s),this.off("upgradeError",s),t()},r=()=>{this.once("upgrade",s),this.once("upgradeError",s)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?r():t()}):this.upgrading?r():t()),this}_onError(t){if(en.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return this.transports.shift(),this._open();this.emitReserved("error",t),this._onClose("transport error",t)}_onClose(t,s){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),ql&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const r=aa.indexOf(this._offlineEventListener);r!==-1&&aa.splice(r,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,s),this.writeBuffer=[],this._prevBufferLen=0}}}en.protocol=mm;class Nj extends en{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade)for(let t=0;t<this._upgrades.length;t++)this._probe(this._upgrades[t])}_probe(t){let s=this.createTransport(t),r=!1;en.priorWebsocketSuccess=!1;const i=()=>{r||(s.send([{type:"ping",data:"probe"}]),s.once("packet",f=>{if(!r)if(f.type==="pong"&&f.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",s),!s)return;en.priorWebsocketSuccess=s.name==="websocket",this.transport.pause(()=>{r||this.readyState!=="closed"&&(m(),this.setTransport(s),s.send([{type:"upgrade"}]),this.emitReserved("upgrade",s),s=null,this.upgrading=!1,this.flush())})}else{const g=new Error("probe error");g.transport=s.name,this.emitReserved("upgradeError",g)}}))};function a(){r||(r=!0,m(),s.close(),s=null)}const o=f=>{const g=new Error("probe error: "+f);g.transport=s.name,a(),this.emitReserved("upgradeError",g)};function l(){o("transport closed")}function c(){o("socket closed")}function u(f){s&&f.name!==s.name&&a()}const m=()=>{s.removeListener("open",i),s.removeListener("error",o),s.removeListener("close",l),this.off("close",c),this.off("upgrading",u)};s.once("open",i),s.once("error",o),s.once("close",l),this.once("close",c),this.once("upgrading",u),this._upgrades.indexOf("webtransport")!==-1&&t!=="webtransport"?this.setTimeoutFn(()=>{r||s.open()},200):s.open()}onHandshake(t){this._upgrades=this._filterUpgrades(t.upgrades),super.onHandshake(t)}_filterUpgrades(t){const s=[];for(let r=0;r<t.length;r++)~this.transports.indexOf(t[r])&&s.push(t[r]);return s}}let kj=class extends Nj{constructor(t,s={}){const r=typeof t=="object"?t:s;(!r.transports||r.transports&&typeof r.transports[0]=="string")&&(r.transports=(r.transports||["polling","websocket","webtransport"]).map(i=>gj[i]).filter(i=>!!i)),super(t,r)}};function bj(e,t="",s){let r=e;s=s||typeof location<"u"&&location,e==null&&(e=s.protocol+"//"+s.host),typeof e=="string"&&(e.charAt(0)==="/"&&(e.charAt(1)==="/"?e=s.protocol+e:e=s.host+e),/^(https?|wss?):\/\//.test(e)||(typeof s<"u"?e=s.protocol+"//"+e:e="https://"+e),r=Jl(e)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port="80":/^(http|ws)s$/.test(r.protocol)&&(r.port="443")),r.path=r.path||"/";const a=r.host.indexOf(":")!==-1?"["+r.host+"]":r.host;return r.id=r.protocol+"://"+a+":"+r.port+t,r.href=r.protocol+"://"+a+(s&&s.port===r.port?"":":"+r.port),r}const Sj=typeof ArrayBuffer=="function",Cj=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,wm=Object.prototype.toString,Ej=typeof Blob=="function"||typeof Blob<"u"&&wm.call(Blob)==="[object BlobConstructor]",Rj=typeof File=="function"||typeof File<"u"&&wm.call(File)==="[object FileConstructor]";function id(e){return Sj&&(e instanceof ArrayBuffer||Cj(e))||Ej&&e instanceof Blob||Rj&&e instanceof File}function oa(e,t){if(!e||typeof e!="object")return!1;if(Array.isArray(e)){for(let s=0,r=e.length;s<r;s++)if(oa(e[s]))return!0;return!1}if(id(e))return!0;if(e.toJSON&&typeof e.toJSON=="function"&&arguments.length===1)return oa(e.toJSON(),!0);for(const s in e)if(Object.prototype.hasOwnProperty.call(e,s)&&oa(e[s]))return!0;return!1}function _j(e){const t=[],s=e.data,r=e;return r.data=Gl(s,t),r.attachments=t.length,{packet:r,buffers:t}}function Gl(e,t){if(!e)return e;if(id(e)){const s={_placeholder:!0,num:t.length};return t.push(e),s}else if(Array.isArray(e)){const s=new Array(e.length);for(let r=0;r<e.length;r++)s[r]=Gl(e[r],t);return s}else if(typeof e=="object"&&!(e instanceof Date)){const s={};for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(s[r]=Gl(e[r],t));return s}return e}function Pj(e,t){return e.data=Ql(e.data,t),delete e.attachments,e}function Ql(e,t){if(!e)return e;if(e&&e._placeholder===!0){if(typeof e.num=="number"&&e.num>=0&&e.num<t.length)return t[e.num];throw new Error("illegal attachments")}else if(Array.isArray(e))for(let s=0;s<e.length;s++)e[s]=Ql(e[s],t);else if(typeof e=="object")for(const s in e)Object.prototype.hasOwnProperty.call(e,s)&&(e[s]=Ql(e[s],t));return e}const Tj=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],Aj=5;var Ne;(function(e){e[e.CONNECT=0]="CONNECT",e[e.DISCONNECT=1]="DISCONNECT",e[e.EVENT=2]="EVENT",e[e.ACK=3]="ACK",e[e.CONNECT_ERROR=4]="CONNECT_ERROR",e[e.BINARY_EVENT=5]="BINARY_EVENT",e[e.BINARY_ACK=6]="BINARY_ACK"})(Ne||(Ne={}));class Oj{constructor(t){this.replacer=t}encode(t){return(t.type===Ne.EVENT||t.type===Ne.ACK)&&oa(t)?this.encodeAsBinary({type:t.type===Ne.EVENT?Ne.BINARY_EVENT:Ne.BINARY_ACK,nsp:t.nsp,data:t.data,id:t.id}):[this.encodeAsString(t)]}encodeAsString(t){let s=""+t.type;return(t.type===Ne.BINARY_EVENT||t.type===Ne.BINARY_ACK)&&(s+=t.attachments+"-"),t.nsp&&t.nsp!=="/"&&(s+=t.nsp+","),t.id!=null&&(s+=t.id),t.data!=null&&(s+=JSON.stringify(t.data,this.replacer)),s}encodeAsBinary(t){const s=_j(t),r=this.encodeAsString(s.packet),i=s.buffers;return i.unshift(r),i}}function ph(e){return Object.prototype.toString.call(e)==="[object Object]"}class ad extends He{constructor(t){super(),this.reviver=t}add(t){let s;if(typeof t=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");s=this.decodeString(t);const r=s.type===Ne.BINARY_EVENT;r||s.type===Ne.BINARY_ACK?(s.type=r?Ne.EVENT:Ne.ACK,this.reconstructor=new zj(s),s.attachments===0&&super.emitReserved("decoded",s)):super.emitReserved("decoded",s)}else if(id(t)||t.base64)if(this.reconstructor)s=this.reconstructor.takeBinaryData(t),s&&(this.reconstructor=null,super.emitReserved("decoded",s));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+t)}decodeString(t){let s=0;const r={type:Number(t.charAt(0))};if(Ne[r.type]===void 0)throw new Error("unknown packet type "+r.type);if(r.type===Ne.BINARY_EVENT||r.type===Ne.BINARY_ACK){const a=s+1;for(;t.charAt(++s)!=="-"&&s!=t.length;);const o=t.substring(a,s);if(o!=Number(o)||t.charAt(s)!=="-")throw new Error("Illegal attachments");r.attachments=Number(o)}if(t.charAt(s+1)==="/"){const a=s+1;for(;++s&&!(t.charAt(s)===","||s===t.length););r.nsp=t.substring(a,s)}else r.nsp="/";const i=t.charAt(s+1);if(i!==""&&Number(i)==i){const a=s+1;for(;++s;){const o=t.charAt(s);if(o==null||Number(o)!=o){--s;break}if(s===t.length)break}r.id=Number(t.substring(a,s+1))}if(t.charAt(++s)){const a=this.tryParse(t.substr(s));if(ad.isPayloadValid(r.type,a))r.data=a;else throw new Error("invalid payload")}return r}tryParse(t){try{return JSON.parse(t,this.reviver)}catch{return!1}}static isPayloadValid(t,s){switch(t){case Ne.CONNECT:return ph(s);case Ne.DISCONNECT:return s===void 0;case Ne.CONNECT_ERROR:return typeof s=="string"||ph(s);case Ne.EVENT:case Ne.BINARY_EVENT:return Array.isArray(s)&&(typeof s[0]=="number"||typeof s[0]=="string"&&Tj.indexOf(s[0])===-1);case Ne.ACK:case Ne.BINARY_ACK:return Array.isArray(s)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class zj{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){const s=Pj(this.reconPack,this.buffers);return this.finishedReconstruction(),s}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const Lj=Object.freeze(Object.defineProperty({__proto__:null,Decoder:ad,Encoder:Oj,get PacketType(){return Ne},protocol:Aj},Symbol.toStringTag,{value:"Module"}));function ts(e,t,s){return e.on(t,s),function(){e.off(t,s)}}const Mj=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Nm extends He{constructor(t,s,r){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=t,this.nsp=s,r&&r.auth&&(this.auth=r.auth),this._opts=Object.assign({},r),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const t=this.io;this.subs=[ts(t,"open",this.onopen.bind(this)),ts(t,"packet",this.onpacket.bind(this)),ts(t,"error",this.onerror.bind(this)),ts(t,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...t){return t.unshift("message"),this.emit.apply(this,t),this}emit(t,...s){var r,i,a;if(Mj.hasOwnProperty(t))throw new Error('"'+t.toString()+'" is a reserved event name');if(s.unshift(t),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(s),this;const o={type:Ne.EVENT,data:s};if(o.options={},o.options.compress=this.flags.compress!==!1,typeof s[s.length-1]=="function"){const m=this.ids++,f=s.pop();this._registerAckCallback(m,f),o.id=m}const l=(i=(r=this.io.engine)===null||r===void 0?void 0:r.transport)===null||i===void 0?void 0:i.writable,c=this.connected&&!(!((a=this.io.engine)===null||a===void 0)&&a._hasPingExpired());return this.flags.volatile&&!l||(c?(this.notifyOutgoingListeners(o),this.packet(o)):this.sendBuffer.push(o)),this.flags={},this}_registerAckCallback(t,s){var r;const i=(r=this.flags.timeout)!==null&&r!==void 0?r:this._opts.ackTimeout;if(i===void 0){this.acks[t]=s;return}const a=this.io.setTimeoutFn(()=>{delete this.acks[t];for(let l=0;l<this.sendBuffer.length;l++)this.sendBuffer[l].id===t&&this.sendBuffer.splice(l,1);s.call(this,new Error("operation has timed out"))},i),o=(...l)=>{this.io.clearTimeoutFn(a),s.apply(this,l)};o.withError=!0,this.acks[t]=o}emitWithAck(t,...s){return new Promise((r,i)=>{const a=(o,l)=>o?i(o):r(l);a.withError=!0,s.push(a),this.emit(t,...s)})}_addToQueue(t){let s;typeof t[t.length-1]=="function"&&(s=t.pop());const r={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push((i,...a)=>r!==this._queue[0]?void 0:(i!==null?r.tryCount>this._opts.retries&&(this._queue.shift(),s&&s(i)):(this._queue.shift(),s&&s(null,...a)),r.pending=!1,this._drainQueue())),this._queue.push(r),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||this._queue.length===0)return;const s=this._queue[0];s.pending&&!t||(s.pending=!0,s.tryCount++,this.flags=s.flags,this.emit.apply(this,s.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){typeof this.auth=="function"?this.auth(t=>{this._sendConnectPacket(t)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:Ne.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,s){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,s),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(t=>{if(!this.sendBuffer.some(r=>String(r.id)===t)){const r=this.acks[t];delete this.acks[t],r.withError&&r.call(this,new Error("socket has been disconnected"))}})}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case Ne.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case Ne.EVENT:case Ne.BINARY_EVENT:this.onevent(t);break;case Ne.ACK:case Ne.BINARY_ACK:this.onack(t);break;case Ne.DISCONNECT:this.ondisconnect();break;case Ne.CONNECT_ERROR:this.destroy();const r=new Error(t.data.message);r.data=t.data.data,this.emitReserved("connect_error",r);break}}onevent(t){const s=t.data||[];t.id!=null&&s.push(this.ack(t.id)),this.connected?this.emitEvent(s):this.receiveBuffer.push(Object.freeze(s))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const s=this._anyListeners.slice();for(const r of s)r.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&typeof t[t.length-1]=="string"&&(this._lastOffset=t[t.length-1])}ack(t){const s=this;let r=!1;return function(...i){r||(r=!0,s.packet({type:Ne.ACK,id:t,data:i}))}}onack(t){const s=this.acks[t.id];typeof s=="function"&&(delete this.acks[t.id],s.withError&&t.data.unshift(null),s.apply(this,t.data))}onconnect(t,s){this.id=t,this.recovered=s&&this._pid===s,this._pid=s,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(t=>this.emitEvent(t)),this.receiveBuffer=[],this.sendBuffer.forEach(t=>{this.notifyOutgoingListeners(t),this.packet(t)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(t=>t()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:Ne.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const s=this._anyListeners;for(let r=0;r<s.length;r++)if(t===s[r])return s.splice(r,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(t),this}prependAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(t),this}offAnyOutgoing(t){if(!this._anyOutgoingListeners)return this;if(t){const s=this._anyOutgoingListeners;for(let r=0;r<s.length;r++)if(t===s[r])return s.splice(r,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(t){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const s=this._anyOutgoingListeners.slice();for(const r of s)r.apply(this,t.data)}}}function vr(e){e=e||{},this.ms=e.min||100,this.max=e.max||1e4,this.factor=e.factor||2,this.jitter=e.jitter>0&&e.jitter<=1?e.jitter:0,this.attempts=0}vr.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),s=Math.floor(t*this.jitter*e);e=Math.floor(t*10)&1?e+s:e-s}return Math.min(e,this.max)|0};vr.prototype.reset=function(){this.attempts=0};vr.prototype.setMin=function(e){this.ms=e};vr.prototype.setMax=function(e){this.max=e};vr.prototype.setJitter=function(e){this.jitter=e};class Yl extends He{constructor(t,s){var r;super(),this.nsps={},this.subs=[],t&&typeof t=="object"&&(s=t,t=void 0),s=s||{},s.path=s.path||"/socket.io",this.opts=s,lo(this,s),this.reconnection(s.reconnection!==!1),this.reconnectionAttempts(s.reconnectionAttempts||1/0),this.reconnectionDelay(s.reconnectionDelay||1e3),this.reconnectionDelayMax(s.reconnectionDelayMax||5e3),this.randomizationFactor((r=s.randomizationFactor)!==null&&r!==void 0?r:.5),this.backoff=new vr({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(s.timeout==null?2e4:s.timeout),this._readyState="closed",this.uri=t;const i=s.parser||Lj;this.encoder=new i.Encoder,this.decoder=new i.Decoder,this._autoConnect=s.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,t||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(t){return t===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var s;return t===void 0?this._reconnectionDelay:(this._reconnectionDelay=t,(s=this.backoff)===null||s===void 0||s.setMin(t),this)}randomizationFactor(t){var s;return t===void 0?this._randomizationFactor:(this._randomizationFactor=t,(s=this.backoff)===null||s===void 0||s.setJitter(t),this)}reconnectionDelayMax(t){var s;return t===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,(s=this.backoff)===null||s===void 0||s.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new kj(this.uri,this.opts);const s=this.engine,r=this;this._readyState="opening",this.skipReconnect=!1;const i=ts(s,"open",function(){r.onopen(),t&&t()}),a=l=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",l),t?t(l):this.maybeReconnectOnOpen()},o=ts(s,"error",a);if(this._timeout!==!1){const l=this._timeout,c=this.setTimeoutFn(()=>{i(),a(new Error("timeout")),s.close()},l);this.opts.autoUnref&&c.unref(),this.subs.push(()=>{this.clearTimeoutFn(c)})}return this.subs.push(i),this.subs.push(o),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(ts(t,"ping",this.onping.bind(this)),ts(t,"data",this.ondata.bind(this)),ts(t,"error",this.onerror.bind(this)),ts(t,"close",this.onclose.bind(this)),ts(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(s){this.onclose("parse error",s)}}ondecoded(t){oo(()=>{this.emitReserved("packet",t)},this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,s){let r=this.nsps[t];return r?this._autoConnect&&!r.active&&r.connect():(r=new Nm(this,t,s),this.nsps[t]=r),r}_destroy(t){const s=Object.keys(this.nsps);for(const r of s)if(this.nsps[r].active)return;this._close()}_packet(t){const s=this.encoder.encode(t);for(let r=0;r<s.length;r++)this.engine.write(s[r],t.options)}cleanup(){this.subs.forEach(t=>t()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(t,s){var r;this.cleanup(),(r=this.engine)===null||r===void 0||r.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,s),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const s=this.backoff.duration();this._reconnecting=!0;const r=this.setTimeoutFn(()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),!t.skipReconnect&&t.open(i=>{i?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",i)):t.onreconnect()}))},s);this.opts.autoUnref&&r.unref(),this.subs.push(()=>{this.clearTimeoutFn(r)})}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const _r={};function la(e,t){typeof e=="object"&&(t=e,e=void 0),t=t||{};const s=bj(e,t.path||"/socket.io"),r=s.source,i=s.id,a=s.path,o=_r[i]&&a in _r[i].nsps,l=t.forceNew||t["force new connection"]||t.multiplex===!1||o;let c;return l?c=new Yl(r,t):(_r[i]||(_r[i]=new Yl(r,t)),c=_r[i]),s.query&&!t.query&&(t.query=s.queryKey),c.socket(s.path,t)}Object.assign(la,{Manager:Yl,Socket:Nm,io:la,connect:la});const km=d.createContext(void 0);function Ij({children:e}){const[,t]=d.useState(null),[s,r]=d.useState(!1),[i,a]=d.useState({active:!1}),[o,l]=d.useState([]),[c,u]=d.useState(null),[m,f]=d.useState(null),[g,R]=d.useState([]);d.useEffect(()=>{const N=la(window.location.origin,{transports:["websocket","polling"]});return N.on("connect",()=>{r(!0),console.log("[Recorder] Connected to server")}),N.on("disconnect",()=>{r(!1),console.log("[Recorder] Disconnected from server")}),N.on("recorder:status",S=>{console.log("STATUS UPDATE:",S),a(S)}),N.on("recorder:action",S=>{console.log("ACTION RECEIVED:",S),l(P=>[...P,S.step])}),N.on("recorder:steps",S=>{l(S.steps)}),N.on("recorder:event",S=>{switch(console.log("[Recorder] Event:",S),S.type){case"session_started":k();break;case"session_stopped":k(),C();break;case"capture_started":case"capture_completed":case"capture_error":k(),C();break}}),N.on("recorder:diagnostic",S=>{const P={level:S.level,message:S.message,timestamp:new Date().toISOString()};R(b=>[...b,P].slice(-50)),S.level==="error"&&f(S.message)}),t(N),fetch("/api/recorder/status").then(S=>S.json()).then(S=>S.ok&&a(S.status)),fetch("/api/recorder/steps").then(S=>S.json()).then(S=>S.ok&&l(S.steps)),()=>{N.close()}},[]);const k=d.useCallback(async()=>{try{const N=await fetch("/api/recorder/status");if(N.ok){const S=await N.json();a(S.status||{active:!1})}}catch(N){console.error("[Recorder] Failed to refresh status:",N)}},[]),C=d.useCallback(async()=>{try{const N=await fetch("/api/recorder/steps");if(N.ok){const S=await N.json();l(S.steps||[])}}catch(N){console.error("[Recorder] Failed to refresh steps:",N)}},[]),j=d.useCallback(async N=>{l([]);try{f(null);const S=await fetch("/api/recorder/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(N)});if(!S.ok){const O=(await S.json()).error||"Failed to start recording";throw f(O),new Error(O)}a(b=>({...b,active:!0,visualKey:N.visualKey||b.visualKey}));const P=await fetch("/api/recorder/status");if(P.ok){const b=await P.json();a(b.status||{active:!1})}}catch(S){throw console.error("[Recorder] Failed to start:",S),f(S.message||"Failed to start recording"),S}},[]),p=d.useCallback(async(N=!0)=>{try{f(null);const S=await fetch("/api/recorder/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({save:N})});if(!S.ok){const D=(await S.json()).error||"Failed to stop recording";throw f(D),new Error(D)}const[P,b]=await Promise.all([fetch("/api/recorder/status"),fetch("/api/recorder/steps")]);if(P.ok){const O=await P.json();a(O.status||{active:!1})}if(b.ok){const O=await b.json();l(O.steps||[])}u(null)}catch(S){throw console.error("[Recorder] Failed to stop:",S),f(S.message||"Failed to stop recording"),S}},[]),h=d.useCallback(async(N={})=>{try{const S=await fetch("/api/recorder/capture",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(N)});if(!S.ok){const O=await S.json();throw new Error(O.error||"Failed to capture")}const[P,b]=await Promise.all([fetch("/api/recorder/status"),fetch("/api/recorder/steps")]);if(P.ok){const O=await P.json();a(O.status||{active:!1})}if(b.ok){const O=await b.json();l(O.steps||[])}}catch(S){throw console.error("[Recorder] Failed to capture:",S),S}},[]),x=d.useCallback(async N=>{try{const S=await fetch(`/api/recorder/steps/${N}`,{method:"DELETE"});if(!S.ok){const P=await S.json();throw new Error(P.error||"Failed to remove step")}l(P=>P.filter((b,O)=>O!==N))}catch(S){throw console.error("[Recorder] Failed to remove step:",S),S}},[]),w=d.useMemo(()=>({status:i,steps:o,isConnected:s,lastEvent:c,error:m,diagnostics:g,start:j,stop:p,capture:h,removeStep:x,refreshStatus:k,refreshSteps:C}),[i,o,s,c,m,g,j,p,h,x,k,C]);return n.jsx(km.Provider,{value:w,children:e})}function bm(){const e=d.useContext(km);if(e===void 0)throw new Error("useRecorder must be used within a RecorderProvider");return e}const he=d.forwardRef(({className:e,...t},s)=>n.jsx("div",{ref:s,className:Y("rounded-lg border border-border/40 bg-card/50 text-card-foreground backdrop-blur-sm",e),...t}));he.displayName="Card";const ke=d.forwardRef(({className:e,...t},s)=>n.jsx("div",{ref:s,className:Y("flex flex-col space-y-1 p-4",e),...t}));ke.displayName="CardHeader";const be=d.forwardRef(({className:e,...t},s)=>n.jsx("h3",{ref:s,className:Y("text-sm font-medium leading-none tracking-tight",e),...t}));be.displayName="CardTitle";const at=d.forwardRef(({className:e,...t},s)=>n.jsx("p",{ref:s,className:Y("text-[13px] text-muted-foreground",e),...t}));at.displayName="CardDescription";const me=d.forwardRef(({className:e,...t},s)=>n.jsx("div",{ref:s,className:Y("p-4 pt-0",e),...t}));me.displayName="CardContent";const Dj=d.forwardRef(({className:e,...t},s)=>n.jsx("div",{ref:s,className:Y("flex items-center p-4 pt-0",e),...t}));Dj.displayName="CardFooter";const mh=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,xh=nm,Sm=(e,t)=>s=>{var r;if((t==null?void 0:t.variants)==null)return xh(e,s==null?void 0:s.class,s==null?void 0:s.className);const{variants:i,defaultVariants:a}=t,o=Object.keys(i).map(u=>{const m=s==null?void 0:s[u],f=a==null?void 0:a[u];if(m===null)return null;const g=mh(m)||mh(f);return i[u][g]}),l=s&&Object.entries(s).reduce((u,m)=>{let[f,g]=m;return g===void 0||(u[f]=g),u},{}),c=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((u,m)=>{let{class:f,className:g,...R}=m;return Object.entries(R).every(k=>{let[C,j]=k;return Array.isArray(j)?j.includes({...a,...l}[C]):{...a,...l}[C]===j})?[...u,f,g]:u},[]);return xh(e,o,c,s==null?void 0:s.class,s==null?void 0:s.className)},Fj=Sm("inline-flex items-center rounded-md border px-1.5 py-0.5 text-[11px] font-medium transition-colors focus:outline-none",{variants:{variant:{default:"border-transparent bg-primary/20 text-primary",secondary:"border-transparent bg-secondary text-secondary-foreground",destructive:"border-transparent bg-destructive/20 text-destructive",success:"border-transparent bg-success/20 text-success",approved:"border-transparent bg-green-500/20 text-green-600 dark:text-green-400",pending:"border-transparent bg-amber-500/20 text-amber-600 dark:text-amber-400",warning:"border-transparent bg-warning/20 text-warning",info:"border-transparent bg-blue-500/20 text-blue-600 dark:text-blue-400",outline:"border-border/60 text-muted-foreground bg-transparent",muted:"border-transparent bg-muted text-muted-foreground"}},defaultVariants:{variant:"default"}});function ue({className:e,variant:t,...s}){return n.jsx("div",{className:Y(Fj({variant:t}),e),...s})}const $j=Sm("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-[13px] font-medium transition-all duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90 shadow-[0_1px_2px_rgba(0,0,0,0.3),inset_0_1px_0_rgba(255,255,255,0.1)]",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-border bg-transparent hover:bg-accent hover:text-accent-foreground hover:border-border/80",secondary:"bg-secondary/80 text-secondary-foreground hover:bg-secondary",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline",success:"bg-success text-success-foreground hover:bg-success/90 shadow-[0_1px_2px_rgba(0,0,0,0.3),inset_0_1px_0_rgba(255,255,255,0.1)]"},size:{default:"h-8 px-3 py-1.5",sm:"h-7 rounded-md px-2.5 text-xs",lg:"h-9 rounded-md px-4",icon:"h-8 w-8","icon-sm":"h-7 w-7"}},defaultVariants:{variant:"default",size:"default"}}),T=d.forwardRef(({className:e,variant:t,size:s,...r},i)=>n.jsx("button",{className:Y($j({variant:t,size:s,className:e})),ref:i,...r}));T.displayName="Button";const Fa=d.forwardRef(({className:e,value:t=0,...s},r)=>n.jsx("div",{ref:r,className:`relative h-2 w-full overflow-hidden rounded-full bg-gray-700 ${e||""}`,...s,children:n.jsx("div",{className:"h-full bg-blue-500 transition-all duration-300",style:{width:`${Math.min(100,Math.max(0,t))}%`}})}));Fa.displayName="Progress";const Cm=d.createContext(void 0);function st({open:e,onOpenChange:t,children:s}){return d.useEffect(()=>(e?document.body.style.overflow="hidden":document.body.style.overflow="",()=>{document.body.style.overflow=""}),[e]),e?n.jsx(Cm.Provider,{value:{open:e,onOpenChange:t},children:n.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[n.jsx("div",{className:"fixed inset-0 bg-black/50",onClick:()=>t(!1)}),n.jsx("div",{className:"relative z-50",children:s})]})}):null}function nt({className:e,children:t,...s}){if(!d.useContext(Cm))throw new Error("DialogContent must be used within Dialog");return n.jsx("div",{...s,className:Y("bg-card/95 backdrop-blur-xl border border-border/50 rounded-xl shadow-2xl p-6 w-full max-w-lg max-h-[90vh] overflow-auto",e),children:t})}function Xe({className:e,...t}){return n.jsx("div",{...t,className:Y("flex flex-col space-y-1.5 mb-4",e)})}function Ze({className:e,...t}){return n.jsx("h2",{...t,className:Y("text-[15px] font-semibold leading-none tracking-tight",e)})}function ot({className:e,...t}){return n.jsx("p",{...t,className:Y("text-[13px] text-muted-foreground mt-1",e)})}function lt({className:e,...t}){return n.jsx("div",{...t,className:Y("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2 mt-4",e)})}function gh(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Em(...e){return t=>{let s=!1;const r=e.map(i=>{const a=gh(i,t);return!s&&typeof a=="function"&&(s=!0),a});if(s)return()=>{for(let i=0;i<r.length;i++){const a=r[i];typeof a=="function"?a():gh(e[i],null)}}}}function od(...e){return d.useCallback(Em(...e),e)}function Vj(e,t=[]){let s=[];function r(a,o){const l=d.createContext(o),c=s.length;s=[...s,o];const u=f=>{var p;const{scope:g,children:R,...k}=f,C=((p=g==null?void 0:g[e])==null?void 0:p[c])||l,j=d.useMemo(()=>k,Object.values(k));return n.jsx(C.Provider,{value:j,children:R})};u.displayName=a+"Provider";function m(f,g){var C;const R=((C=g==null?void 0:g[e])==null?void 0:C[c])||l,k=d.useContext(R);if(k)return k;if(o!==void 0)return o;throw new Error(`\`${f}\` must be used within \`${a}\``)}return[u,m]}const i=()=>{const a=s.map(o=>d.createContext(o));return function(l){const c=(l==null?void 0:l[e])||a;return d.useMemo(()=>({[`__scope${e}`]:{...l,[e]:c}}),[l,c])}};return i.scopeName=e,[r,Uj(i,...t)]}function Uj(...e){const t=e[0];if(e.length===1)return t;const s=()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(a){const o=r.reduce((l,{useScope:c,scopeName:u})=>{const f=c(a)[`__scope${u}`];return{...l,...f}},{});return d.useMemo(()=>({[`__scope${t.scopeName}`]:o}),[o])}};return s.scopeName=t.scopeName,s}function vh(e,t,{checkForDefaultPrevented:s=!0}={}){return function(i){if(e==null||e(i),s===!1||!i.defaultPrevented)return t==null?void 0:t(i)}}var $a=globalThis!=null&&globalThis.document?d.useLayoutEffect:()=>{},Bj=zh[" useInsertionEffect ".trim().toString()]||$a;function Wj({prop:e,defaultProp:t,onChange:s=()=>{},caller:r}){const[i,a,o]=Kj({defaultProp:t,onChange:s}),l=e!==void 0,c=l?e:i;{const m=d.useRef(e!==void 0);d.useEffect(()=>{const f=m.current;f!==l&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${l?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),m.current=l},[l,r])}const u=d.useCallback(m=>{var f;if(l){const g=Hj(m)?m(e):m;g!==e&&((f=o.current)==null||f.call(o,g))}else a(m)},[l,e,a,o]);return[c,u]}function Kj({defaultProp:e,onChange:t}){const[s,r]=d.useState(e),i=d.useRef(s),a=d.useRef(t);return Bj(()=>{a.current=t},[t]),d.useEffect(()=>{var o;i.current!==s&&((o=a.current)==null||o.call(a,s),i.current=s)},[s,i]),[s,r,a]}function Hj(e){return typeof e=="function"}function Jj(e){const t=d.useRef({value:e,previous:e});return d.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function qj(e){const[t,s]=d.useState(void 0);return $a(()=>{if(e){s({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const a=i[0];let o,l;if("borderBoxSize"in a){const c=a.borderBoxSize,u=Array.isArray(c)?c[0]:c;o=u.inlineSize,l=u.blockSize}else o=e.offsetWidth,l=e.offsetHeight;s({width:o,height:l})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else s(void 0)},[e]),t}function Gj(e,t){return d.useReducer((s,r)=>t[s][r]??s,e)}var Rm=e=>{const{present:t,children:s}=e,r=Qj(t),i=typeof s=="function"?s({present:r.isPresent}):d.Children.only(s),a=od(r.ref,Yj(i));return typeof s=="function"||r.isPresent?d.cloneElement(i,{ref:a}):null};Rm.displayName="Presence";function Qj(e){const[t,s]=d.useState(),r=d.useRef(null),i=d.useRef(e),a=d.useRef("none"),o=e?"mounted":"unmounted",[l,c]=Gj(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return d.useEffect(()=>{const u=Bi(r.current);a.current=l==="mounted"?u:"none"},[l]),$a(()=>{const u=r.current,m=i.current;if(m!==e){const g=a.current,R=Bi(u);e?c("MOUNT"):R==="none"||(u==null?void 0:u.display)==="none"?c("UNMOUNT"):c(m&&g!==R?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,c]),$a(()=>{if(t){let u;const m=t.ownerDocument.defaultView??window,f=R=>{const C=Bi(r.current).includes(CSS.escape(R.animationName));if(R.target===t&&C&&(c("ANIMATION_END"),!i.current)){const j=t.style.animationFillMode;t.style.animationFillMode="forwards",u=m.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=j)})}},g=R=>{R.target===t&&(a.current=Bi(r.current))};return t.addEventListener("animationstart",g),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{m.clearTimeout(u),t.removeEventListener("animationstart",g),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else c("ANIMATION_END")},[t,c]),{isPresent:["mounted","unmountSuspended"].includes(l),ref:d.useCallback(u=>{r.current=u?getComputedStyle(u):null,s(u)},[])}}function Bi(e){return(e==null?void 0:e.animationName)||"none"}function Yj(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,s=t&&"isReactWarning"in t&&t.isReactWarning;return s?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,s=t&&"isReactWarning"in t&&t.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}function Xj(e){const t=Zj(e),s=d.forwardRef((r,i)=>{const{children:a,...o}=r,l=d.Children.toArray(a),c=l.find(t1);if(c){const u=c.props.children,m=l.map(f=>f===c?d.Children.count(u)>1?d.Children.only(null):d.isValidElement(u)?u.props.children:null:f);return n.jsx(t,{...o,ref:i,children:d.isValidElement(u)?d.cloneElement(u,void 0,m):null})}return n.jsx(t,{...o,ref:i,children:a})});return s.displayName=`${e}.Slot`,s}function Zj(e){const t=d.forwardRef((s,r)=>{const{children:i,...a}=s;if(d.isValidElement(i)){const o=n1(i),l=s1(a,i.props);return i.type!==d.Fragment&&(l.ref=r?Em(r,o):o),d.cloneElement(i,l)}return d.Children.count(i)>1?d.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var e1=Symbol("radix.slottable");function t1(e){return d.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===e1}function s1(e,t){const s={...t};for(const r in t){const i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?s[r]=(...l)=>{const c=a(...l);return i(...l),c}:i&&(s[r]=i):r==="style"?s[r]={...i,...a}:r==="className"&&(s[r]=[i,a].filter(Boolean).join(" "))}return{...e,...s}}function n1(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,s=t&&"isReactWarning"in t&&t.isReactWarning;return s?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,s=t&&"isReactWarning"in t&&t.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}var r1=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ld=r1.reduce((e,t)=>{const s=Xj(`Primitive.${t}`),r=d.forwardRef((i,a)=>{const{asChild:o,...l}=i,c=o?s:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),n.jsx(c,{...l,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{}),co="Checkbox",[i1]=Vj(co),[a1,cd]=i1(co);function o1(e){const{__scopeCheckbox:t,checked:s,children:r,defaultChecked:i,disabled:a,form:o,name:l,onCheckedChange:c,required:u,value:m="on",internal_do_not_use_render:f}=e,[g,R]=Wj({prop:s,defaultProp:i??!1,onChange:c,caller:co}),[k,C]=d.useState(null),[j,p]=d.useState(null),h=d.useRef(!1),x=k?!!o||!!k.closest("form"):!0,w={checked:g,disabled:a,setChecked:R,control:k,setControl:C,name:l,form:o,value:m,hasConsumerStoppedPropagationRef:h,required:u,defaultChecked:tn(i)?!1:i,isFormControl:x,bubbleInput:j,setBubbleInput:p};return n.jsx(a1,{scope:t,...w,children:l1(f)?f(w):r})}var _m="CheckboxTrigger",Pm=d.forwardRef(({__scopeCheckbox:e,onKeyDown:t,onClick:s,...r},i)=>{const{control:a,value:o,disabled:l,checked:c,required:u,setControl:m,setChecked:f,hasConsumerStoppedPropagationRef:g,isFormControl:R,bubbleInput:k}=cd(_m,e),C=od(i,m),j=d.useRef(c);return d.useEffect(()=>{const p=a==null?void 0:a.form;if(p){const h=()=>f(j.current);return p.addEventListener("reset",h),()=>p.removeEventListener("reset",h)}},[a,f]),n.jsx(ld.button,{type:"button",role:"checkbox","aria-checked":tn(c)?"mixed":c,"aria-required":u,"data-state":Lm(c),"data-disabled":l?"":void 0,disabled:l,value:o,...r,ref:C,onKeyDown:vh(t,p=>{p.key==="Enter"&&p.preventDefault()}),onClick:vh(s,p=>{f(h=>tn(h)?!0:!h),k&&R&&(g.current=p.isPropagationStopped(),g.current||p.stopPropagation())})})});Pm.displayName=_m;var dd=d.forwardRef((e,t)=>{const{__scopeCheckbox:s,name:r,checked:i,defaultChecked:a,required:o,disabled:l,value:c,onCheckedChange:u,form:m,...f}=e;return n.jsx(o1,{__scopeCheckbox:s,checked:i,defaultChecked:a,disabled:l,required:o,onCheckedChange:u,name:r,form:m,value:c,internal_do_not_use_render:({isFormControl:g})=>n.jsxs(n.Fragment,{children:[n.jsx(Pm,{...f,ref:t,__scopeCheckbox:s}),g&&n.jsx(zm,{__scopeCheckbox:s})]})})});dd.displayName=co;var Tm="CheckboxIndicator",Am=d.forwardRef((e,t)=>{const{__scopeCheckbox:s,forceMount:r,...i}=e,a=cd(Tm,s);return n.jsx(Rm,{present:r||tn(a.checked)||a.checked===!0,children:n.jsx(ld.span,{"data-state":Lm(a.checked),"data-disabled":a.disabled?"":void 0,...i,ref:t,style:{pointerEvents:"none",...e.style}})})});Am.displayName=Tm;var Om="CheckboxBubbleInput",zm=d.forwardRef(({__scopeCheckbox:e,...t},s)=>{const{control:r,hasConsumerStoppedPropagationRef:i,checked:a,defaultChecked:o,required:l,disabled:c,name:u,value:m,form:f,bubbleInput:g,setBubbleInput:R}=cd(Om,e),k=od(s,R),C=Jj(a),j=qj(r);d.useEffect(()=>{const h=g;if(!h)return;const x=window.HTMLInputElement.prototype,N=Object.getOwnPropertyDescriptor(x,"checked").set,S=!i.current;if(C!==a&&N){const P=new Event("click",{bubbles:S});h.indeterminate=tn(a),N.call(h,tn(a)?!1:a),h.dispatchEvent(P)}},[g,C,a,i]);const p=d.useRef(tn(a)?!1:a);return n.jsx(ld.input,{type:"checkbox","aria-hidden":!0,defaultChecked:o??p.current,required:l,disabled:c,name:u,value:m,form:f,...t,tabIndex:-1,ref:k,style:{...t.style,...j,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});zm.displayName=Om;function l1(e){return typeof e=="function"}function tn(e){return e==="indeterminate"}function Lm(e){return tn(e)?"indeterminate":e?"checked":"unchecked"}const ns=d.forwardRef(({className:e,indeterminate:t,...s},r)=>n.jsx(dd,{ref:r,className:Y("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",t&&"bg-primary text-primary-foreground",e),...s,children:n.jsx(Am,{className:Y("flex items-center justify-center text-current"),children:t?n.jsx(Zp,{className:"h-3 w-3"}):n.jsx(ro,{className:"h-3 w-3"})})}));ns.displayName=dd.displayName;const uo=d.forwardRef(({className:e,...t},s)=>n.jsx("textarea",{className:Y("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:s,...t}));uo.displayName="Textarea";function ho({open:e,onOpenChange:t,scenarioKeys:s,onConfirm:r}){const[i,a]=d.useState([]),[o,l]=d.useState(!0),[c,u]=d.useState(!1),[m,f]=d.useState(""),[g,R]=d.useState(new Set),[k,C]=d.useState({}),j=d.useMemo(()=>JSON.stringify(s||[]),[s]);d.useEffect(()=>{if(!e)return;(async()=>{l(!0);try{const $=(await(await fetch("/api/output?latestJobOnly=true")).json()).groups||[],A=(s?$.filter(J=>s.includes(J.scenarioKey)):$).map(J=>({scenarioKey:J.scenarioKey,variationSlug:J.variationSlug,assets:J.assets||[]}));a(A);const z={};for(const J of A){const G=`${J.scenarioKey}::${J.variationSlug}`;z[G]=!0}C(z),R(new Set);const W=[...new Set(A.map(J=>J.scenarioKey))];W.length===1?f(`Update ${W[0]} visuals`):W.length>1?f(`Update ${W.length} scenarios`):f(""),l(!1)}catch(_){console.error("Failed to load assets:",_),l(!1)}})()},[e,j]);const p=y=>y<1024?`${y} B`:y<1024*1024?`${(y/1024).toFixed(1)} KB`:`${(y/(1024*1024)).toFixed(1)} MB`,h=y=>{const _=i.filter($=>$.scenarioKey===y),F=_.every($=>k[`${$.scenarioKey}::${$.variationSlug}`]);C($=>{const E={...$};for(const A of _)E[`${A.scenarioKey}::${A.variationSlug}`]=!F;return E})},x=y=>{const _=`${y.scenarioKey}::${y.variationSlug}`;C(F=>({...F,[_]:!F[_]}))},w=()=>{C(y=>{const _={...y};for(const F of Object.keys(_))_[F]=!0;return _})},N=()=>{C(y=>{const _={...y};for(const F of Object.keys(_))_[F]=!1;return _})},S=y=>{R(_=>{const F=new Set(_);return F.has(y)?F.delete(y):F.add(y),F})},P=Object.values(k).filter(Boolean).length,b=i.length,O=d.useMemo(()=>{let y=0;for(const _ of i){const F=`${_.scenarioKey}::${_.variationSlug}`;k[F]&&(y+=_.assets.length)}return y},[i,k]),D=d.useMemo(()=>{let y=0;for(const _ of i){const F=`${_.scenarioKey}::${_.variationSlug}`;if(k[F])for(const $ of _.assets)y+=$.size}return y},[i,k]),v=async()=>{u(!0);try{const y=i.filter(_=>{const F=`${_.scenarioKey}::${_.variationSlug}`;return k[F]});await r(y,m.trim()||void 0)}finally{u(!1)}},L=y=>{const _=i.filter($=>$.scenarioKey===y),F=_.filter($=>k[`${$.scenarioKey}::${$.variationSlug}`]).length;return F===0?"none":F===_.length?"all":"some"},V=d.useMemo(()=>{const y=new Map;for(const _ of i){const F=y.get(_.scenarioKey)||[];F.push(_),y.set(_.scenarioKey,F)}return y},[i]);return n.jsx(st,{open:e,onOpenChange:t,children:n.jsxs(nt,{className:"max-w-3xl max-h-[85vh] overflow-y-auto",children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:"Publish Preview"}),n.jsx(ot,{children:"Select which scenarios to publish to the platform"})]}),o?n.jsx("div",{className:"py-8 text-center text-muted-foreground",children:"Loading assets..."}):b===0?n.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[n.jsx("p",{children:"No assets found to publish."}),n.jsx("p",{className:"text-sm mt-2",children:"Run `reshot run` to generate assets first."})]}):n.jsxs("div",{className:"space-y-4",children:[n.jsxs(he,{children:[n.jsxs(ke,{className:"pb-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Fy,{className:"h-4 w-4 text-muted-foreground"}),n.jsx(be,{className:"text-sm",children:"Commit Message"})]}),n.jsx(at,{className:"text-xs",children:"Describe what changed in this publish for version tracking."})]}),n.jsx(me,{children:n.jsxs("div",{className:"space-y-2",children:[n.jsx(uo,{placeholder:"e.g., Updated dashboard screenshots with new navigation design",value:m,onChange:y=>f(y.target.value),rows:2,className:"resize-none"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:m.length>0?`${m.length} characters`:"Optional but recommended"})]})})]}),n.jsxs(he,{children:[n.jsx(ke,{className:"pb-2",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(be,{className:"text-sm",children:"Summary"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsxs(T,{variant:"outline",size:"sm",onClick:w,className:"text-xs h-7",children:[n.jsx(Qc,{className:"h-3 w-3 mr-1"}),"Select All"]}),n.jsxs(T,{variant:"outline",size:"sm",onClick:N,className:"text-xs h-7",children:[n.jsx(ed,{className:"h-3 w-3 mr-1"}),"Select None"]})]})]})}),n.jsx(me,{children:n.jsxs("div",{className:"grid grid-cols-4 gap-4 text-sm",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-muted-foreground text-xs",children:"Scenarios"}),n.jsx("div",{className:"font-semibold text-lg",children:V.size})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-muted-foreground text-xs",children:"Variations"}),n.jsxs("div",{className:"font-semibold text-lg",children:[P," / ",b]})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-muted-foreground text-xs",children:"Assets"}),n.jsx("div",{className:"font-semibold text-lg",children:O})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-muted-foreground text-xs",children:"Size"}),n.jsx("div",{className:"font-semibold text-lg",children:p(D)})]})]})})]}),n.jsx("div",{className:"space-y-2",children:Array.from(V.entries()).map(([y,_])=>{const F=L(y),$=g.has(y),E=_.reduce((z,W)=>z+W.assets.length,0),A=_.filter(z=>k[`${z.scenarioKey}::${z.variationSlug}`]).length;return n.jsxs(he,{className:"overflow-hidden",children:[n.jsxs("div",{className:"flex items-center gap-3 p-3 hover:bg-muted/30 cursor-pointer border-b",onClick:()=>h(y),children:[n.jsx(ns,{checked:F==="all",indeterminate:F==="some",onCheckedChange:()=>h(y),onClick:z=>z.stopPropagation()}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"font-medium text-sm truncate",children:y}),n.jsxs("div",{className:"text-xs text-muted-foreground",children:[A,"/",_.length," variations · ",E," assets"]})]}),n.jsx(T,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:z=>{z.stopPropagation(),S(y)},children:$?n.jsx(zs,{className:"h-4 w-4"}):n.jsx(Ps,{className:"h-4 w-4"})})]}),$&&n.jsx("div",{className:"p-2 space-y-1 bg-muted/10",children:_.map(z=>{const W=`${z.scenarioKey}::${z.variationSlug}`,J=k[W];return n.jsxs("div",{className:`flex items-center gap-3 p-2 rounded-md cursor-pointer transition-colors ${J?"bg-primary/10 border border-primary/20":"hover:bg-muted/50"}`,onClick:()=>x(z),children:[n.jsx(ns,{checked:J,onCheckedChange:()=>x(z),onClick:G=>G.stopPropagation(),className:"ml-4"}),n.jsx("div",{className:"flex-1 min-w-0",children:n.jsx(ue,{variant:"secondary",className:"font-mono text-xs",children:z.variationSlug})}),n.jsxs("span",{className:"text-xs text-muted-foreground",children:[z.assets.length," assets"]})]},W)})})]},y)})})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>t(!1),disabled:c,children:"Cancel"}),n.jsx(T,{onClick:v,disabled:P===0||c,children:c?n.jsxs(n.Fragment,{children:[n.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[n.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),n.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Publishing..."]}):n.jsxs(n.Fragment,{children:[n.jsx(on,{className:"h-4 w-4 mr-2"}),"Publish"," ",O>0&&`${O} assets`]})})]})]})})}const Mm=/\u001b\[[0-9;]*m/g;function tr(e){for(let t=e.length-1;t>=0;t--){const s=e[t].message.replace(Mm,""),r=s.match(/\[PROGRESS\]\s*(\d+)\/(\d+)\s*\|\s*active:(\d+)\s*\|\s*last:[^\|]+\|\s*eta:([^\|]+)\|\s*rate:([^\s]+)\/min/);if(r)return{current:parseInt(r[1],10),total:parseInt(r[2],10),activeWorkers:parseInt(r[3],10),eta:r[4].trim(),throughput:r[5].trim()};const i=s.match(/\[(\d+)\/(\d+)\]/)||s.match(/Progress:\s*(\d+)\/(\d+)/);if(i)return{current:parseInt(i[1],10),total:parseInt(i[2],10)}}return null}function Im(e){return e.replace(Mm,"")}const Dm=d.createContext(null);function ji(){const e=d.useContext(Dm);if(!e)throw new Error("useJobMonitor must be used within JobMonitorProvider");return e}function c1({children:e}){const[t,s]=d.useState([]),[r,i]=d.useState(!1),[a,o]=d.useState(0),[l,c]=d.useState(".reshot/output"),[u,m]=d.useState(null);d.useEffect(()=>{fetch("/api/config").then(w=>w.json()).then(w=>{var N,S;(N=w.config)!=null&&N.assetDir&&c(w.config.assetDir),(S=w.settings)!=null&&S.platformUrl&&m(w.settings.platformUrl)}).catch(()=>{})},[]);const f=d.useRef(new Set),g=d.useRef(new Set),[R,k]=d.useState(null),C=d.useCallback(()=>{k(null)},[]),j=d.useCallback(async()=>{try{const S=(await(await fetch("/api/jobs?limit=20")).json()).jobs||[],P=Date.now(),b=S.filter(O=>{if(O.status==="running"||O.status==="pending")return!0;const D=new Date(O.updatedAt).getTime();return P-D<1e4});s(b)}catch(w){console.error("Failed to load jobs:",w)}},[]),p=t.some(w=>w.status==="running"||w.status==="pending");d.useEffect(()=>{if(j(),a===0&&!p)return;const w=setInterval(j,2e3);return()=>clearInterval(w)},[j,p,a]),d.useEffect(()=>{var w;for(const N of t)if(f.current.has(N.id)&&!g.current.has(N.id)){if(N.status==="success"){g.current.add(N.id),k(N);break}if(N.status==="failed"&&((w=N.metadata)!=null&&w.authRequired)){g.current.add(N.id),k(N);break}}},[t]);const h=d.useCallback(w=>{s(N=>[w,...N.filter(S=>S.id!==w.id)]),i(!1)},[]),x=d.useCallback((w,N)=>{f.current.add(w),i(!1),o(S=>S+1),setTimeout(()=>o(0),1e4),j()},[j]);return n.jsx(Dm.Provider,{value:{activeJobs:t,addJob:h,refreshJobs:j,trackJob:x,isMinimized:r,setIsMinimized:i,completedJobForModal:R,dismissCompletionModal:C,outputDir:l,platformUrl:u},children:e})}function d1(){var V;const e=Os(),t=On(),{toast:s}=Pt(),{activeJobs:r,isMinimized:i,setIsMinimized:a,trackJob:o,completedJobForModal:l,dismissCompletionModal:c,outputDir:u,platformUrl:m}=ji(),[f,g]=d.useState(null),[R,k]=d.useState(new Set),[C,j]=d.useState(!1),[p,h]=d.useState([]),[x,w]=d.useState(null);if(d.useEffect(()=>{const y=r.find(_=>_.status==="running"||_.status==="pending");y&&y.id!==x&&(g(y.id),w(y.id)),!y&&x&&w(null)},[r,x]),t.pathname==="/jobs")return null;const N=r.filter(y=>!R.has(y.id));if(N.length===0)return null;const S=N.filter(y=>y.status==="running"||y.status==="pending"),P=N.filter(y=>y.status==="success"||y.status==="failed"||y.status==="cancelled"),b=y=>{y.scenarioKey?e(`/scenarios/${y.scenarioKey}?tab=assets`):e("/assets"),k(_=>new Set([..._,y.id]))},O=y=>{k(_=>new Set([..._,y]))},D=(y,_)=>{if(_==="running"||_==="pending")return n.jsx(_e,{className:"h-3.5 w-3.5 animate-spin"});if(_==="success")return n.jsx(vt,{className:"h-3.5 w-3.5 text-green-500"});if(_==="failed")return n.jsx(Da,{className:"h-3.5 w-3.5 text-red-500"});switch(y){case"run":return n.jsx(Ts,{className:"h-3.5 w-3.5"});case"publish":return n.jsx(on,{className:"h-3.5 w-3.5"});default:return n.jsx(fn,{className:"h-3.5 w-3.5"})}},v=y=>{const _=y.type==="run"?"Capture":y.type==="publish"?"Publish":"Record";return y.scenarioKey?`${_}: ${y.scenarioKey}`:`${_} All`},L=y=>{switch(y.status){case"running":{const _=tr(y.logs);return n.jsx(ue,{variant:"info",className:"text-[10px] px-1.5 py-0",children:_?`${_.current}/${_.total}`:"Running"})}case"pending":return n.jsx(ue,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:"Queued"});case"success":return n.jsx(ue,{variant:"success",className:"text-[10px] px-1.5 py-0",children:"Done"});case"failed":return n.jsx(ue,{variant:"destructive",className:"text-[10px] px-1.5 py-0",children:"Failed"});case"cancelled":return n.jsx(ue,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:"Cancelled"});default:return null}};return n.jsxs("div",{className:"fixed bottom-4 right-4 z-50 flex flex-col gap-2 max-w-sm w-full",children:[i&&n.jsx(he,{className:"cursor-pointer hover:bg-accent transition-colors shadow-lg border-border",onClick:()=>a(!1),children:n.jsxs(me,{className:"p-3 flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[S.length>0&&n.jsx(_e,{className:"h-4 w-4 animate-spin text-blue-500"}),S.length===0&&P.length>0&&n.jsx(vt,{className:"h-4 w-4 text-green-500"}),n.jsx("span",{className:"text-sm font-medium",children:S.length>0?(()=>{const y=tr(S[0].logs);if(y){const _=y.eta?` — ETA ${y.eta}`:"";return`Capturing ${y.current}/${y.total}${_}`}return`${S.length} job${S.length>1?"s":""} running`})():`${P.length} completed`})]}),n.jsx(Wy,{className:"h-4 w-4 text-muted-foreground"})]})}),!i&&n.jsxs(he,{className:"shadow-lg border-border overflow-hidden",children:[n.jsxs(ke,{className:"py-2 px-3 border-b bg-muted/30 flex flex-row items-center justify-between",children:[n.jsxs(be,{className:"text-xs font-medium flex items-center gap-2",children:[S.length>0&&n.jsx(_e,{className:"h-3 w-3 animate-spin text-blue-500"}),"Active Jobs (",N.length,")"]}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx(T,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>e("/jobs"),children:n.jsx(an,{className:"h-3 w-3"})}),n.jsx(T,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>a(!0),children:n.jsx(Hy,{className:"h-3 w-3"})})]})]}),n.jsx(me,{className:"p-0 max-h-80 overflow-y-auto",children:n.jsx("div",{className:"divide-y divide-border",children:N.map(y=>{var _,F;return n.jsxs("div",{className:"p-2 hover:bg-accent/50 transition-colors",children:[n.jsxs("div",{className:"flex items-center justify-between cursor-pointer",onClick:()=>g(f===y.id?null:y.id),children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[D(y.type,y.status),n.jsx("span",{className:"text-xs font-medium truncate",children:v(y)})]}),n.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[L(y),f===y.id?n.jsx(Yc,{className:"h-3 w-3 text-muted-foreground"}):n.jsx(zs,{className:"h-3 w-3 text-muted-foreground"})]})]}),(y.status==="running"||y.status==="pending")&&(()=>{const $=tr(y.logs);if($){const E=Math.round($.current/$.total*100);return n.jsxs("div",{className:"mt-2 space-y-1",children:[n.jsx(Fa,{value:E,className:"h-1"}),n.jsxs("div",{className:"flex items-center justify-between text-[10px] text-muted-foreground",children:[n.jsxs("span",{children:[$.current,"/",$.total," completed",$.activeWorkers&&$.activeWorkers>1?` (${$.activeWorkers} parallel)`:""]}),n.jsxs("span",{children:[E,"%"]})]}),($.eta||$.throughput)&&n.jsxs("div",{className:"flex items-center justify-between text-[10px] text-muted-foreground",children:[$.eta&&n.jsxs("span",{children:["ETA: ",$.eta]}),$.throughput&&n.jsxs("span",{children:[$.throughput,"/min"]})]})]})}return y.status==="running"?n.jsxs("div",{className:"mt-2 text-[10px] text-muted-foreground flex items-center gap-1",children:[n.jsx(_e,{className:"h-3 w-3 animate-spin"}),n.jsx("span",{children:"Processing..."})]}):null})(),y.status==="failed"&&((_=y.metadata)==null?void 0:_.error)&&n.jsxs("div",{className:"mt-2 p-2 bg-red-50 dark:bg-red-950/30 rounded border border-red-200 dark:border-red-900",children:[n.jsx("p",{className:"text-[10px] text-red-600 dark:text-red-400 font-medium",children:y.metadata.error}),((F=y.metadata)==null?void 0:F.authRequired)&&n.jsxs(T,{size:"sm",variant:"outline",className:"h-6 text-xs mt-1.5",onClick:$=>{$.stopPropagation(),e("/connection")},children:[n.jsx(Ma,{className:"h-3 w-3 mr-1"}),"Reconnect"]})]}),f===y.id&&n.jsxs("div",{className:"mt-2 space-y-2",children:[n.jsx("div",{className:"bg-muted/50 rounded p-2 max-h-32 overflow-y-auto",children:n.jsxs("div",{className:"font-mono text-[10px] space-y-0.5",children:[y.logs.slice(-8).map(($,E)=>n.jsxs("div",{className:"text-muted-foreground truncate",children:[n.jsx("span",{className:"text-muted-foreground/40 text-[9px]",children:new Date($.timestamp).toLocaleTimeString()})," ",Im($.message)]},E)),y.logs.length===0&&n.jsx("div",{className:"text-muted-foreground",children:"Waiting to start..."})]})}),n.jsxs("div",{className:"flex items-center gap-2",children:[y.status==="success"&&n.jsx(T,{size:"sm",variant:"default",className:"h-6 text-xs",onClick:$=>{$.stopPropagation(),b(y)},children:"View Assets"}),n.jsx(T,{size:"sm",variant:"ghost",className:"h-6 text-xs ml-auto",onClick:$=>{$.stopPropagation(),O(y.id)},children:n.jsx(ln,{className:"h-3 w-3"})})]})]})]},y.id)})})})]}),n.jsx(st,{open:!!l,onOpenChange:y=>{y||c()},children:n.jsx(nt,{children:(l==null?void 0:l.status)==="failed"&&((V=l==null?void 0:l.metadata)!=null&&V.authRequired)?n.jsxs(n.Fragment,{children:[n.jsxs(Xe,{children:[n.jsxs(Ze,{className:"flex items-center gap-2",children:[n.jsx(Da,{className:"h-5 w-5 text-red-500"}),"Authentication Required"]}),n.jsx(ot,{children:l.metadata.error||"Your API key has expired or is invalid. Please reconnect to publish."})]}),n.jsxs(lt,{className:"gap-2 sm:gap-0",children:[n.jsx(T,{variant:"outline",onClick:c,children:"Close"}),n.jsxs(T,{onClick:()=>{c(),e("/connection")},children:[n.jsx(Ma,{className:"h-4 w-4 mr-2"}),"Reconnect"]})]})]}):(l==null?void 0:l.type)==="publish"?n.jsxs(n.Fragment,{children:[n.jsxs(Xe,{children:[n.jsxs(Ze,{className:"flex items-center gap-2",children:[n.jsx(vt,{className:"h-5 w-5 text-green-500"}),"Publish Complete"]}),n.jsx(ot,{children:l!=null&&l.scenarioKey?`Scenario "${l.scenarioKey}" published successfully.`:"Successfully published to platform."})]}),n.jsxs(lt,{className:"gap-2 sm:gap-0",children:[n.jsx(T,{variant:"outline",onClick:c,children:"Close"}),m&&n.jsxs(T,{onClick:()=>{window.open(m,"_blank"),c()},children:[n.jsx(an,{className:"h-4 w-4 mr-2"}),"View on Platform"]})]})]}):n.jsxs(n.Fragment,{children:[n.jsxs(Xe,{children:[n.jsxs(Ze,{className:"flex items-center gap-2",children:[n.jsx(vt,{className:"h-5 w-5 text-green-500"}),"Capture Complete"]}),n.jsx(ot,{children:l!=null&&l.scenarioKey?`Scenario "${l.scenarioKey}" finished successfully.`:"All scenarios finished successfully."})]}),n.jsx("div",{className:"py-2",children:n.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground bg-muted/50 rounded-md p-3",children:[n.jsx(fi,{className:"h-4 w-4 flex-shrink-0"}),n.jsxs("span",{className:"font-mono text-xs truncate",children:[u,"/"]})]})}),n.jsxs(lt,{className:"gap-2 sm:gap-0",children:[n.jsx(T,{variant:"outline",onClick:c,children:"Close"}),n.jsx(T,{variant:"secondary",onClick:()=>{l!=null&&l.scenarioKey?e(`/scenarios/${l.scenarioKey}?tab=assets`):e("/assets"),c()},children:"Review Assets"}),n.jsxs(T,{onClick:()=>{var _;const y=l!=null&&l.scenarioKey?[l.scenarioKey]:((_=l==null?void 0:l.metadata)==null?void 0:_.scenarioKeys)||[];h(y),c(),j(!0)},children:[n.jsx(on,{className:"h-4 w-4 mr-2"}),"Publish to Platform"]})]})]})})}),n.jsx(ho,{open:C,onOpenChange:j,scenarioKeys:p.length>0?p:void 0,onConfirm:async y=>{var _;try{const F=y.reduce((A,z)=>A+z.assets.length,0),$=await fetch("/api/jobs/publish",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:p,selectedGroups:y})}),E=await $.json();if($.status===401||E.authRequired){j(!1),s({title:"Authentication Required",description:E.error||"Please reconnect to publish.",variant:"destructive"}),e("/connection");return}$.ok&&E.ok?(s({title:"Job Created",description:`Publishing ${F} asset(s). Monitor progress in the panel below.`}),j(!1),(_=E.job)!=null&&_.id&&o(E.job.id)):s({title:"Error",description:E.error||"Failed to create publish job",variant:"destructive"})}catch{s({title:"Error",description:"Failed to connect to server",variant:"destructive"})}}})]})}const u1=[{value:"platform",label:"Reshot Platform",icon:Py,description:"Managed hosting"},{value:"s3",label:"Amazon S3",icon:ih,description:"Your own bucket"},{value:"r2",label:"Cloudflare R2",icon:ih,description:"Your own bucket"},{value:"local",label:"Local Storage",icon:Vy,description:"Offline only"}];function wi({open:e,onOpenChange:t,onAuthenticated:s}){const{toast:r}=Pt(),[i,a]=d.useState("idle"),[o,l]=d.useState("platform"),[c,u]=d.useState(null),[m,f]=d.useState(null),[g,R]=d.useState(null),[k,C]=d.useState(null);d.useEffect(()=>{e&&(a("idle"),u(null),f(null),R(null),C(null))},[e]),d.useEffect(()=>{if(i!=="waiting"||!m)return;const h=setInterval(async()=>{try{const w=await(await fetch(`/api/auth/status?token=${m}`)).json();w.status==="completed"?(a("completed"),C({projectId:w.projectId,projectName:w.projectName,workspaceName:w.workspaceName}),clearInterval(h),setTimeout(()=>{s(),t(!1)},1500)):(w.status==="expired"||w.status==="invalid")&&(a("error"),R(w.error||"Authentication session expired"),clearInterval(h))}catch(x){console.error("Poll error:",x)}},2e3);return()=>clearInterval(h)},[i,m,s,t]);const j=async()=>{a("starting"),R(null);try{const x=await(await fetch("/api/auth/start",{method:"POST",headers:{"Content-Type":"application/json"}})).json();if(x.ok&&x.authUrl){u(x.authUrl),f(x.authToken),a("waiting");try{await fetch("/api/auth/open-browser",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({authUrl:x.authUrl})})}catch{}}else throw new Error(x.error||"Failed to start authentication")}catch(h){a("error"),R(h.message||"Failed to start authentication")}},p=d.useCallback(async()=>{if(c)try{await navigator.clipboard.writeText(c),r({title:"Copied",description:"Authentication URL copied to clipboard",variant:"success"})}catch{r({title:"Error",description:"Failed to copy URL",variant:"destructive"})}},[c,r]);return n.jsx(st,{open:e,onOpenChange:t,children:n.jsxs(nt,{className:"max-w-md",children:[n.jsxs(Xe,{children:[n.jsxs(Ze,{className:"flex items-center gap-2",children:[n.jsx(La,{className:"h-5 w-5"}),"Connect to Reshot Platform"]}),n.jsx(ot,{children:"Choose your storage destination and authenticate to sync your assets."})]}),n.jsxs("div",{className:"py-4 space-y-4",children:[i==="idle"&&n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsx("label",{className:"text-sm font-medium",children:"Storage Destination"}),n.jsx("div",{className:"grid grid-cols-2 gap-2",children:u1.map(h=>{const x=h.icon;return n.jsxs("button",{onClick:()=>l(h.value),className:Y("flex flex-col items-start gap-1 p-3 rounded-lg border text-left transition-colors",o===h.value?"border-primary bg-primary/5":"border-border hover:border-primary/50 hover:bg-muted/50"),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(x,{className:"h-4 w-4"}),n.jsx("span",{className:"text-sm font-medium",children:h.label})]}),n.jsx("span",{className:"text-xs text-muted-foreground",children:h.description})]},h.value)})})]}),o==="platform"&&n.jsxs(T,{onClick:j,className:"w-full",children:[n.jsx(La,{className:"h-4 w-4 mr-2"}),"Authenticate with Platform"]}),o==="s3"&&n.jsxs("div",{className:"text-center space-y-2 p-4 bg-muted/50 rounded-lg",children:[n.jsx("p",{className:"text-sm text-muted-foreground",children:"S3 storage requires configuration in your project settings."}),n.jsxs("p",{className:"text-xs text-muted-foreground",children:["Run ",n.jsx("code",{className:"bg-muted px-1 rounded",children:"reshot config --storage s3"})]})]}),o==="r2"&&n.jsxs("div",{className:"text-center space-y-2 p-4 bg-muted/50 rounded-lg",children:[n.jsx("p",{className:"text-sm text-muted-foreground",children:"Cloudflare R2 storage requires configuration in your project settings."}),n.jsxs("p",{className:"text-xs text-muted-foreground",children:["Run ",n.jsx("code",{className:"bg-muted px-1 rounded",children:"reshot config --storage r2"})]})]}),o==="local"&&n.jsxs("div",{className:"text-center space-y-2 p-4 bg-muted/50 rounded-lg",children:[n.jsx("p",{className:"text-sm text-muted-foreground",children:"Local storage keeps assets only on your machine. Great for testing."}),n.jsx(T,{variant:"outline",onClick:()=>{s(),t(!1),r({title:"Local Mode",description:"Working in local-only mode",variant:"success"})},className:"w-full mt-2",children:"Use Local Storage"})]}),n.jsx("div",{className:"pt-2 border-t border-border",children:n.jsxs("a",{href:"https://docs.reshot.dev/reference/cli",target:"_blank",rel:"noopener noreferrer",className:"flex items-center justify-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors",children:[n.jsx(an,{className:"h-3 w-3"}),"View CLI Documentation"]})})]}),i==="starting"&&n.jsxs("div",{className:"text-center space-y-4 py-4",children:[n.jsx(_e,{className:"h-8 w-8 animate-spin mx-auto text-primary"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"Starting authentication..."})]}),i==="waiting"&&c&&n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"text-center space-y-2",children:[n.jsx(_e,{className:"h-8 w-8 animate-spin mx-auto text-primary"}),n.jsx("p",{className:"text-sm font-medium",children:"Complete authentication in your browser"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"A browser window should have opened. Select a project to link."})]}),n.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 space-y-2",children:[n.jsx("p",{className:"text-xs text-muted-foreground",children:"If the browser didn't open, click below or copy the URL:"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsxs(T,{variant:"outline",size:"sm",className:"flex-1",onClick:()=>window.open(c,"_blank"),children:[n.jsx(an,{className:"h-3 w-3 mr-1"}),"Open in Browser"]}),n.jsx(T,{variant:"outline",size:"sm",onClick:p,children:n.jsx(rn,{className:"h-3 w-3"})})]})]})]}),i==="completed"&&k&&n.jsxs("div",{className:"text-center space-y-4 py-4",children:[n.jsx(Ry,{className:"h-12 w-12 mx-auto text-green-500"}),n.jsxs("div",{children:[n.jsx("p",{className:"font-medium",children:"Successfully Connected!"}),n.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Linked to"," ",k.workspaceName&&`${k.workspaceName} / `,k.projectName]})]})]}),i==="error"&&n.jsxs("div",{className:"text-center space-y-4 py-4",children:[n.jsx(Jt,{className:"h-12 w-12 mx-auto text-destructive"}),n.jsxs("div",{children:[n.jsx("p",{className:"font-medium",children:"Authentication Failed"}),n.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:g||"Something went wrong"})]}),n.jsx(T,{onClick:j,variant:"outline",children:"Try Again"})]})]})]})})}function h1({status:e,className:t}){const s=()=>{switch(e){case"success":return n.jsx(vt,{className:"h-3 w-3"});case"failed":return n.jsx(Da,{className:"h-3 w-3"});case"running":return n.jsx(_e,{className:"h-3 w-3 animate-spin"});default:return n.jsx(hi,{className:"h-3 w-3"})}},r=()=>{switch(e){case"success":return"default";case"failed":return"destructive";default:return"secondary"}};return n.jsxs(ue,{variant:r(),className:Y("text-[10px] h-5 px-2 font-medium flex items-center gap-1",t),children:[s(),e]})}const ve=d.forwardRef(({className:e,type:t,...s},r)=>n.jsx("input",{type:t,className:Y("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...s}));ve.displayName="Input";function f1({open:e,onOpenChange:t,workspaceScenarios:s,allScenarios:r,onScenariosChange:i}){const{toast:a}=Pt(),[o,l]=d.useState(""),[c,u]=d.useState("name"),[m,f]=d.useState("all"),[g,R]=d.useState(new Set);d.useEffect(()=>{e&&l("")},[e]);const k=N=>s.includes(N),C=d.useMemo(()=>{let N=[...r];if(o){const S=o.toLowerCase();N=N.filter(P=>{var b;return P.name.toLowerCase().includes(S)||P.key.toLowerCase().includes(S)||((b=P.url)==null?void 0:b.toLowerCase().includes(S))})}return m==="in-workspace"?N=N.filter(S=>k(S.key)):m==="not-in-workspace"&&(N=N.filter(S=>!k(S.key))),N.sort((S,P)=>{var b,O;switch(c){case"name":return S.name.localeCompare(P.name);case"key":return S.key.localeCompare(P.key);case"steps":return(((b=P.steps)==null?void 0:b.length)||0)-(((O=S.steps)==null?void 0:O.length)||0);default:return 0}}),N},[r,o,m,c,s]),j=async N=>{const S=k(N);R(P=>new Set(P).add(N));try{if(S){const P=await fetch(`/api/workspace/scenarios/${encodeURIComponent(N)}`,{method:"DELETE"});if(!P.ok){const b=await P.json();throw new Error(b.error||"Failed to remove scenario")}a({title:"Removed",description:`${N} removed from workspace`})}else{const P=await fetch("/api/workspace/scenarios",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:[N]})});if(!P.ok){const b=await P.json();throw new Error(b.error||"Failed to add scenario")}a({title:"Added",description:`${N} added to workspace`})}i()}catch(P){const b=P instanceof Error?P.message:"Operation failed";a({title:"Error",description:b,variant:"destructive"})}finally{R(P=>{const b=new Set(P);return b.delete(N),b})}},p=async()=>{const N=C.filter(S=>!k(S.key));if(N.length!==0){R(new Set(N.map(S=>S.key)));try{const S=await fetch("/api/workspace/scenarios",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:N.map(P=>P.key)})});if(!S.ok){const P=await S.json();throw new Error(P.error||"Failed to add scenarios")}a({title:"Added",description:`Added ${N.length} scenarios to workspace`}),i()}catch(S){const P=S instanceof Error?S.message:"Operation failed";a({title:"Error",description:P,variant:"destructive"})}finally{R(new Set)}}},h=async()=>{const N=C.filter(S=>k(S.key));if(N.length!==0){R(new Set(N.map(S=>S.key)));try{for(const S of N)await fetch(`/api/workspace/scenarios/${encodeURIComponent(S.key)}`,{method:"DELETE"});a({title:"Removed",description:`Removed ${N.length} scenarios from workspace`}),i()}catch(S){const P=S instanceof Error?S.message:"Operation failed";a({title:"Error",description:P,variant:"destructive"})}finally{R(new Set)}}},x=r.filter(N=>k(N.key)).length,w=r.length-x;return n.jsx(st,{open:e,onOpenChange:t,children:n.jsxs(nt,{className:"max-w-2xl max-h-[85vh] flex flex-col",children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:"Manage Workspace Scenarios"}),n.jsxs(ot,{children:["Add or remove scenarios from your workspace. ",x," of"," ",r.length," scenarios selected."]})]}),n.jsxs("div",{className:"space-y-3 py-2",children:[n.jsxs("div",{className:"relative",children:[n.jsx(Zc,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),n.jsx(ve,{placeholder:"Search scenarios...",value:o,onChange:N=>l(N.target.value),className:"pl-9"})]}),n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsxs("div",{className:"flex items-center gap-1 text-xs",children:[n.jsx(Ly,{className:"h-3.5 w-3.5 text-muted-foreground"}),n.jsxs(T,{variant:m==="all"?"secondary":"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>f("all"),children:["All (",r.length,")"]}),n.jsxs(T,{variant:m==="in-workspace"?"secondary":"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>f("in-workspace"),children:["In Workspace (",x,")"]}),n.jsxs(T,{variant:m==="not-in-workspace"?"secondary":"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>f("not-in-workspace"),children:["Available (",w,")"]})]}),n.jsx("div",{className:"flex-1"}),n.jsxs("div",{className:"flex items-center gap-1 text-xs",children:[n.jsx(Gc,{className:"h-3.5 w-3.5 text-muted-foreground"}),n.jsx(T,{variant:c==="name"?"secondary":"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>u("name"),children:"Name"}),n.jsx(T,{variant:c==="key"?"secondary":"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>u("key"),children:"Key"}),n.jsx(T,{variant:c==="steps"?"secondary":"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>u("steps"),children:"Steps"})]})]}),C.length>0&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:p,disabled:C.every(N=>k(N.key))||g.size>0,children:[n.jsx(as,{className:"h-3 w-3 mr-1"}),"Add All Visible"]}),n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:h,disabled:!C.some(N=>k(N.key))||g.size>0,children:[n.jsx(Zp,{className:"h-3 w-3 mr-1"}),"Remove All Visible"]})]})]}),n.jsx("div",{className:"flex-1 overflow-y-auto min-h-0 -mx-6 px-6",children:C.length===0?n.jsx("div",{className:"text-center py-8 text-muted-foreground text-sm",children:o?"No scenarios match your search":"No scenarios available"}):n.jsx("div",{className:"space-y-1 pb-4",children:C.map(N=>{var b;const S=k(N.key),P=g.has(N.key);return n.jsxs("div",{className:Y("flex items-center gap-3 p-3 rounded-lg border transition-colors cursor-pointer",S?"bg-primary/5 border-primary/20 hover:bg-primary/10":"bg-card border-border hover:bg-accent/50"),onClick:()=>!P&&j(N.key),children:[n.jsx("div",{className:Y("w-5 h-5 rounded border flex items-center justify-center transition-colors",S?"bg-primary border-primary":"border-muted-foreground/30"),children:P?n.jsx(_e,{className:"h-3 w-3 animate-spin text-primary-foreground"}):S?n.jsx(ro,{className:"h-3 w-3 text-primary-foreground"}):null}),n.jsx(Rn,{className:"h-4 w-4 text-muted-foreground shrink-0"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm font-medium truncate",children:N.name}),n.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:N.key})]}),N.url&&n.jsx("p",{className:"text-xs text-muted-foreground truncate",children:N.url})]}),n.jsxs(ue,{variant:"secondary",className:"text-xs shrink-0",children:[((b=N.steps)==null?void 0:b.length)||0," steps"]})]},N.key)})})}),n.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[n.jsxs("p",{className:"text-sm text-muted-foreground",children:[x," scenario",x!==1?"s":""," in workspace"]}),n.jsx(T,{onClick:()=>t(!1),children:"Done"})]})]})})}function p1(){var V,y,_,F,$;const{toast:e}=Pt(),{trackJob:t}=ji(),[s,r]=d.useState({workspace:null,allScenarios:[],assetGroups:[],jobs:[],settings:null,loading:!0,error:null}),[i,a]=d.useState(new Set),[o,l]=d.useState(!1),[c,u]=d.useState(!1),[m,f]=d.useState(!1),[g,R]=d.useState(new Set),[k,C]=d.useState(!1),[j,p]=d.useState(0),h=d.useCallback(async(E=!1)=>{var A,z;try{E&&C(!0);const[W,J,G,fe]=await Promise.all([fetch("/api/status"),fetch("/api/workspace"),fetch("/api/output"),fetch("/api/config")]);if(!W.ok)throw new Error(`Status API failed: ${W.status}`);const[ye,ge,Re,U]=await Promise.all([W.json(),J.json(),G.json(),fe.json()]);let X=ge.workspace;if(!X){const ce=await fetch("/api/workspace",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:"Default Workspace"})});ce.ok&&(X=(await ce.json()).workspace)}const Z=((A=X==null?void 0:X.allScenarios)==null?void 0:A.length)>0?X.allScenarios:((z=U.config)==null?void 0:z.scenarios)||[];r({workspace:X,allScenarios:Z,assetGroups:Re.groups||[],jobs:ye.jobs||[],settings:ye.settings||null,loading:!1,error:null}),E&&e({title:"Refreshed",description:"Data updated successfully"})}catch(W){const J=W instanceof Error?W.message:"Failed to load data";console.error("Failed to load data:",W),r(G=>({...G,loading:!1,error:J})),E&&e({title:"Error",description:J,variant:"destructive"})}finally{C(!1)}},[e]);d.useEffect(()=>{h()},[h]),d.useEffect(()=>{if(!s.jobs.some(z=>z.status==="running"||z.status==="pending")&&j===0)return;const A=setInterval(()=>h(!1),3e3);return()=>clearInterval(A)},[s.jobs,h,j]);const x=async E=>{try{const A=await fetch("/api/workspace/scenarios",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:[E]})});if(!A.ok){const W=await A.json();throw new Error(W.error||"Failed to add scenario")}const z=await A.json();z.workspace&&(r(W=>({...W,workspace:z.workspace})),e({title:"Added",description:`Added ${E} to workspace`}))}catch(A){const z=A instanceof Error?A.message:"Failed to add scenario";console.error("Add scenario error:",A),e({title:"Error",description:z,variant:"destructive"})}},w=async E=>{try{const A=await fetch(`/api/workspace/scenarios/${encodeURIComponent(E)}`,{method:"DELETE"});if(!A.ok){const W=await A.json();throw new Error(W.error||"Failed to remove scenario")}const z=await A.json();z.workspace&&(r(W=>({...W,workspace:z.workspace})),e({title:"Removed",description:`Removed ${E} from workspace`}))}catch(A){const z=A instanceof Error?A.message:"Failed to remove scenario";console.error("Remove scenario error:",A),e({title:"Error",description:z,variant:"destructive"})}},N=async E=>{R(A=>new Set(A).add(E));try{const A=await fetch("/api/jobs/run",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:[E]})}),z=await A.json();if(!A.ok)throw new Error(z.error||`Failed to start capture (${A.status})`);if(z.ok&&z.job)t(z.job.id,E),await h(!1),p(W=>W+1),setTimeout(()=>p(0),1e4);else throw new Error(z.error||"Unknown error starting job")}catch(A){const z=A instanceof Error?A.message:"Failed to start capture";console.error("Run scenario error:",A),e({title:"Capture Failed",description:z,variant:"destructive"})}finally{R(A=>{const z=new Set(A);return z.delete(E),z})}},S=E=>{a(A=>{const z=new Set(A);return z.has(E)?z.delete(E):z.add(E),z})},P=E=>s.assetGroups.filter(A=>A.scenarioKey===E),b=((V=s.workspace)==null?void 0:V.resolvedScenarios)||[],O=s.allScenarios.filter(E=>{var A,z;return!((z=(A=s.workspace)==null?void 0:A.scenarios)!=null&&z.includes(E.key))}),D=((y=s.settings)==null?void 0:y.isAuthenticated)||!1,v=s.assetGroups.length>0,L=s.jobs.filter(E=>E.status==="running"||E.status==="pending");return s.loading?n.jsx("div",{className:"flex items-center justify-center h-full",children:n.jsxs("div",{className:"text-center",children:[n.jsx(_e,{className:"h-8 w-8 animate-spin text-muted-foreground mx-auto mb-3"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading workspace..."})]})}):s.error&&!s.workspace?n.jsx("div",{className:"flex items-center justify-center h-full p-6",children:n.jsx(he,{className:"max-w-md w-full",children:n.jsxs(me,{className:"pt-6 text-center",children:[n.jsx(Jt,{className:"h-10 w-10 text-destructive mx-auto mb-3"}),n.jsx("h2",{className:"text-lg font-semibold mb-2",children:"Failed to Load"}),n.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:s.error}),n.jsxs(T,{onClick:()=>h(!0),children:[n.jsx(_t,{className:"h-4 w-4 mr-2"}),"Retry"]})]})})}):n.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[n.jsx("div",{className:"shrink-0 px-6 py-4 border-b border-border bg-background",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("h1",{className:"text-lg font-semibold text-foreground",children:((_=s.workspace)==null?void 0:_.name)||"Workspace"}),n.jsxs("p",{className:"text-sm text-muted-foreground",children:[b.length," scenario",b.length!==1?"s":"",v&&` • ${s.assetGroups.length} captured variant${s.assetGroups.length!==1?"s":""}`]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(T,{variant:"outline",size:"icon",onClick:()=>h(!0),disabled:k,title:"Refresh",children:n.jsx(_t,{className:Y("h-4 w-4",k&&"animate-spin")})}),n.jsxs(T,{variant:"outline",size:"sm",onClick:()=>f(!0),className:"gap-1.5",children:[n.jsx(Yy,{className:"h-3.5 w-3.5"}),"Manage Scenarios"]}),D&&n.jsxs(T,{size:"sm",onClick:()=>u(!0),disabled:!v,className:"gap-1.5",children:[n.jsx(on,{className:"h-3.5 w-3.5"}),"Commit"]})]})]})}),n.jsxs("div",{className:"flex-1 overflow-auto p-6 space-y-6",children:[!D&&n.jsx(he,{className:"border-yellow-500/30 bg-yellow-50/5",children:n.jsx(me,{className:"py-4",children:n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("div",{className:"p-2 rounded-full bg-yellow-500/10",children:n.jsx(em,{className:"h-4 w-4 text-yellow-500"})}),n.jsxs("div",{className:"flex-1",children:[n.jsx("p",{className:"text-sm font-medium text-foreground",children:"Connect to Platform"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Authenticate to publish assets and sync with the platform"})]}),n.jsx(T,{size:"sm",variant:"outline",onClick:()=>l(!0),children:"Connect"})]})})}),L.length>0&&n.jsxs(he,{children:[n.jsx(ke,{className:"py-3 px-4",children:n.jsxs(be,{className:"text-sm font-medium flex items-center gap-2",children:[n.jsx(_e,{className:"h-4 w-4 animate-spin"}),"Active Jobs"]})}),n.jsx(me,{className:"px-4 pb-4",children:n.jsx("div",{className:"space-y-2",children:L.map(E=>n.jsxs("div",{className:"flex items-center justify-between p-2 rounded-md bg-muted/50",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(h1,{status:E.status}),n.jsxs("span",{className:"text-sm",children:[E.type==="run"?"Capturing":E.type,E.scenarioKey&&`: ${E.scenarioKey}`]})]}),E.progress!==void 0&&n.jsxs("span",{className:"text-xs text-muted-foreground",children:[E.progress,"%"]})]},E.id))})})]}),n.jsxs("section",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(fi,{className:"h-4 w-4 text-muted-foreground"}),n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Workspace Scenarios"})]}),n.jsxs("button",{onClick:()=>f(!0),className:"text-xs text-muted-foreground hover:text-foreground",children:["View all ",s.allScenarios.length," scenarios →"]})]}),b.length===0?n.jsx(he,{className:"border-dashed",children:n.jsxs(me,{className:"py-8 text-center",children:[n.jsx(fi,{className:"h-8 w-8 mx-auto text-muted-foreground/50 mb-3"}),n.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"No scenarios in workspace"}),n.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Add scenarios to start capturing and publishing visuals"}),n.jsxs(T,{variant:"outline",size:"sm",onClick:()=>f(!0),children:[n.jsx(as,{className:"h-3.5 w-3.5 mr-1.5"}),"Add First Scenario"]})]})}):n.jsx("div",{className:"space-y-2",children:b.map(E=>{const A=P(E.key),z=i.has(E.key),W=g.has(E.key)||L.some(J=>J.scenarioKey===E.key);return n.jsxs(he,{className:"overflow-hidden",children:[n.jsxs("div",{className:Y("flex items-center gap-3 px-4 py-3 cursor-pointer hover:bg-accent/50 transition-colors",z&&"bg-accent/30"),onClick:()=>S(E.key),children:[n.jsx("button",{className:"text-muted-foreground",children:z?n.jsx(zs,{className:"h-4 w-4"}):n.jsx(Ps,{className:"h-4 w-4"})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm font-medium text-foreground",children:E.name||E.key}),n.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:E.key})]}),E.url&&n.jsx("p",{className:"text-xs text-muted-foreground truncate",children:E.url})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[A.length>0&&n.jsxs(ue,{variant:"secondary",className:"text-xs",children:[A.reduce((J,G)=>J+G.assets.length,0)," ","assets"]}),n.jsxs("div",{className:"flex items-center gap-1",onClick:J=>J.stopPropagation(),children:[n.jsx(T,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>N(E.key),disabled:W,children:W?n.jsx(_e,{className:"h-3.5 w-3.5 animate-spin"}):n.jsx(Ts,{className:"h-3.5 w-3.5"})}),n.jsx(T,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>w(E.key),children:n.jsx(ps,{className:"h-3.5 w-3.5"})})]})]})]}),z&&n.jsxs("div",{className:"border-t border-border bg-muted/30 px-4 py-3",children:[A.length===0?n.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[n.jsx(Jt,{className:"h-3.5 w-3.5"}),"No captures yet. Click play to run this scenario."]}):n.jsx("div",{className:"space-y-3",children:A.map((J,G)=>n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[n.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:J.variationSlug==="default"?"Default":J.variationSlug}),n.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",J.assets.length," file",J.assets.length!==1?"s":"",")"]})]}),n.jsxs("div",{className:"grid grid-cols-4 sm:grid-cols-6 md:grid-cols-8 gap-2",children:[J.assets.slice(0,8).map((fe,ye)=>n.jsx(Kt,{to:`/assets/${J.scenarioKey}/${J.variationSlug}/${fe.captureKey}`,className:"aspect-video rounded-md overflow-hidden border border-border hover:border-primary/50 transition-colors",children:fe.filename.endsWith(".mp4")?n.jsx("div",{className:"w-full h-full bg-muted flex items-center justify-center",children:n.jsx(io,{className:"h-4 w-4 text-muted-foreground"})}):n.jsx("img",{src:fe.url,alt:fe.captureKey,className:"w-full h-full object-cover"})},ye)),J.assets.length>8&&n.jsx(Kt,{to:"/assets",className:"aspect-video rounded-md overflow-hidden border border-border bg-muted flex items-center justify-center hover:bg-accent transition-colors",children:n.jsxs("span",{className:"text-xs text-muted-foreground",children:["+",J.assets.length-8]})})]})]},`${J.scenarioKey}-${J.variationSlug}-${G}`))}),n.jsx("div",{className:"mt-3 pt-3 border-t border-border",children:n.jsx(Kt,{to:`/scenarios/${E.key}`,className:"text-xs text-primary hover:underline",children:"Edit scenario →"})})]})]},E.key)})})]}),O.length>0&&b.length>0&&n.jsxs("section",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(as,{className:"h-4 w-4 text-muted-foreground"}),n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Quick Add"})]}),n.jsx("button",{onClick:()=>f(!0),className:"text-xs text-muted-foreground hover:text-foreground",children:"Manage all →"})]}),n.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2",children:O.slice(0,3).map(E=>n.jsxs("button",{onClick:()=>x(E.key),className:"flex items-center gap-3 p-3 rounded-lg border border-border bg-card hover:bg-accent/50 transition-colors text-left group",children:[n.jsx("div",{className:"p-1.5 rounded bg-muted group-hover:bg-primary/10 transition-colors",children:n.jsx(as,{className:"h-3.5 w-3.5 text-muted-foreground group-hover:text-primary"})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-foreground truncate",children:E.name||E.key}),n.jsx("div",{className:"text-xs text-muted-foreground font-mono truncate",children:E.key})]})]},E.key))})]}),((F=s.workspace)==null?void 0:F.commits)&&s.workspace.commits.length>0&&n.jsxs("section",{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n.jsx(vt,{className:"h-4 w-4 text-muted-foreground"}),n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Recent Commits"})]}),n.jsx("div",{className:"space-y-2",children:s.workspace.commits.slice(-3).reverse().map(E=>n.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-border bg-card",children:[n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-foreground truncate",children:E.message}),n.jsxs("div",{className:"text-xs text-muted-foreground",children:[E.scenarioKeys.length," scenario",E.scenarioKeys.length!==1?"s":""," • ",E.assetCount," asset",E.assetCount!==1?"s":""," • ",new Date(E.createdAt).toLocaleDateString()]})]}),E.platformCommitId?n.jsx(ue,{variant:"secondary",className:"text-xs bg-green-500/10 text-green-500",children:"Synced"}):n.jsx(ue,{variant:"secondary",className:"text-xs",children:"Local"})]},E.id))})]})]}),n.jsx(wi,{open:o,onOpenChange:l,onAuthenticated:h}),n.jsx(f1,{open:m,onOpenChange:f,workspaceScenarios:(($=s.workspace)==null?void 0:$.scenarios)||[],allScenarios:s.allScenarios,onScenariosChange:h}),n.jsx(ho,{open:c,onOpenChange:u,onConfirm:async(E,A)=>{var z;try{const W=await fetch("/api/jobs/publish",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({selectedGroups:E,commitMessage:A})}),J=await W.json();if(W.status===401||J.authRequired){u(!1),e({title:"Authentication Required",description:"Your API key has expired. Please reconnect.",variant:"destructive"}),l(!0);return}W.ok&&J.ok?(u(!1),(z=J.job)!=null&&z.id&&t(J.job.id),h(),p(G=>G+1),setTimeout(()=>p(0),1e4)):e({title:"Error",description:J.error||"Failed to create publish job",variant:"destructive"})}catch{e({title:"Error",description:"Failed to connect to server",variant:"destructive"})}}})]})}const q=d.forwardRef(({className:e,...t},s)=>n.jsx("label",{ref:s,className:Y("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",e),...t}));q.displayName="Label";function Fm(e){const t=d.useRef(!1);return d.useCallback(async()=>{if(!t.current){t.current=!0;try{await e()}finally{t.current=!1}}},[e])}function yh(e){if(!e)return"Never";const t=new Date(e),r=new Date().getTime()-t.getTime(),i=Math.floor(r/(1e3*60)),a=Math.floor(r/(1e3*60*60)),o=Math.floor(r/(1e3*60*60*24));return i<1?"Just now":i<60?`${i}m ago`:a<24?`${a}h ago`:o<7?`${o}d ago`:t.toLocaleDateString()}function Pr(e){if(e.category)return e.category;const s=(e.key||"").split("-");return s.length>=2?s[0]:"other"}function m1(e){return e.split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function x1(){const e=Os(),{toast:t}=Pt(),{trackJob:s}=ji(),[r,i]=d.useState([]),[a,o]=d.useState(!0),[l,c]=d.useState(!1),[u,m]=d.useState({name:"",key:"",url:""}),[f,g]=d.useState(!1),[R,k]=d.useState(""),[C,j]=d.useState("grouped"),[p,h]=d.useState(new Set),[x,w]=d.useState(new Set),[N,S]=d.useState(!1),[P,b]=d.useState(!1),[O,D]=d.useState(null),[v,L]=d.useState({}),[V,y]=d.useState(!0),[_,F]=d.useState("step-by-step-images"),[$,E]=d.useState(null),[A,z]=d.useState(!0),[W,J]=d.useState(!1),[G,fe]=d.useState("scenarios"),[ye,ge]=d.useState(""),[Re,U]=d.useState("lastRun"),[X,Z]=d.useState(!1),ce=d.useCallback(async()=>{var B,oe,se;o(!0);try{const[re,qe]=await Promise.all([fetch("/api/scenarios/metadata"),fetch("/api/config")]),[De,At]=await Promise.all([re.json(),qe.json()]);if(i(De.scenarios||[]),D(((B=At.config)==null?void 0:B.variants)||null),z(((se=(oe=At.config)==null?void 0:oe.diffing)==null?void 0:se.enabled)!==!1),x.size===0){const I=new Set((De.scenarios||[]).map(ee=>Pr(ee)));w(I)}}catch(re){console.error("Failed to load scenarios:",re)}finally{o(!1)}},[x.size]);d.useEffect(()=>{ce()},[ce]);const ie=Fm(ce),ae=async()=>{try{const oe=await fetch(G==="scenarios"?"/api/config/scenarios":"/api/assets",{method:"DELETE"}),se=await oe.json();oe.ok?(t({title:"Success",description:G==="scenarios"?`Deleted ${se.deleted} scenario(s)`:`Deleted ${se.deleted} asset file(s)`,variant:"success"}),J(!1),G==="scenarios"&&ce()):t({title:"Error",description:se.error||"Failed to delete",variant:"destructive"})}catch(B){console.error("Failed to bulk delete:",B),t({title:"Error",description:"Failed to perform bulk delete",variant:"destructive"})}},Se=d.useMemo(()=>{let B=[...r];if(ye){const oe=ye.toLowerCase();B=B.filter(se=>se.name.toLowerCase().includes(oe)||se.key.toLowerCase().includes(oe)||se.url.toLowerCase().includes(oe)||Pr(se).toLowerCase().includes(oe))}return B.sort((oe,se)=>{var qe,De,At,I,ee,pe;let re=0;switch(Re){case"name":re=oe.name.localeCompare(se.name);break;case"key":re=oe.key.localeCompare(se.key);break;case"steps":re=(((qe=oe.steps)==null?void 0:qe.length)||0)-(((De=se.steps)==null?void 0:De.length)||0);break;case"lastRun":const Ce=((At=oe._metadata)==null?void 0:At.lastRunAt)||((I=oe._metadata)==null?void 0:I.createdAt)||"",Oe=((ee=se._metadata)==null?void 0:ee.lastRunAt)||((pe=se._metadata)==null?void 0:pe.createdAt)||"";re=Ce.localeCompare(Oe);break}return X?re:-re}),B},[r,ye,Re,X]),Ie=d.useMemo(()=>{const B={};for(const se of Se){const re=Pr(se);B[re]||(B[re]=[]),B[re].push(se)}return Object.entries(B).sort(([se],[re])=>se==="other"?1:re==="other"?-1:se.localeCompare(re)).map(([se,re])=>({key:se,name:m1(se),scenarios:re,isExpanded:x.has(se)}))},[Se,x]),mt=B=>{w(oe=>{const se=new Set(oe);return se.has(B)?se.delete(B):se.add(B),se})},Nt=B=>{h(oe=>{const se=new Set(oe);return se.has(B)?se.delete(B):se.add(B),se})},Ft=B=>{const oe=B.scenarios.map(re=>re.key),se=oe.every(re=>p.has(re));h(re=>{const qe=new Set(re);return se?oe.forEach(De=>qe.delete(De)):oe.forEach(De=>qe.add(De)),qe})},Yt=()=>{const B=Se.map(oe=>oe.key);h(new Set(B))},$t=()=>{h(new Set)},kt=async()=>{if(p.size===0){t({title:"No scenarios selected",description:"Please select at least one scenario to run",variant:"destructive"});return}b(!0);try{const oe={scenarioKeys:Array.from(p),format:_,diff:$===null?A:$};!V&&Object.keys(v).length>0&&(oe.variant=v);const se=await fetch("/api/jobs/run",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(oe)}),re=await se.json();if(!se.ok)throw new Error(re.error||"Failed to start capture job");re.job&&(s(re.job.id,`${p.size} scenarios`),S(!1),$t())}catch(B){const oe=B instanceof Error?B.message:"Failed to start capture";t({title:"Error",description:oe,variant:"destructive"})}finally{b(!1)}},Tt=B=>{Re===B?Z(!X):(U(B),Z(!0))},Vt=async()=>{var B;if(!u.name||!u.key||!u.url){t({title:"Error",description:"Please fill in all required fields",variant:"destructive"});return}if(!/^[a-z0-9-]+$/.test(u.key)){t({title:"Error",description:"Key must contain only lowercase letters, numbers, and hyphens",variant:"destructive"});return}try{const oe=await fetch("/api/config/scenarios",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...u,steps:[]})});if(oe.ok){t({title:"Success",description:"Scenario created successfully",variant:"success"}),c(!1),m({name:"",key:"",url:""});const re=await(await fetch("/api/config")).json();i(((B=re.config)==null?void 0:B.scenarios)||[]),e(`/scenarios/${u.key}`)}else{const se=await oe.json();t({title:"Error",description:se.error||"Failed to create scenario",variant:"destructive"})}}catch(oe){console.error("Failed to create scenario:",oe),t({title:"Error",description:"Failed to create scenario",variant:"destructive"})}},je=B=>B.toLowerCase().replace(/[^a-z0-9\s-]/g,"").trim().replace(/\s+/g,"-").replace(/-+/g,"-");return n.jsxs("div",{"data-testid":"studio-scenarios","data-loaded":"true",className:"p-5 space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 pb-3",children:[n.jsxs("div",{children:[n.jsx("h1",{className:"text-xl font-bold tracking-tight",children:"Scenarios"}),n.jsxs("p",{className:"text-xs text-muted-foreground mt-1 font-normal",children:[r.length," scenarios in ",Ie.length," categories"]})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx(T,{variant:"outline",size:"icon",onClick:ie,title:"Refresh",className:"shadow-sm",disabled:a,children:n.jsx(_t,{className:`h-4 w-4 ${a?"animate-spin":""}`})}),n.jsxs(T,{variant:"outline",size:"sm",onClick:()=>{fe("scenarios"),J(!0)},title:"Delete all scenarios",className:"shadow-sm text-destructive hover:text-destructive",children:[n.jsx(ps,{className:"h-3.5 w-3.5 mr-1.5"}),"Delete All"]}),n.jsxs(T,{size:"sm",onClick:()=>e("/recorder"),className:"shadow-sm",children:[n.jsx(as,{className:"h-3.5 w-3.5 mr-1.5"}),"New Scenario"]})]})]}),r.length>0&&n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[n.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-md",children:[n.jsx(Zc,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),n.jsx(ve,{placeholder:"Search scenarios or categories...",value:ye,onChange:B=>ge(B.target.value),className:"pl-9 h-9"})]}),n.jsxs("div",{className:"flex items-center gap-1 border rounded-md p-0.5",children:[n.jsxs(T,{variant:C==="grouped"?"secondary":"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>j("grouped"),children:[n.jsx(Kr,{className:"h-3 w-3 mr-1"}),"Grouped"]}),n.jsxs(T,{variant:C==="flat"?"secondary":"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>j("flat"),children:[n.jsx(Rn,{className:"h-3 w-3 mr-1"}),"Flat"]})]}),n.jsxs("div",{className:"flex items-center gap-1 text-xs",children:[n.jsx(Gc,{className:"h-3.5 w-3.5 text-muted-foreground mr-1"}),n.jsxs(T,{variant:Re==="lastRun"?"secondary":"ghost",size:"sm",className:"h-8 text-xs",onClick:()=>Tt("lastRun"),children:["Last Run ",Re==="lastRun"&&(X?"↑":"↓")]}),n.jsxs(T,{variant:Re==="name"?"secondary":"ghost",size:"sm",className:"h-8 text-xs",onClick:()=>Tt("name"),children:["Name ",Re==="name"&&(X?"↑":"↓")]})]})]}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(T,{variant:"ghost",size:"sm",className:"h-8 text-xs",onClick:p.size>0?$t:Yt,children:p.size>0?n.jsxs(n.Fragment,{children:[n.jsx(ed,{className:"h-3.5 w-3.5 mr-1"}),"Clear (",p.size,")"]}):n.jsxs(n.Fragment,{children:[n.jsx(Qc,{className:"h-3.5 w-3.5 mr-1"}),"Select All"]})}),p.size>0&&n.jsxs(ue,{variant:"secondary",className:"text-xs",children:[p.size," selected"]})]}),p.size>0&&n.jsxs(T,{size:"sm",onClick:()=>S(!0),className:"gap-1.5",children:[n.jsx(Ts,{className:"h-3.5 w-3.5"}),"Run Selected (",p.size,")"]})]})]}),a?n.jsx("div",{className:"text-muted-foreground",children:"Loading scenarios..."}):r.length===0?n.jsxs(he,{children:[n.jsxs(ke,{children:[n.jsx(be,{children:"No Scenarios"}),n.jsx(at,{children:"Create your first scenario to get started"})]}),n.jsx(me,{children:n.jsxs(T,{onClick:()=>c(!0),children:[n.jsx(as,{className:"h-4 w-4 mr-2"}),"Create Scenario"]})})]}):Se.length===0?n.jsx(he,{children:n.jsxs(me,{className:"py-8 text-center",children:[n.jsxs("p",{className:"text-muted-foreground",children:['No scenarios match "',ye,'"']}),n.jsx(T,{variant:"link",onClick:()=>ge(""),children:"Clear search"})]})}):C==="grouped"?n.jsx("div",{className:"space-y-4",children:Ie.map(B=>{const oe=B.scenarios.every(re=>p.has(re.key)),se=B.scenarios.some(re=>p.has(re.key));return n.jsxs(he,{className:"overflow-hidden",children:[n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 bg-muted/30 border-b cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>mt(B.key),children:[n.jsx(ns,{checked:oe,className:Y("data-[state=indeterminate]:bg-primary/50",se&&!oe&&"data-[state=checked]:bg-primary/50"),onClick:re=>{re.stopPropagation(),Ft(B)}}),n.jsxs("div",{className:"flex items-center gap-2 flex-1",children:[B.isExpanded?n.jsx(zs,{className:"h-4 w-4 text-muted-foreground"}):n.jsx(Ps,{className:"h-4 w-4 text-muted-foreground"}),n.jsx(fi,{className:"h-4 w-4 text-muted-foreground"}),n.jsx("span",{className:"font-medium text-sm",children:B.name}),n.jsx(ue,{variant:"secondary",className:"text-xs",children:B.scenarios.length})]})]}),B.isExpanded&&n.jsx("div",{className:"divide-y",children:B.scenarios.map(re=>{var qe,De;return n.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 hover:bg-muted/20 transition-colors",children:[n.jsx(ns,{checked:p.has(re.key),onClick:At=>{At.stopPropagation(),Nt(re.key)}}),n.jsx(Kt,{to:`/scenarios/${re.key}`,className:"flex-1 min-w-0 group",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"text-sm font-medium group-hover:text-primary transition-colors truncate",children:re.name}),n.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[n.jsx("span",{className:"font-mono",children:re.key}),n.jsx("span",{children:"•"}),n.jsxs("span",{children:[((qe=re.steps)==null?void 0:qe.length)||0," steps"]}),n.jsx("span",{children:"•"}),n.jsx(hi,{className:"h-3 w-3"}),n.jsx("span",{children:yh(((De=re._metadata)==null?void 0:De.lastRunAt)||null)})]})]}),n.jsx(Ps,{className:"h-4 w-4 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity"})]})})]},re.key)})})]},B.key)})}):n.jsx("div",{className:"grid gap-3 md:grid-cols-2 lg:grid-cols-3",children:Se.map(B=>{var oe,se;return n.jsxs("div",{className:"relative",children:[n.jsx("div",{className:"absolute top-3 left-3 z-10",children:n.jsx(ns,{checked:p.has(B.key),onClick:re=>{re.stopPropagation(),Nt(B.key)},className:"bg-background"})}),n.jsx(Kt,{to:`/scenarios/${B.key}`,children:n.jsxs(he,{className:"dagster-card cursor-pointer group",children:[n.jsxs(ke,{className:"px-4 py-3 pl-10",children:[n.jsxs("div",{className:"flex items-start justify-between",children:[n.jsx(be,{className:"text-sm font-semibold group-hover:text-primary transition-colors",children:B.name}),n.jsx(Rn,{className:"h-3.5 w-3.5 text-muted-foreground group-hover:text-primary transition-colors"})]}),n.jsx(at,{className:"font-mono text-[10px] mt-1 text-muted-foreground",children:B.key})]}),n.jsx(me,{className:"px-4 pb-3",children:n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[n.jsx(ue,{variant:"outline",className:"text-[10px]",children:Pr(B)}),n.jsx("span",{children:"•"}),n.jsx("span",{className:"font-medium",children:((oe=B.steps)==null?void 0:oe.length)||0}),n.jsx("span",{children:"steps"})]}),n.jsx("div",{className:"flex items-center gap-3 text-[10px] text-muted-foreground",children:n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx(hi,{className:"h-3 w-3"}),n.jsx("span",{children:yh(((se=B._metadata)==null?void 0:se.lastRunAt)||null)})]})}),n.jsx("div",{className:"text-[10px] text-muted-foreground truncate font-mono",children:B.url})]})})]})})]},B.key)})}),n.jsx(st,{open:l,onOpenChange:c,children:n.jsxs(nt,{children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:"Create New Scenario"}),n.jsx(ot,{children:"Create a new visual scenario. You can add steps later."})]}),n.jsxs("div",{className:"space-y-4 py-4",children:[n.jsxs("div",{children:[n.jsx(q,{htmlFor:"name",children:"Name"}),n.jsx(ve,{id:"name",value:u.name,onChange:B=>{m({...u,name:B.target.value,key:u.key||je(B.target.value)})},placeholder:"Admin Dashboard"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"key",children:"Key"}),n.jsx(ve,{id:"key",value:u.key,onChange:B=>m({...u,key:B.target.value}),placeholder:"admin-dashboard",className:"font-mono"}),n.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Lowercase letters, numbers, and hyphens only"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"url",children:"URL"}),n.jsx(ve,{id:"url",value:u.url,onChange:B=>m({...u,url:B.target.value}),placeholder:"https://example.com/dashboard"})]})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>c(!1),children:"Cancel"}),n.jsx(T,{onClick:Vt,children:"Create Scenario"})]})]})}),n.jsx(st,{open:f,onOpenChange:g,children:n.jsxs(nt,{children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:"Record New Visual"}),n.jsx(ot,{children:"Create a new visual by recording it. Enter a title and the recorder will start."})]}),n.jsxs("div",{className:"space-y-4 py-4",children:[n.jsxs("div",{children:[n.jsx(q,{htmlFor:"record-title",children:"Visual Title"}),n.jsx(ve,{id:"record-title",value:R,onChange:B=>k(B.target.value),placeholder:"Admin Dashboard"})]}),n.jsxs("div",{className:"text-sm text-muted-foreground space-y-2",children:[n.jsx("p",{children:"This will:"}),n.jsxs("ul",{className:"list-disc list-inside space-y-1 ml-2",children:[n.jsx("li",{children:"Start a recording job"}),n.jsx("li",{children:"Open Chrome with remote debugging (if not already open)"}),n.jsx("li",{children:"Allow you to capture steps using keyboard shortcuts"})]}),n.jsx("p",{className:"mt-4 font-medium",children:"Keyboard shortcuts:"}),n.jsxs("ul",{className:"list-disc list-inside space-y-1 ml-2",children:[n.jsxs("li",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded text-xs",children:"C"})," ","- Capture"]}),n.jsxs("li",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded text-xs",children:"Q"})," ","- Quit and save"]})]})]})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>g(!1),children:"Cancel"}),n.jsx(T,{onClick:async()=>{if(!R.trim()){t({title:"Error",description:"Please enter a title",variant:"destructive"});return}try{const B=await fetch("/api/jobs/record",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:R})}),oe=await B.json();B.ok?(t({title:"Success",description:"Recording job started. Check Jobs page and your terminal.",variant:"success"}),g(!1),k("")):t({title:"Error",description:oe.error||"Failed to start recording",variant:"destructive"})}catch{t({title:"Error",description:"Failed to start recording",variant:"destructive"})}},children:"Start Recording"})]})]})}),n.jsx(st,{open:N,onOpenChange:S,children:n.jsxs(nt,{className:"max-w-lg",children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:"Run Selected Scenarios"}),n.jsxs(ot,{children:["Capture assets for ",p.size," selected scenario(s)"]})]}),n.jsxs("div",{className:"space-y-5 py-4",children:[n.jsxs("div",{className:"space-y-3",children:[n.jsx(q,{className:"text-sm font-medium",children:"Output Format"}),n.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[n.jsx("button",{type:"button",onClick:()=>F("step-by-step-images"),className:`p-3 rounded-lg border-2 text-left transition-all ${_==="step-by-step-images"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(fn,{className:"h-4 w-4"}),n.jsx("span",{className:"font-medium text-sm",children:"Screenshots"})]})}),n.jsx("button",{type:"button",onClick:()=>F("summary-video"),className:`p-3 rounded-lg border-2 text-left transition-all ${_==="summary-video"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(io,{className:"h-4 w-4"}),n.jsx("span",{className:"font-medium text-sm",children:"Video"})]})})]})]}),n.jsx("div",{className:"space-y-2",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(q,{className:"text-sm font-medium",children:"Visual Diffing"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Compare against approved baselines"})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[$===null&&A&&n.jsx("span",{className:"text-xs text-muted-foreground",children:"(default: on)"}),$===null&&!A&&n.jsx("span",{className:"text-xs text-muted-foreground",children:"(default: off)"}),n.jsx("input",{type:"checkbox",checked:$===null?A:$,onChange:B=>E(B.target.checked),className:"rounded h-4 w-4"})]})]})}),n.jsx("div",{className:"space-y-2",children:n.jsx("div",{className:"flex items-center justify-between",children:n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(q,{className:"text-sm font-medium",children:"Output Crop"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Crop is configured per-scenario in Details tab"})]})})}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Selected Scenarios:"}),n.jsx("div",{className:"max-h-28 overflow-auto border rounded-md p-2 space-y-1",children:Array.from(p).map(B=>{const oe=r.find(re=>re.key===B),se=oe?Pr(oe):B.split("-")[0]||"other";return n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx(ue,{variant:"outline",className:"text-[10px]",children:se}),n.jsx("span",{className:"font-medium",children:(oe==null?void 0:oe.name)||B})]},B)})})]}),(O==null?void 0:O.dimensions)&&Object.keys(O.dimensions).length>0&&n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(ns,{id:"run-all-variants",checked:V,onCheckedChange:B=>y(!!B)}),n.jsx(q,{htmlFor:"run-all-variants",className:"text-sm",children:"Run all variant combinations"})]}),!V&&n.jsxs("div",{className:"pl-6 space-y-2",children:[n.jsx("p",{className:"text-xs text-muted-foreground",children:"Select specific variant:"}),Object.entries(O.dimensions).map(([B,oe])=>n.jsxs("div",{className:"space-y-1",children:[n.jsx(q,{className:"text-xs",children:oe.label||B}),n.jsx("div",{className:"flex flex-wrap gap-1",children:oe.options&&Object.entries(oe.options).map(([se,re])=>n.jsx(ue,{variant:v[B]===se?"default":"outline",className:"cursor-pointer text-xs",onClick:()=>L(qe=>({...qe,[B]:se})),children:(re==null?void 0:re.name)||se},se))})]},B))]})]})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>S(!1),disabled:P,children:"Cancel"}),n.jsx(T,{onClick:kt,disabled:P,children:P?n.jsxs(n.Fragment,{children:[n.jsx(_t,{className:"h-4 w-4 mr-2 animate-spin"}),"Starting..."]}):n.jsxs(n.Fragment,{children:[n.jsx(Ts,{className:"h-4 w-4 mr-2"}),"Run ",p.size," Scenario(s)"]})})]})]})}),n.jsx(st,{open:W,onOpenChange:J,children:n.jsxs(nt,{children:[n.jsxs(Xe,{children:[n.jsxs(Ze,{className:"text-destructive",children:["Delete All"," ",G==="scenarios"?"Scenarios":"Assets","?"]}),n.jsx(ot,{children:G==="scenarios"?`This will permanently remove all ${r.length} scenarios from your config. This action cannot be undone.`:"This will permanently delete all captured asset files from the output folder. This action cannot be undone."})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>J(!1),children:"Cancel"}),n.jsxs(T,{variant:"destructive",onClick:ae,children:[n.jsx(ps,{className:"h-4 w-4 mr-2"}),"Delete All"]})]})]})})]})}const ud=d.createContext(void 0),hd=d.forwardRef(({className:e,value:t,onValueChange:s,...r},i)=>n.jsx(ud.Provider,{value:{value:t,onValueChange:s},children:n.jsx("div",{ref:i,className:Y("w-full",e),...r})}));hd.displayName="Tabs";const fd=d.forwardRef(({className:e,...t},s)=>n.jsx("div",{ref:s,className:Y("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",e),...t}));fd.displayName="TabsList";const sr=d.forwardRef(({className:e,value:t,...s},r)=>{const i=d.useContext(ud);if(!i)throw new Error("TabsTrigger must be used within Tabs");const a=i.value===t;return n.jsx("button",{ref:r,className:Y("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",a&&"bg-background text-foreground shadow-sm",e),onClick:()=>i.onValueChange(t),...s})});sr.displayName="TabsTrigger";const nr=d.forwardRef(({className:e,value:t,forceMount:s,...r},i)=>{const a=d.useContext(ud);if(!a)throw new Error("TabsContent must be used within Tabs");const o=a.value===t;return!o&&!s?null:n.jsx("div",{ref:i,className:Y("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",!o&&"hidden",e),...r})});nr.displayName="TabsContent";const Ni=d.createContext({open:!1,setOpen:()=>{},containerRef:{current:null}}),$m=({value:e,onValueChange:t,children:s,disabled:r})=>{const[i,a]=d.useState(!1),o=d.useRef(null);return d.useEffect(()=>{if(!i)return;const l=u=>{const m=u.target;o.current&&!o.current.contains(m)&&a(!1)},c=u=>{u.key==="Escape"&&a(!1)};return document.addEventListener("mousedown",l),document.addEventListener("keydown",c),()=>{document.removeEventListener("mousedown",l),document.removeEventListener("keydown",c)}},[i]),n.jsx(Ni.Provider,{value:{value:e,onValueChange:t,open:i,setOpen:a,containerRef:o},children:n.jsx("div",{ref:o,className:"relative inline-block","data-disabled":r,children:s})})},pd=d.forwardRef(({className:e,children:t,...s},r)=>{const{open:i,setOpen:a}=d.useContext(Ni);return n.jsxs("button",{ref:r,type:"button",onClick:()=>a(!i),className:Y("flex h-9 w-full items-center justify-between rounded-md border border-gray-600 bg-gray-800 px-3 py-2 text-sm text-white ring-offset-background placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...s,children:[t,n.jsx(zs,{className:Y("h-4 w-4 opacity-50 transition-transform ml-2 flex-shrink-0",i&&"rotate-180")})]})});pd.displayName="SelectTrigger";const Vm=({placeholder:e})=>{const{value:t}=d.useContext(Ni);return n.jsx("span",{className:"truncate",children:t||e})},md=d.forwardRef(({className:e,children:t,...s},r)=>{const{open:i}=d.useContext(Ni);return i?n.jsx("div",{ref:r,className:Y("absolute z-[100] mt-1 max-h-60 min-w-full overflow-auto rounded-md border border-gray-600 bg-gray-800 py-1 shadow-lg",e),...s,children:t}):null});md.displayName="SelectContent";const xd=d.forwardRef(({className:e,children:t,value:s,...r},i)=>{const{value:a,onValueChange:o,setOpen:l}=d.useContext(Ni),c=a===s,u=f=>{f.stopPropagation()},m=f=>{f.preventDefault(),f.stopPropagation(),o==null||o(s),l(!1)};return n.jsxs("div",{ref:i,className:Y("relative flex w-full cursor-pointer select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm text-white outline-none hover:bg-gray-700 focus:bg-gray-700",c&&"bg-gray-700",e),onMouseDown:u,onClick:m,...r,children:[n.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c&&n.jsx(ro,{className:"h-4 w-4"})}),t]})});xd.displayName="SelectItem";function g1({url:e,filename:t,onClose:s}){const[r,i]=d.useState(1),[a,o]=d.useState({x:0,y:0}),[l,c]=d.useState(!1),[u,m]=d.useState({x:0,y:0}),[f,g]=d.useState(0),R=.5,k=5,C=()=>{i(b=>Math.min(b+.25,k))},j=()=>{i(b=>Math.max(b-.25,R))},p=()=>{i(1),o({x:0,y:0}),g(0)},h=()=>{g(b=>(b+90)%360)},x=()=>{const b=document.createElement("a");b.href=e,b.download=t,document.body.appendChild(b),b.click(),document.body.removeChild(b)},w=b=>{r>1&&(c(!0),m({x:b.clientX-a.x,y:b.clientY-a.y}))},N=b=>{l&&r>1&&o({x:b.clientX-u.x,y:b.clientY-u.y})},S=()=>{c(!1)},P=b=>{b.preventDefault();const O=b.deltaY>0?-.1:.1;i(D=>Math.max(R,Math.min(k,D+O)))};return d.useEffect(()=>{const b=O=>{O.key==="Escape"&&s()};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[s]),n.jsx(st,{open:!0,onOpenChange:s,children:n.jsx(nt,{className:"max-w-[95vw] max-h-[95vh] p-0 bg-black/95 border-none",children:n.jsxs("div",{className:"relative w-full h-full flex flex-col",children:[n.jsxs("div",{className:"absolute top-0 left-0 right-0 z-10 flex items-center justify-between p-4 bg-black/50 backdrop-blur-sm",children:[n.jsx("div",{className:"flex items-center gap-2",children:n.jsx("span",{className:"text-white text-sm font-medium",children:t})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(T,{variant:"ghost",size:"sm",onClick:j,disabled:r<=R,className:"text-white hover:bg-white/20",children:n.jsx(l0,{className:"h-4 w-4"})}),n.jsxs("span",{className:"text-white text-sm min-w-[60px] text-center",children:[Math.round(r*100),"%"]}),n.jsx(T,{variant:"ghost",size:"sm",onClick:C,disabled:r>=k,className:"text-white hover:bg-white/20",children:n.jsx(o0,{className:"h-4 w-4"})}),n.jsx(T,{variant:"ghost",size:"sm",onClick:h,className:"text-white hover:bg-white/20",children:n.jsx(Qy,{className:"h-4 w-4"})}),n.jsx(T,{variant:"ghost",size:"sm",onClick:p,className:"text-white hover:bg-white/20",children:"Reset"}),n.jsx(T,{variant:"ghost",size:"sm",onClick:x,className:"text-white hover:bg-white/20",children:n.jsx(Ay,{className:"h-4 w-4"})}),n.jsx(T,{variant:"ghost",size:"sm",onClick:s,className:"text-white hover:bg-white/20",children:n.jsx(ln,{className:"h-4 w-4"})})]})]}),n.jsx("div",{className:"flex-1 overflow-hidden flex items-center justify-center cursor-move",onMouseDown:w,onMouseMove:N,onMouseUp:S,onMouseLeave:S,onWheel:P,children:n.jsx("img",{src:e,alt:t,className:"max-w-full max-h-full object-contain select-none",style:{transform:`translate(${a.x}px, ${a.y}px) scale(${r}) rotate(${f}deg)`,transition:l?"none":"transform 0.1s"},draggable:!1})})]})})})}function v1({url:e,className:t}){const s=d.useRef(null),[r,i]=d.useState(!1),[a,o]=d.useState(!1),[l,c]=d.useState(!0),u=()=>{s.current&&(r?s.current.pause():s.current.play(),i(!r))},m=()=>{s.current&&(s.current.muted=!a,o(!a))},f=()=>{s.current&&s.current.requestFullscreen&&s.current.requestFullscreen()};return n.jsxs("div",{className:Y("relative group",t),onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[n.jsx("video",{ref:s,src:e,className:"w-full h-full object-contain",onPlay:()=>i(!0),onPause:()=>i(!1),onEnded:()=>i(!1),muted:a,playsInline:!0,preload:"metadata"}),l&&n.jsx("div",{className:"absolute inset-0 bg-black/30 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(T,{variant:"ghost",size:"sm",onClick:u,className:"text-white hover:bg-white/20",children:r?n.jsx(qy,{className:"h-6 w-6"}):n.jsx(Ts,{className:"h-6 w-6"})}),n.jsx(T,{variant:"ghost",size:"sm",onClick:m,className:"text-white hover:bg-white/20",children:a?n.jsx(i0,{className:"h-4 w-4"}):n.jsx(r0,{className:"h-4 w-4"})}),n.jsx(T,{variant:"ghost",size:"sm",onClick:f,className:"text-white hover:bg-white/20",children:n.jsx(Ky,{className:"h-4 w-4"})})]})})]})}function fo({url:e,filename:t,className:s,size:r="md",showControls:i=!0}){const[a,o]=d.useState(!1),[l,c]=d.useState(!1),[u,m]=d.useState(!0);d.useEffect(()=>{c(!1),m(!0)},[e]);const f=t.toLowerCase().split(".").pop(),g=["png","jpg","jpeg","gif","webp"].includes(f||""),R=["mp4","webm","mov"].includes(f||""),k={sm:"h-16 w-24",md:"h-32 w-48",lg:"h-64 w-96"};return g?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:Y("relative rounded-md border border-border overflow-hidden bg-muted cursor-pointer group",k[r],s),onClick:()=>o(!0),children:[l?n.jsxs("div",{className:"flex items-center justify-center h-full flex-col gap-1",children:[n.jsx(ah,{className:"h-6 w-6 text-muted-foreground"}),n.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Failed to load"})]}):n.jsxs(n.Fragment,{children:[u&&n.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-muted z-10",children:n.jsx(_e,{className:"h-5 w-5 text-muted-foreground animate-spin"})}),n.jsx("img",{src:e,alt:t,className:Y("w-full h-full object-contain transition-opacity",u?"opacity-0":"opacity-100"),loading:"lazy",onLoad:()=>m(!1),onError:()=>{c(!0),m(!1)}})]}),i&&!u&&!l&&n.jsx("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/20 transition-colors flex items-center justify-center opacity-0 group-hover:opacity-100",children:n.jsx(fn,{className:"h-6 w-6 text-white"})})]}),a&&n.jsx(g1,{url:e,filename:t,onClose:()=>o(!1)})]}):R?r==="sm"?n.jsxs("div",{className:Y("relative rounded-md border border-border overflow-hidden bg-muted group cursor-pointer",k[r],s),children:[n.jsx("video",{src:e,className:"w-full h-full object-contain",preload:"metadata",muted:!0,playsInline:!0}),n.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/20",children:n.jsx("div",{className:"rounded-full bg-black/50 p-1",children:n.jsx(Ts,{className:"h-3 w-3 text-white fill-white"})})})]}):n.jsx("div",{className:Y("rounded-md border border-border overflow-hidden bg-muted",k[r],s),children:n.jsx(v1,{url:e,filename:t})}):n.jsx("div",{className:Y("rounded-md border border-border bg-muted flex items-center justify-center",k[r],s),children:n.jsx(ah,{className:"h-8 w-8 text-muted-foreground"})})}const y1=["goto","click","type","hover","wait","waitForSelector","screenshot","clip"];function j1({open:e,onOpenChange:t,step:s,onSave:r,assetUrl:i}){const[a,o]=d.useState({action:"click",selector:"",key:"",text:"",url:"",ms:"",duration:"",clip:null,selectorPadding:null,deviceScaleFactor:null,path:"",order:0});d.useEffect(()=>{o(s?{...a,...s}:{action:"click",selector:"",key:"",text:"",url:"",ms:"",duration:"",clip:null,selectorPadding:null,deviceScaleFactor:null,path:"",order:0})},[s,e]);const l=()=>{const c={action:a.action};if(a.selector&&(c.selector=a.selector),a.key&&(c.key=a.key),a.text&&(c.text=a.text),a.url&&(c.url=a.url),a.ms&&(c.ms=parseInt(a.ms,10)),a.duration&&(c.duration=parseInt(a.duration,10)),a.path&&(c.path=a.path),a.order!==void 0&&(c.order=a.order),a.clip)try{c.clip=typeof a.clip=="string"?JSON.parse(a.clip):a.clip}catch{}a.selectorPadding!==null&&a.selectorPadding!==""&&(c.selectorPadding=parseInt(a.selectorPadding,10)),a.deviceScaleFactor!==null&&a.deviceScaleFactor!==""&&(c.deviceScaleFactor=parseFloat(a.deviceScaleFactor)),r(c)};return n.jsx(st,{open:e,onOpenChange:t,children:n.jsxs(nt,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:s?"Edit Step":"Add Step"}),n.jsx(ot,{children:"Configure the step action and parameters"})]}),n.jsxs("div",{className:"space-y-4 py-4",children:[n.jsxs("div",{children:[n.jsx(q,{htmlFor:"action",children:"Action"}),n.jsx("select",{id:"action",value:a.action,onChange:c=>o({...a,action:c.target.value}),className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:y1.map(c=>n.jsx("option",{value:c,children:c},c))})]}),(a.action==="click"||a.action==="type"||a.action==="hover"||a.action==="waitForSelector"||a.action==="screenshot")&&n.jsxs("div",{children:[n.jsx(q,{htmlFor:"selector",children:"Selector"}),n.jsx(ve,{id:"selector",value:a.selector||"",onChange:c=>o({...a,selector:c.target.value}),placeholder:"#id, .class, [data-testid]"})]}),a.action==="type"&&n.jsxs("div",{children:[n.jsx(q,{htmlFor:"text",children:"Text"}),n.jsx(ve,{id:"text",value:a.text||"",onChange:c=>o({...a,text:c.target.value}),placeholder:"Text to type"})]}),a.action==="goto"&&n.jsxs("div",{children:[n.jsx(q,{htmlFor:"url",children:"URL"}),n.jsx(ve,{id:"url",value:a.url||"",onChange:c=>o({...a,url:c.target.value}),placeholder:"https://example.com"})]}),a.action==="wait"&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{children:[n.jsx(q,{htmlFor:"ms",children:"Milliseconds"}),n.jsx(ve,{id:"ms",type:"number",value:a.ms||"",onChange:c=>o({...a,ms:c.target.value}),placeholder:"1000"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"duration",children:"Duration (alternative)"}),n.jsx(ve,{id:"duration",type:"number",value:a.duration||"",onChange:c=>o({...a,duration:c.target.value}),placeholder:"1000"})]})]}),(a.action==="screenshot"||a.action==="clip")&&n.jsxs(n.Fragment,{children:[i&&n.jsxs("div",{children:[n.jsx(q,{children:"Asset Preview"}),n.jsx("div",{className:"mt-2",children:n.jsx(fo,{url:i,filename:a.path||`${a.key||"asset"}.png`,size:"md"})})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"key",children:"Key"}),n.jsx(ve,{id:"key",value:a.key||"",onChange:c=>o({...a,key:c.target.value}),placeholder:"capture-key"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"path",children:"Path"}),n.jsx(ve,{id:"path",value:a.path||"",onChange:c=>o({...a,path:c.target.value}),placeholder:"screenshot.png"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"clip",children:"Clip (JSON)"}),n.jsx(uo,{id:"clip",value:typeof a.clip=="object"?JSON.stringify(a.clip,null,2):a.clip||"",onChange:c=>o({...a,clip:c.target.value}),placeholder:'{"x": 0, "y": 0, "width": 800, "height": 600}',className:"font-mono text-sm"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"selectorPadding",children:"Selector Padding"}),n.jsx(ve,{id:"selectorPadding",type:"number",value:a.selectorPadding||"",onChange:c=>o({...a,selectorPadding:c.target.value}),placeholder:"0"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"deviceScaleFactor",children:"Device Scale Factor"}),n.jsx(ve,{id:"deviceScaleFactor",type:"number",step:"0.1",value:a.deviceScaleFactor||"",onChange:c=>o({...a,deviceScaleFactor:c.target.value}),placeholder:"1.0"})]})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"order",children:"Order"}),n.jsx(ve,{id:"order",type:"number",value:a.order||0,onChange:c=>o({...a,order:parseInt(c.target.value,10)||0})})]})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),n.jsxs(T,{onClick:l,children:[s?"Update":"Add"," Step"]})]})]})})}const w1=({open:e,children:t})=>(d.useEffect(()=>{if(e){const s=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=s}}},[e]),e?n.jsx(n.Fragment,{children:t}):null),N1={top:"inset-x-0 top-0 border-b animate-in slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t animate-in slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r animate-in slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l animate-in slide-in-from-right sm:max-w-lg"},Um=d.forwardRef(({side:e="right",className:t,children:s,onOpenChange:r},i)=>{const a=d.useCallback(l=>{l.stopPropagation(),r==null||r(!1)},[r]),o=d.useCallback(l=>{l.stopPropagation()},[]);return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-50 bg-black/80 animate-in fade-in-0",onClick:a}),n.jsxs("div",{ref:i,className:Y("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out duration-300",N1[e],t),onClick:o,children:[s,n.jsxs("button",{onClick:()=>r==null?void 0:r(!1),className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",children:[n.jsx(ln,{className:"h-4 w-4"}),n.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Um.displayName="SheetContent";const Bm=({className:e,...t})=>n.jsx("div",{className:Y("flex flex-col space-y-2 text-center sm:text-left",e),...t});Bm.displayName="SheetHeader";const Wm=({className:e,children:t,...s})=>n.jsx("h2",{className:Y("text-lg font-semibold text-foreground",e),...s,children:t});Wm.displayName="SheetTitle";const Km=({className:e,children:t,...s})=>n.jsx("p",{className:Y("text-sm text-muted-foreground",e),...s,children:t});Km.displayName="SheetDescription";function k1({open:e,onOpenChange:t,asset:s,scenarioKey:r,variationSlug:i,allAssets:a=[],onNavigate:o}){var V;const{toast:l}=Pt(),[c,u]=d.useState(null),[m,f]=d.useState(!1),[g,R]=d.useState(!1),k=d.useRef(a),C=d.useRef(o),j=d.useRef(t);d.useEffect(()=>{k.current=a,C.current=o,j.current=t});const p=(s==null?void 0:s.captureKey)||(s==null?void 0:s.filename.replace(/\.[^/.]+$/,"")),h=a.findIndex(y=>y.filename===(s==null?void 0:s.filename)),x=h>0,w=h<a.length-1&&h>=0,N=d.useRef({currentIndex:h,hasPrev:x,hasNext:w});d.useEffect(()=>{N.current={currentIndex:h,hasPrev:x,hasNext:w}}),d.useEffect(()=>{f(!1),R(!1)},[s==null?void 0:s.url]);const S=d.useRef(null);d.useEffect(()=>{!r||!e||S.current!==r&&(S.current=r,fetch(`/api/config/scenarios/${r}`).then(y=>y.json()).then(y=>{const _=y.scenario;if(_!=null&&_.steps){const F=_.steps.findIndex($=>{var E;return $.key===p||$.captureKey===p||((E=$.path)==null?void 0:E.replace(/\.[^/.]+$/,""))===p});u(F!==-1?{step:_.steps[F],index:F}:null)}}).catch(()=>{u(null)}))},[r,e]);const P=d.useCallback(()=>{const{currentIndex:y,hasPrev:_}=N.current,F=k.current,$=C.current;_&&$&&F[y-1]&&$(F[y-1])},[]),b=d.useCallback(()=>{const{currentIndex:y,hasNext:_}=N.current,F=k.current,$=C.current;_&&$&&F[y+1]&&$(F[y+1])},[]),O=d.useCallback(()=>{var y;(y=j.current)==null||y.call(j,!1)},[]);d.useEffect(()=>{if(!e)return;const y=_=>{if(_.key==="Escape"){_.preventDefault(),_.stopPropagation(),O();return}_.key==="ArrowLeft"?(_.preventDefault(),_.stopPropagation(),P()):_.key==="ArrowRight"&&(_.preventDefault(),_.stopPropagation(),b())};return window.addEventListener("keydown",y,!0),()=>{window.removeEventListener("keydown",y,!0)}},[e,P,b,O]);const D=y=>y<1024?`${y} B`:y<1024*1024?`${(y/1024).toFixed(1)} KB`:`${(y/(1024*1024)).toFixed(1)} MB`,v=()=>{s!=null&&s.path&&(navigator.clipboard.writeText(s.path),l({title:"Copied",description:"File path copied to clipboard",variant:"success"}))},L=()=>{if(s!=null&&s.url){const y=`${window.location.origin}${s.url}`;navigator.clipboard.writeText(y),l({title:"Copied",description:"Asset URL copied to clipboard",variant:"success"})}};return s?n.jsx(w1,{open:e,onOpenChange:t,children:n.jsxs(Um,{side:"right",className:"w-full sm:max-w-2xl overflow-y-auto",onOpenChange:t,children:[n.jsxs(Bm,{children:[n.jsxs(Wm,{className:"flex items-center gap-2",children:[n.jsx("span",{className:"truncate",children:s.filename}),s.diff&&n.jsxs(n.Fragment,{children:[s.diff.status==="new"&&n.jsx(ue,{variant:"success",className:"text-xs",children:"New"}),s.diff.status==="changed"&&n.jsx(ue,{variant:"warning",className:"text-xs",children:s.diff.score!==void 0?`${(s.diff.score*100).toFixed(1)}% diff`:"Changed"}),s.diff.status==="unchanged"&&n.jsx(ue,{variant:"approved",className:"text-xs",children:"Match"})]})]}),n.jsxs(Km,{children:[r," / ",i,a.length>1&&n.jsxs("span",{className:"ml-2",children:["(",h+1," of ",a.length,")"]})]})]}),a.length>1&&o&&n.jsxs("div",{className:"flex items-center justify-between my-4",children:[n.jsxs(T,{variant:"outline",size:"sm",onClick:P,disabled:!x,children:[n.jsx(_y,{className:"h-4 w-4 mr-1"}),"Previous"]}),n.jsx("span",{className:"text-sm text-muted-foreground",children:"Use ← → arrow keys to navigate"}),n.jsxs(T,{variant:"outline",size:"sm",onClick:b,disabled:!w,children:["Next",n.jsx(Ps,{className:"h-4 w-4 ml-1"})]})]}),n.jsxs("div",{className:"mt-4 space-y-4",children:[n.jsxs("div",{className:"relative rounded-lg border bg-muted overflow-hidden",children:[!m&&!g&&n.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:n.jsx("div",{className:"animate-pulse text-muted-foreground",children:"Loading..."})}),g?n.jsx("div",{className:"flex items-center justify-center h-64 text-muted-foreground",children:"Failed to load image"}):n.jsx("img",{src:s.url,alt:s.filename,className:Y("w-full h-auto max-h-[50vh] object-contain transition-opacity",m?"opacity-100":"opacity-0"),onLoad:()=>f(!0),onError:()=>R(!0)})]}),n.jsxs("div",{className:"flex gap-2 flex-wrap",children:[n.jsxs(T,{variant:"outline",size:"sm",onClick:v,children:[n.jsx(rn,{className:"h-3.5 w-3.5 mr-1.5"}),"Copy Path"]}),n.jsxs(T,{variant:"outline",size:"sm",onClick:L,children:[n.jsx(rn,{className:"h-3.5 w-3.5 mr-1.5"}),"Copy URL"]}),n.jsxs("a",{href:s.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground",children:[n.jsx(an,{className:"h-3.5 w-3.5"}),"Open Full Size"]})]}),n.jsxs("div",{className:"space-y-3 border-t pt-4",children:[n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"File Size"}),n.jsx("div",{className:"text-sm font-medium mt-0.5",children:D(s.size)})]}),n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Modified"}),n.jsx("div",{className:"text-sm font-medium mt-0.5",children:new Date(s.mtime).toLocaleString()})]}),p&&n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Capture Key"}),n.jsx("code",{className:"block text-sm font-mono bg-muted px-2 py-1 rounded mt-0.5",children:p})]}),n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"File Path"}),n.jsx("div",{className:"text-xs font-mono bg-muted px-2 py-1 rounded mt-0.5 break-all",children:s.relativePath})]}),c&&n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Linked Step"}),n.jsx("div",{className:"mt-1",children:n.jsxs("div",{className:"inline-flex items-center gap-1.5 text-sm",children:[n.jsx(Rn,{className:"h-3.5 w-3.5 text-primary"}),"Step #",c.index+1,": ",c.step.action]})}),c.step.selector&&n.jsx("div",{className:"text-xs font-mono bg-muted px-2 py-1 rounded mt-1",children:c.step.selector})]})]}),((V=s.diff)==null?void 0:V.diffUrl)&&n.jsxs("div",{className:"space-y-2 border-t pt-4",children:[n.jsxs(q,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n.jsx(Qp,{className:"h-3.5 w-3.5 text-yellow-500"}),"Visual Diff"]}),n.jsx("div",{className:"rounded-lg border overflow-hidden",children:n.jsx("img",{src:s.diff.diffUrl,alt:"Visual diff",className:"w-full h-auto"})})]})]})]})}):null}function b1({scenarioKey:e}){const[t,s]=d.useState([]),[r,i]=d.useState([]),[a,o]=d.useState(!0),[l,c]=d.useState(null),[u,m]=d.useState(null),[f,g]=d.useState(null),[R,k]=d.useState(!1),[C,j]=d.useState(new Set);d.useEffect(()=>{if(!e){o(!1);return}fetch(`/api/output/${e}/versions`).then(v=>v.json()).then(v=>{const L=v.versions||[];i(L),L.length>0?c(L[0].timestamp):o(!1)}).catch(v=>{console.error("Failed to load versions:",v),o(!1)})},[e]),d.useEffect(()=>{!e||!l||(o(!0),fetch(`/api/output/${e}/version/${l}`).then(v=>v.json()).then(v=>{s(v.assets||[]),m(v.diffManifest||null),o(!1)}).catch(v=>{console.error("Failed to load assets:",v),o(!1)}))},[e,l]);const p=d.useMemo(()=>t.filter(v=>!v.isSentinel),[t]),{images:h,videos:x,stepsByVariant:w}=d.useMemo(()=>{var y;const v=p.filter(_=>_.filename.endsWith(".png")||_.filename.endsWith(".jpg")||_.filename.endsWith(".jpeg")||_.filename.endsWith(".webp")),L=p.filter(_=>_.filename.endsWith(".mp4")||_.filename.endsWith(".webm")),V={};for(const _ of v){const F=((y=_.assetKey)==null?void 0:y.split("/"))||[];let $="default";F.length>1&&($=F.slice(0,-1).join("/"));const E=_.filename.match(/(step-\d+)/),A=E?E[1]:"other";V[$]||(V[$]={}),V[$][A]||(V[$][A]=[]),V[$][A].push(_)}return{images:v,videos:L,stepsByVariant:V}},[p]),N=Object.keys(w).sort(),S=p.length,P=d.useCallback(v=>{j(L=>{const V=new Set(L);return V.has(v)?V.delete(v):V.add(v),V})},[]),b=d.useCallback(v=>{g(v),k(!0)},[]),O=d.useCallback(v=>{g(v)},[]),D=d.useCallback(v=>{k(v),v||g(null)},[]);return a?n.jsx("div",{className:"text-muted-foreground text-center py-4 text-sm",children:"Loading assets..."}):S===0&&r.length===0?n.jsx("div",{className:"text-center text-muted-foreground py-6 text-sm",children:n.jsx("p",{children:"No assets found. Run the scenario to generate assets."})}):n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Uy,{className:"h-4 w-4 text-muted-foreground"}),n.jsxs($m,{value:l||"",onValueChange:c,children:[n.jsx(pd,{className:"h-8 w-[200px] text-xs",children:n.jsx(Vm,{placeholder:"Select version"})}),n.jsx(md,{children:r.map(v=>n.jsxs(xd,{value:v.timestamp,className:"text-xs",children:[v.label," ",v.isLatest&&"(Latest)"," · ",v.assetCount]},v.timestamp))})]})]}),n.jsxs("div",{className:"flex gap-1.5 flex-wrap",children:[n.jsxs(ue,{variant:"secondary",className:"text-xs h-6",children:[n.jsx(fn,{className:"h-3 w-3 mr-1"}),h.length]}),x.length>0&&n.jsxs(ue,{variant:"secondary",className:"text-xs h-6",children:[n.jsx(_n,{className:"h-3 w-3 mr-1"}),x.length]}),(u==null?void 0:u.summary)&&n.jsxs(n.Fragment,{children:[u.summary.new>0&&n.jsxs(ue,{variant:"info",className:"text-xs h-6",children:["+",u.summary.new]}),u.summary.changed>0&&n.jsxs(ue,{variant:"warning",className:"text-xs h-6",children:["⚠",u.summary.changed]}),u.summary.unchanged>0&&n.jsxs(ue,{variant:"approved",className:"text-xs h-6",children:["✓",u.summary.unchanged]})]})]})]}),l&&h.length>0&&n.jsx("div",{className:"space-y-2",children:N.map(v=>{const L=w[v],V=Object.keys(L).sort((F,$)=>{var z,W;const E=parseInt(((z=F.match(/\d+/))==null?void 0:z[0])||"0"),A=parseInt(((W=$.match(/\d+/))==null?void 0:W[0])||"0");return E-A}),y=C.has(v),_=Object.values(L).flat().length;return n.jsxs("div",{className:"border rounded-lg bg-card",children:[n.jsxs("button",{onClick:()=>P(v),className:"w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-accent/50 transition-colors",children:[y?n.jsx(Ps,{className:"h-4 w-4 text-muted-foreground"}):n.jsx(zs,{className:"h-4 w-4 text-muted-foreground"}),n.jsx(Xp,{className:"h-4 w-4 text-muted-foreground"}),n.jsx("span",{className:"font-medium text-sm",children:v==="default"?"Default":v.replace(/_/g," / ").replace(/-/g,": ")}),n.jsxs(ue,{variant:"outline",className:"text-xs ml-auto",children:[_," assets"]})]}),!y&&n.jsx("div",{className:"px-3 pb-3",children:n.jsx("div",{className:"flex gap-2 overflow-x-auto pb-2",children:V.map(F=>{const $=L[F];return n.jsxs("div",{className:"flex-shrink-0 space-y-1",children:[n.jsx("div",{className:"text-xs text-muted-foreground text-center",children:F==="other"?"Other":F.replace("-"," ")}),n.jsx("div",{className:"flex gap-1",children:$.map((E,A)=>{const z=E.diff,W=E.filename.includes("after");return n.jsxs("div",{onClick:()=>b(E),className:Y("relative cursor-pointer rounded overflow-hidden border transition-all hover:ring-2 hover:ring-primary",(z==null?void 0:z.status)==="changed"&&"border-yellow-500",(z==null?void 0:z.status)==="new"&&"border-blue-500",(z==null?void 0:z.status)==="unchanged"&&"border-green-500/50"),style:{width:100,height:64},children:[n.jsx("img",{src:E.url,alt:E.filename,className:"w-full h-full object-cover",loading:"lazy"}),z&&n.jsxs("div",{className:"absolute top-0.5 right-0.5",children:[z.status==="new"&&n.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-500"}),z.status==="changed"&&n.jsx("div",{className:"w-2 h-2 rounded-full bg-yellow-500"})]}),n.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/60 text-[9px] text-center text-white py-0.5",children:W?"after":"before"})]},A)})})]},F)})})})]},v)})}),x.length>0&&n.jsxs("div",{className:"border rounded-lg bg-card p-3",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[n.jsx(_n,{className:"h-4 w-4 text-muted-foreground"}),n.jsx("span",{className:"font-medium text-sm",children:"Videos"}),n.jsx(ue,{variant:"outline",className:"text-xs",children:x.length})]}),n.jsx("div",{className:"flex gap-2 overflow-x-auto",children:x.map((v,L)=>n.jsxs("div",{onClick:()=>b(v),className:"flex-shrink-0 cursor-pointer rounded overflow-hidden border hover:ring-2 hover:ring-primary transition-all",style:{width:160},children:[n.jsx(fo,{url:v.url,filename:v.filename,size:"sm",showControls:!1}),n.jsx("div",{className:"p-1.5 text-xs truncate text-muted-foreground",children:v.filename})]},L))})]}),l&&p.length===0&&n.jsx("div",{className:"text-center text-muted-foreground py-4 text-sm",children:"No assets for this version."}),n.jsx(k1,{open:R,onOpenChange:D,asset:f,scenarioKey:e,variationSlug:l||"default",allAssets:h,onNavigate:O})]})}const S1=d.memo(b1);function C1({stepCount:e,assetCount:t=0,hasAssets:s=!1,lastPublishAt:r}){const i=e>0,a=s,o=!!r;return n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsxs("div",{className:Y("flex items-center gap-1 px-2 py-1 rounded-full border",i?"bg-green-500/10 border-green-500/30 text-green-500":"bg-muted/50 border-border text-muted-foreground"),children:[i?n.jsx(vt,{className:"h-3 w-3"}):n.jsx(na,{className:"h-3 w-3"}),n.jsx(Rn,{className:"h-3 w-3"}),n.jsxs("span",{children:[e," steps"]})]}),n.jsx("span",{className:"text-muted-foreground",children:"→"}),n.jsxs("div",{className:Y("flex items-center gap-1 px-2 py-1 rounded-full border",a?"bg-green-500/10 border-green-500/30 text-green-500":"bg-muted/50 border-border text-muted-foreground"),children:[a?n.jsx(vt,{className:"h-3 w-3"}):n.jsx(na,{className:"h-3 w-3"}),n.jsx(fn,{className:"h-3 w-3"}),n.jsxs("span",{children:[t," assets"]})]}),n.jsx("span",{className:"text-muted-foreground",children:"→"}),n.jsxs("div",{className:Y("flex items-center gap-1 px-2 py-1 rounded-full border",o?"bg-green-500/10 border-green-500/30 text-green-500":"bg-muted/50 border-border text-muted-foreground"),children:[o?n.jsx(vt,{className:"h-3 w-3"}):n.jsx(na,{className:"h-3 w-3"}),n.jsx(on,{className:"h-3 w-3"}),n.jsx("span",{children:o?"Published":"Not published"})]})]})}const E1={locale:n.jsx(ur,{className:"h-4 w-4"}),role:n.jsx(xr,{className:"h-4 w-4"}),theme:n.jsx(Xc,{className:"h-4 w-4"})};function R1({variantsConfig:e,value:t,preset:s,onChange:r}){var x;const[i,a]=d.useState(s?"preset":"custom"),[o,l]=d.useState(!1),c=(e==null?void 0:e.dimensions)||{},u=(e==null?void 0:e.presets)||{},m=Object.keys(c),f=Object.keys(u),g=i==="preset"&&s&&((x=u[s])!=null&&x.values)?u[s].values:t||{},R=()=>{var N,S;const w=[];if(!g||typeof g!="object")return w;for(const[P,b]of Object.entries(g)){const O=(S=(N=c[P])==null?void 0:N.options)==null?void 0:S[b];if(O!=null&&O.inject)for(const D of O.inject)switch(D.method){case"localStorage":w.push({method:"localStorage",details:`${D.key} = "${D.value}"`});break;case"sessionStorage":w.push({method:"sessionStorage",details:`${D.key} = "${D.value}"`});break;case"cookie":w.push({method:"cookie",details:`${D.name} = "${D.value}"`});break;case"urlParam":w.push({method:"URL param",details:`?${D.param}=${D.value}`});break;case"browser":D.locale&&w.push({method:"browser",details:`locale: ${D.locale}`}),D.timezone&&w.push({method:"browser",details:`timezone: ${D.timezone}`});break;case"header":w.push({method:"HTTP header",details:`${D.header}: ${D.value}`});break;case"script":w.push({method:"script",details:"Custom JS"});break}}return w},k=(w,N)=>{const S={...t,[w]:N};a("custom"),r(S,void 0)},C=w=>{a("preset"),r({},w)},j=()=>{a("custom"),r({},void 0)},p=Object.keys(g).length>0||s,h=R();return m.length===0&&f.length===0?n.jsx(he,{className:"bg-gray-800/50 border-gray-700",children:n.jsxs(me,{className:"py-6 text-center text-gray-400",children:[n.jsx(Kr,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),n.jsx("p",{className:"text-sm",children:"No variant dimensions configured."}),n.jsx("p",{className:"text-xs mt-1",children:"Add dimensions in docsync.config.json under variants.dimensions"})]})}):n.jsxs("div",{className:"space-y-4",children:[f.length>0&&n.jsxs(hd,{value:i,onValueChange:w=>a(w),children:[n.jsxs(fd,{className:"grid w-full grid-cols-2",children:[n.jsxs(sr,{value:"preset",children:[n.jsx(a0,{className:"h-3 w-3 mr-1"}),"Preset"]}),n.jsxs(sr,{value:"custom",children:[n.jsx(Kr,{className:"h-3 w-3 mr-1"}),"Custom"]})]}),n.jsx(nr,{value:"preset",className:"mt-4",children:n.jsx("div",{className:"grid gap-2",children:f.map(w=>{const N=u[w];if(!N)return null;const S=s===w,P=N.values||{};return n.jsxs("button",{onClick:()=>C(w),className:`w-full text-left p-3 rounded-lg border transition-colors ${S?"bg-blue-500/20 border-blue-500":"bg-gray-800 border-gray-700 hover:border-gray-600"}`,children:[n.jsx("div",{className:"font-medium text-sm",children:N.name||w}),N.description&&n.jsx("div",{className:"text-xs text-gray-400 mt-1",children:N.description}),n.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:Object.entries(P).map(([b,O])=>{var D,v,L,V;return n.jsxs(ue,{variant:"secondary",className:"text-xs",children:[((D=c[b])==null?void 0:D.label)||b,":"," ",((V=(L=(v=c[b])==null?void 0:v.options)==null?void 0:L[O])==null?void 0:V.name)||O]},b)})})]},w)})})}),n.jsx(nr,{value:"custom",className:"mt-4",children:n.jsx(jh,{dimensions:c,values:t,onChange:k})})]}),f.length===0&&n.jsx(jh,{dimensions:c,values:t,onChange:k}),p&&n.jsxs(he,{className:"bg-gray-800/50 border-gray-700",children:[n.jsx(ke,{className:"py-3 px-4",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs(be,{className:"text-sm font-medium flex items-center gap-2",children:[n.jsx(Kr,{className:"h-4 w-4"}),"Active Variant"]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs(T,{variant:"ghost",size:"sm",onClick:()=>l(!o),className:"h-7 px-2",children:[o?n.jsx(Yc,{className:"h-3 w-3"}):n.jsx(zs,{className:"h-3 w-3"}),o?"Hide":"Show"," Details"]}),n.jsx(T,{variant:"ghost",size:"sm",onClick:j,className:"h-7 px-2 text-gray-400 hover:text-white",children:"Clear"})]})]})}),o&&h.length>0&&n.jsxs(me,{className:"py-3 px-4 border-t border-gray-700",children:[n.jsx("div",{className:"text-xs text-gray-400 mb-2",children:"Injections that will be applied:"}),n.jsx("div",{className:"space-y-1",children:h.map((w,N)=>n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx(ue,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:w.method}),n.jsx("code",{className:"text-gray-300",children:w.details})]},N))})]})]})]})}function jh({dimensions:e,values:t,onChange:s}){return!e||typeof e!="object"?null:n.jsx("div",{className:"space-y-4",children:Object.entries(e).map(([r,i])=>!(i!=null&&i.options)||typeof i.options!="object"?null:n.jsxs("div",{children:[n.jsxs(q,{className:"flex items-center gap-2 mb-2",children:[E1[r]||n.jsx(Kr,{className:"h-4 w-4"}),i.label]}),i.description&&n.jsx("p",{className:"text-xs text-gray-400 mb-2",children:i.description}),n.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[n.jsx("button",{onClick:()=>{({...t},s(r,""))},className:`p-2 rounded-md border text-sm transition-colors ${t[r]?"bg-gray-800 border-gray-700 hover:border-gray-600":"bg-gray-700 border-gray-500"}`,children:"Default"}),Object.entries(i.options).map(([a,o])=>n.jsx("button",{onClick:()=>s(r,a),className:`p-2 rounded-md border text-sm transition-colors ${t[r]===a?"bg-blue-500/20 border-blue-500":"bg-gray-800 border-gray-700 hover:border-gray-600"}`,children:(o==null?void 0:o.name)||a},a))]})]},r))})}function _1({scenarioKey:e,className:t,showActions:s=!0,onStatusChange:r}){const[i,a]=d.useState(null),[o,l]=d.useState(!1),c=d.useCallback(async()=>{var m,f;try{const k=((f=(m=(await(await fetch("/api/workspace")).json()).workspace)==null?void 0:m.scenarios)==null?void 0:f.includes(e))||!1;a(k)}catch{a(!1)}},[e]);d.useEffect(()=>{c()},[c]);const u=async()=>{l(!0);try{i?(await fetch(`/api/workspace/scenarios/${encodeURIComponent(e)}`,{method:"DELETE"}),a(!1),r==null||r(!1)):(await fetch("/api/workspace/scenarios",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:[e]})}),a(!0),r==null||r(!0))}catch{c()}finally{l(!1)}};return i===null?null:n.jsxs("div",{className:Y("flex items-center gap-1.5",t),children:[n.jsx(ue,{variant:i?"default":"secondary",className:Y("text-[10px] h-5 px-2 font-medium",i&&"bg-primary/90"),children:i?"In Workspace":"Not in Workspace"}),s&&n.jsx(T,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:u,disabled:o,title:i?"Remove from workspace":"Add to workspace",children:o?n.jsx(_e,{className:"h-3.5 w-3.5 animate-spin"}):i?n.jsx(Iy,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-destructive"}):n.jsx(Dy,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-primary"})})]})}function P1({open:e,onOpenChange:t,imageUrl:s,currentCrop:r,onSave:i,scenarioName:a}){const o=d.useRef(null),l=d.useRef(null),[c,u]=d.useState(!1),[m,f]=d.useState(!1),[g,R]=d.useState(null),[k,C]=d.useState({x:0,y:0}),[j,p]=d.useState(null),[h,x]=d.useState((r==null?void 0:r.region)||null),[w,N]=d.useState(!1),[S,P]=d.useState(!1);d.useEffect(()=>{e&&(N(!1),P(!1),p(null),x((r==null?void 0:r.region)||null))},[e,r]);const b=d.useCallback((_,F)=>{if(!l.current||!o.current)return{x:0,y:0};const $=l.current.getBoundingClientRect(),E=o.current.getBoundingClientRect(),A=l.current.naturalWidth/$.width,z=l.current.naturalHeight/$.height,W=_-($.left-E.left),J=F-($.top-E.top);return{x:Math.round(W*A),y:Math.round(J*z)}},[]);d.useEffect(()=>{if(w&&(r!=null&&r.region)&&l.current&&o.current){const _=l.current.getBoundingClientRect(),F=o.current.getBoundingClientRect(),$=_.width/l.current.naturalWidth,E=_.height/l.current.naturalHeight,A=_.left-F.left,z=_.top-F.top;p({left:A+r.region.x*$,top:z+r.region.y*E,width:r.region.width*$,height:r.region.height*E}),x(r.region)}},[w,r]);const O=_=>{if(!o.current)return;const F=_.target,$=o.current.getBoundingClientRect(),E=_.clientX-$.left,A=_.clientY-$.top;if(F.dataset.handle){f(!0),R(F.dataset.handle),C({x:_.clientX,y:_.clientY});return}u(!0),C({x:E,y:A}),p({left:E,top:A,width:0,height:0})},D=_=>{if(!o.current)return;const F=o.current.getBoundingClientRect();if(c){const $=_.clientX-F.left,E=_.clientY-F.top,A=$-k.x,z=E-k.y;p({left:A<0?$:k.x,top:z<0?E:k.y,width:Math.abs(A),height:Math.abs(z)})}else if(m&&j&&g){const $=_.clientX-k.x,E=_.clientY-k.y;let A={...j};g.includes("e")&&(A.width=Math.max(10,j.width+$)),g.includes("w")&&(A.left=j.left+$,A.width=Math.max(10,j.width-$)),g.includes("s")&&(A.height=Math.max(10,j.height+E)),g.includes("n")&&(A.top=j.top+E,A.height=Math.max(10,j.height-E)),p(A),C({x:_.clientX,y:_.clientY})}},v=()=>{if((c||m)&&j&&j.width>5&&j.height>5){const _=b(j.left,j.top),F=b(j.left+j.width,j.top+j.height);x({x:Math.max(0,_.x),y:Math.max(0,_.y),width:Math.max(1,F.x-_.x),height:Math.max(1,F.y-_.y)})}u(!1),f(!1),R(null)},L=()=>{p(null),x(null)},V=()=>{h&&h.width>0&&h.height>0?i({enabled:!0,region:h}):i(null),t(!1)},y=()=>{i(null),t(!1)};return n.jsx(st,{open:e,onOpenChange:t,children:n.jsxs(nt,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[n.jsxs(Xe,{children:[n.jsxs(Ze,{className:"flex items-center gap-2",children:[n.jsx(ra,{className:"h-5 w-5"}),"Configure Crop Region"]}),n.jsx(ot,{children:a?`Drag to select the crop region for "${a}". This will apply to all captures.`:"Drag to select the crop region. This will apply to all captures."})]}),n.jsxs("div",{className:"flex-1 min-h-0 py-4",children:[s?S?n.jsx("div",{className:"flex items-center justify-center h-64 bg-muted rounded-lg",children:n.jsxs("div",{className:"text-center text-muted-foreground",children:[n.jsx(Jt,{className:"h-8 w-8 mx-auto mb-2"}),n.jsx("p",{className:"text-sm",children:"Failed to load image."})]})}):n.jsxs("div",{ref:o,className:"relative mx-auto select-none overflow-auto max-h-[50vh] border rounded-lg bg-zinc-900",style:{cursor:c?"crosshair":"default"},onMouseDown:O,onMouseMove:D,onMouseUp:v,onMouseLeave:v,children:[n.jsx("img",{ref:l,src:s,alt:"Reference screenshot",className:"block max-w-full",style:{maxHeight:"50vh"},onLoad:()=>N(!0),onError:()=>P(!0),draggable:!1}),j&&j.width>0&&j.height>0&&n.jsxs("div",{className:"absolute border-2 border-green-500 bg-green-500/10 pointer-events-none",style:{left:j.left,top:j.top,width:j.width,height:j.height,boxShadow:"0 0 0 9999px rgba(0, 0, 0, 0.5)"},children:[n.jsx("div",{"data-handle":"nw",className:"absolute -left-1.5 -top-1.5 w-3 h-3 bg-green-500 border border-white cursor-nw-resize pointer-events-auto"}),n.jsx("div",{"data-handle":"ne",className:"absolute -right-1.5 -top-1.5 w-3 h-3 bg-green-500 border border-white cursor-ne-resize pointer-events-auto"}),n.jsx("div",{"data-handle":"sw",className:"absolute -left-1.5 -bottom-1.5 w-3 h-3 bg-green-500 border border-white cursor-sw-resize pointer-events-auto"}),n.jsx("div",{"data-handle":"se",className:"absolute -right-1.5 -bottom-1.5 w-3 h-3 bg-green-500 border border-white cursor-se-resize pointer-events-auto"}),n.jsx("div",{"data-handle":"n",className:"absolute left-1/2 -translate-x-1/2 -top-1.5 w-3 h-3 bg-green-500 border border-white cursor-n-resize pointer-events-auto"}),n.jsx("div",{"data-handle":"s",className:"absolute left-1/2 -translate-x-1/2 -bottom-1.5 w-3 h-3 bg-green-500 border border-white cursor-s-resize pointer-events-auto"}),n.jsx("div",{"data-handle":"w",className:"absolute -left-1.5 top-1/2 -translate-y-1/2 w-3 h-3 bg-green-500 border border-white cursor-w-resize pointer-events-auto"}),n.jsx("div",{"data-handle":"e",className:"absolute -right-1.5 top-1/2 -translate-y-1/2 w-3 h-3 bg-green-500 border border-white cursor-e-resize pointer-events-auto"})]})]}):n.jsx("div",{className:"flex items-center justify-center h-64 bg-muted rounded-lg",children:n.jsxs("div",{className:"text-center text-muted-foreground",children:[n.jsx(Jt,{className:"h-8 w-8 mx-auto mb-2"}),n.jsx("p",{className:"text-sm",children:"No reference image available."}),n.jsx("p",{className:"text-xs mt-1",children:"Run the scenario first to capture an image."})]})}),h&&n.jsxs("div",{className:"mt-3 p-2 bg-muted rounded text-xs font-mono text-center",children:["Crop: x=",h.x,", y=",h.y,", ",h.width,"×",h.height,"px"]})]}),n.jsxs(lt,{className:"flex-shrink-0 gap-2",children:[(r==null?void 0:r.enabled)&&n.jsxs(T,{variant:"outline",onClick:y,className:"mr-auto",children:[n.jsx(ln,{className:"h-4 w-4 mr-2"}),"Disable Crop"]}),n.jsxs(T,{variant:"outline",onClick:L,disabled:!j,children:[n.jsx(Wl,{className:"h-4 w-4 mr-2"}),"Reset"]}),n.jsx(T,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),n.jsxs(T,{onClick:V,disabled:!s||!h&&!(r!=null&&r.enabled),children:[n.jsx(ro,{className:"h-4 w-4 mr-2"}),"Save Crop"]})]})]})})}const wh="reshot-scenario-tab";function T1(){var mn,gd,vd,yd,jd,wd,Nd,kd,bd,Sd,Cd,Ed,Rd,_d,Pd,Td,Ad,Od,zd,Ld,Md,Id,Dd,Fd,$d;const{key:e}=Kp(),t=Os(),[s]=ky(),{trackJob:r}=ji(),[i,a]=d.useState(null),[o,l]=d.useState({}),[c,u]=d.useState(!0),[m,f]=d.useState(!1),g=e??"",R=()=>{const M=s.get("tab");if(M&&["details","steps","assets"].includes(M))return M;const Q=localStorage.getItem(wh);return Q&&["details","steps","assets"].includes(Q)?Q:"details"},[k,C]=d.useState(R),[j,p]=d.useState(null),[h,x]=d.useState(!1),[w,N]=d.useState(!1),[S,P]=d.useState(!1),[b,O]=d.useState(!1),[D,v]=d.useState("step-by-step-images"),[L,V]=d.useState({}),[y,_]=d.useState(!1),[F,$]=d.useState(null),[E,A]=d.useState(!0),[z,W]=d.useState(null),[J,G]=d.useState(null),[fe,ye]=d.useState(!1),[ge,Re]=d.useState(!1),[U,X]=d.useState({}),[Z,ce]=d.useState([]),[ie,ae]=d.useState(0),[Se,Ie]=d.useState(!1),[mt,Nt]=d.useState(!1),[Ft,Yt]=d.useState(null),[$t,kt]=d.useState(!1),[Tt,Vt]=d.useState(0),{toast:je}=Pt();d.useEffect(()=>{fetch("/api/settings").then(M=>M.json()).then(M=>{var Q;Yt(((Q=M.settings)==null?void 0:Q.isAuthenticated)||!1)}).catch(()=>Yt(!1)),fetch("/api/config").then(M=>M.json()).then(M=>{var Q,le;A(((le=(Q=M.config)==null?void 0:Q.diffing)==null?void 0:le.enabled)!==!1)}).catch(()=>{}),fetch("/api/privacy").then(M=>M.json()).then(M=>{var Q;return ye(M.enabled&&((Q=M.selectors)==null?void 0:Q.length)>0)}).catch(()=>{}),fetch("/api/style").then(M=>M.json()).then(M=>Re(M.enabled!==!1)).catch(()=>{})},[]);const B=d.useCallback(M=>{C(M),localStorage.setItem(wh,M)},[]);d.useEffect(()=>{const M=s.get("tab");M&&["details","steps","assets"].includes(M)&&C(M)},[]);const oe=d.useCallback(()=>{Ft===!1?Nt(!0):Ie(!0)},[Ft]),se=d.useCallback(()=>{Yt(!0),je({title:"Connected",description:"Successfully connected to Reshot platform. You can now publish.",variant:"success"}),setTimeout(()=>Ie(!0),300)},[je]),re=d.useCallback(()=>{e&&(u(!0),fetch(`/api/config/scenarios/${e}`).then(M=>M.json()).then(M=>{a(M.scenario),u(!1)}).catch(M=>{console.error("Failed to load scenario:",M),u(!1)}),fetch("/api/config").then(M=>M.json()).then(M=>{var ne;const Q=((ne=M.config)==null?void 0:ne.variants)||{};l(Q);const le=(Q==null?void 0:Q.dimensions)||{};Object.keys(le).length>0&&_(!0)}).catch(M=>{console.error("Failed to load config:",M)}))},[e]);d.useEffect(()=>{re()},[re]),d.useEffect(()=>{e&&fetch("/api/output").then(M=>M.json()).then(M=>{const le=(M.groups||[]).filter(Te=>Te.scenarioKey===e),ne={};let de=0;le.forEach(Te=>{fetch(`/api/output/${Te.scenarioKey}/${Te.variationSlug}`).then(cs=>cs.json()).then(cs=>{var et;(et=cs.assets)==null||et.forEach(xt=>{const zn=xt.filename.replace(/\.[^/.]+$/,"");ne[zn]||(ne[zn]=xt.url,de++)}),X({...ne}),ae(de)}).catch(()=>{})})}).catch(()=>{})},[e]);const[qe,De]=d.useState(0),At=d.useRef(new Set);d.useEffect(()=>{const M=()=>{fetch("/api/jobs?limit=10").then(le=>le.json()).then(le=>{const ne=le.jobs||[],de=ne.filter(et=>et.scenarioKey===e&&(et.status==="running"||et.status==="pending")),Te=new Set(de.map(et=>et.id)),cs=At.current;for(const et of cs)if(!Te.has(et)){const xt=ne.find(zn=>zn.id===et);if(xt&&(xt.type==="run"||xt.type==="capture")){Vt(zn=>zn+1);break}}At.current=Te,ce(de)}).catch(()=>{})};if(M(),qe===0&&Z.length===0)return;const Q=setInterval(M,2e3);return()=>clearInterval(Q)},[e,Z.length,qe]);const I=Fm(re),ee=async()=>{if(!(!i||!e)){f(!0);try{const M=await fetch(`/api/config/scenarios/${e}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(M.ok)je({title:"Success",description:"Scenario saved successfully",variant:"success"});else{const Q=await M.json();je({title:"Error",description:Q.error||"Failed to save scenario",variant:"destructive"})}}catch(M){console.error("Failed to save scenario:",M),je({title:"Error",description:"Failed to save scenario",variant:"destructive"})}finally{f(!1)}}},pe=async()=>{if(e)try{const M=await fetch(`/api/config/scenarios/${e}`,{method:"DELETE"});if(M.ok)je({title:"Success",description:"Scenario deleted successfully",variant:"success"}),t("/scenarios");else{const Q=await M.json();je({title:"Error",description:Q.error||"Failed to delete scenario",variant:"destructive"})}}catch(M){console.error("Failed to delete scenario:",M),je({title:"Error",description:"Failed to delete scenario",variant:"destructive"})}},Ce=()=>{p(null),x(!0)},Oe=M=>{p(M),x(!0)},Ge=async M=>{if(!(!e||!i||!i.steps))try{const Q=await fetch(`/api/config/scenarios/${e}/steps/${M}`,{method:"DELETE"});if(Q.ok){const le=i.steps.filter((ne,de)=>de!==M);a({...i,steps:le}),je({title:"Success",description:"Step deleted successfully",variant:"success"})}else{const le=await Q.json();je({title:"Error",description:le.error||"Failed to delete step",variant:"destructive"})}}catch(Q){console.error("Failed to delete step:",Q),je({title:"Error",description:"Failed to delete step",variant:"destructive"})}},ls=async M=>{if(!e||!i||!i.steps)return;const Q=i.steps[M];if(!Q)return;const le={...Q};try{const ne=await fetch(`/api/config/scenarios/${e}/steps`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(le)});if(ne.ok){const de=[...i.steps];de.splice(M+1,0,le),a({...i,steps:de}),je({title:"Success",description:"Step duplicated successfully",variant:"success"})}else{const de=await ne.json();je({title:"Error",description:de.error||"Failed to duplicate step",variant:"destructive"})}}catch(ne){console.error("Failed to duplicate step:",ne),je({title:"Error",description:"Failed to duplicate step",variant:"destructive"})}},pn=async(M,Q)=>{if(!e||!i||!i.steps)return;const le=Q==="up"?M-1:M+1;if(le<0||le>=i.steps.length)return;const ne=[...i.steps];[ne[M],ne[le]]=[ne[le],ne[M]],ne.forEach((de,Te)=>{de.order!==void 0&&(de.order=Te)});try{const de=await fetch(`/api/config/scenarios/${e}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({steps:ne})});if(de.ok)a({...i,steps:ne}),je({title:"Success",description:"Step reordered successfully",variant:"success"});else{const Te=await de.json();je({title:"Error",description:Te.error||"Failed to reorder step",variant:"destructive"})}}catch(de){console.error("Failed to reorder step:",de),je({title:"Error",description:"Failed to reorder step",variant:"destructive"})}},ki=async M=>{if(!e||!i)return;const Q=i.steps||[];try{if(j!==null){const le=await fetch(`/api/config/scenarios/${e}/steps/${j}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(M)});if(le.ok){const ne=[...Q];ne[j]=M,a({...i,steps:ne}),je({title:"Success",description:"Step updated successfully",variant:"success"}),x(!1)}else{const ne=await le.json();je({title:"Error",description:ne.error||"Failed to update step",variant:"destructive"})}}else{const le=await fetch(`/api/config/scenarios/${e}/steps`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(M)});if(le.ok){const ne=[...Q,M];a({...i,steps:ne}),je({title:"Success",description:"Step added successfully",variant:"success"}),x(!1)}else{const ne=await le.json();je({title:"Error",description:ne.error||"Failed to add step",variant:"destructive"})}}}catch(le){console.error("Failed to save step:",le),je({title:"Error",description:"Failed to save step",variant:"destructive"})}};return c?n.jsx("div",{className:"p-8",children:n.jsx("div",{className:"text-muted-foreground",children:"Loading scenario..."})}):i?n.jsxs("div",{"data-testid":"studio-scenario-detail","data-loaded":"true",className:"p-4 space-y-3",children:[n.jsxs("div",{className:"flex items-center justify-between gap-4",children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx(T,{variant:"ghost",size:"icon",onClick:()=>t("/scenarios"),className:"h-7 w-7 flex-shrink-0",children:n.jsx(Bl,{className:"h-4 w-4"})}),n.jsxs("div",{className:"min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("h1",{className:"text-lg font-semibold truncate",children:i.name}),e&&n.jsx(_1,{scenarioKey:e})]}),n.jsx("p",{className:"text-[10px] text-muted-foreground font-mono truncate",children:i.key})]})]}),n.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[n.jsx(T,{variant:"ghost",size:"icon",onClick:I,disabled:c,className:"h-7 w-7",children:n.jsx(_t,{className:`h-3.5 w-3.5 ${c?"animate-spin":""}`})}),n.jsxs(T,{size:"sm",className:"h-7 text-xs",onClick:()=>{V((i==null?void 0:i.variant)||{}),_(!1),O(!0)},children:[n.jsx(Ts,{className:"h-3 w-3 mr-1"}),"Run"]}),n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:oe,children:[n.jsx(on,{className:"h-3 w-3 mr-1"}),"Publish"]}),n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>t(`/recorder?scenario=${e}`),children:[n.jsx(_n,{className:"h-3 w-3 mr-1"}),"Record"]}),n.jsx(T,{variant:"ghost",size:"icon",onClick:ee,disabled:m,className:"h-7 w-7",children:n.jsx(Hr,{className:"h-3.5 w-3.5"})}),n.jsx(T,{variant:"ghost",size:"icon",onClick:()=>N(!0),className:"h-7 w-7 text-destructive hover:text-destructive",children:n.jsx(ps,{className:"h-3.5 w-3.5"})})]})]}),n.jsx("div",{className:"flex items-center gap-4 flex-wrap",children:n.jsx(C1,{scenarioKey:g,scenarioName:i.name,stepCount:((mn=i.steps)==null?void 0:mn.length)||0,assetCount:ie,hasAssets:ie>0})}),n.jsxs(hd,{value:k,onValueChange:B,children:[n.jsxs(fd,{className:"h-8",children:[n.jsx(sr,{value:"details",className:"text-xs h-7",children:"Details"}),n.jsxs(sr,{value:"steps",className:"text-xs h-7",children:["Steps (",((gd=i.steps)==null?void 0:gd.length)||0,")"]}),n.jsx(sr,{value:"assets",className:"text-xs h-7",children:"Assets"})]}),n.jsx(nr,{value:"details",className:"mt-3",children:n.jsxs("div",{className:"border rounded-lg bg-card p-4 space-y-4",children:[n.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[n.jsxs("div",{children:[n.jsx(q,{htmlFor:"scenario-name",className:"text-xs",children:"Name"}),n.jsx(ve,{id:"scenario-name",value:i.name,onChange:M=>a({...i,name:M.target.value}),className:"h-8 text-sm"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"scenario-key",className:"text-xs",children:"Key"}),n.jsx(ve,{id:"scenario-key",value:i.key,disabled:!0,className:"h-8 text-sm font-mono bg-muted"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"scenario-url",className:"text-xs",children:"URL"}),n.jsx(ve,{id:"scenario-url",value:i.url,onChange:M=>a({...i,url:M.target.value}),className:"h-8 text-sm"})]})]}),n.jsxs("details",{className:"group",children:[n.jsxs("summary",{className:"text-xs font-medium cursor-pointer hover:text-primary",children:["Capture Variants"," ",n.jsxs("span",{className:"text-muted-foreground",children:["(",Object.keys(i.variant||{}).length," configured)"]})]}),n.jsx("div",{className:"mt-2 pl-2 border-l-2 border-border",children:n.jsx(R1,{variantsConfig:o,value:i.variant||{},preset:i.variantPreset,onChange:(M,Q)=>{a({...i,variant:Object.keys(M).length>0?M:void 0,variantPreset:Q,locale:void 0,role:void 0})}})})]}),n.jsxs("details",{className:"group",children:[n.jsxs("summary",{className:"text-xs font-medium cursor-pointer hover:text-primary flex items-center gap-1",children:[n.jsx(ra,{className:"h-3 w-3"}),"Output Crop"," ",n.jsxs("span",{className:"text-muted-foreground",children:["(",(yd=(vd=i.output)==null?void 0:vd.crop)!=null&&yd.enabled?"enabled":"disabled",")"]})]}),n.jsxs("div",{className:"mt-2 pl-2 border-l-2 border-border space-y-2",children:[n.jsx("p",{className:"text-xs text-muted-foreground",children:"Crop all captures to focus on a specific region of the screen."}),((wd=(jd=i.output)==null?void 0:jd.crop)==null?void 0:wd.enabled)&&((kd=(Nd=i.output)==null?void 0:Nd.crop)==null?void 0:kd.region)&&n.jsxs("div",{className:"text-xs font-mono bg-muted px-2 py-1 rounded",children:["Region: ",i.output.crop.region.x,","," ",i.output.crop.region.y," →"," ",i.output.crop.region.width,"×",i.output.crop.region.height,"px"]}),n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>kt(!0),children:[n.jsx(ra,{className:"h-3 w-3 mr-1"}),(Sd=(bd=i.output)==null?void 0:bd.crop)!=null&&Sd.enabled?"Edit Crop Region":"Configure Crop"]}),((Ed=(Cd=i.output)==null?void 0:Cd.crop)==null?void 0:Ed.enabled)&&n.jsx(T,{variant:"ghost",size:"sm",className:"h-7 text-xs text-muted-foreground",onClick:()=>{a({...i,output:{...i.output,crop:void 0}})},children:"Disable Crop"})]})]}),n.jsxs("details",{className:"group",children:[n.jsxs("summary",{className:"text-xs font-medium cursor-pointer hover:text-primary flex items-center gap-1",children:[n.jsx(xr,{className:"h-3 w-3"}),"Privacy Override"," ",n.jsxs("span",{className:"text-muted-foreground",children:["(",i.privacy?"overridden":"inheriting global",")"]})]}),n.jsxs("div",{className:"mt-2 pl-2 border-l-2 border-border space-y-2",children:[n.jsxs("label",{className:"flex items-center gap-2 text-xs",children:[n.jsx("input",{type:"checkbox",checked:!!i.privacy,onChange:M=>{if(M.target.checked)a({...i,privacy:{enabled:!0,method:"redact",selectors:[]}});else{const{privacy:Q,...le}=i;a(le)}},className:"rounded h-3.5 w-3.5"}),"Override global privacy config for this scenario"]}),i.privacy&&n.jsxs("div",{className:"space-y-2 pt-1",children:[n.jsx("div",{className:"flex gap-1",children:["redact","blur","hide","remove"].map(M=>{var Q;return n.jsx(T,{variant:((Q=i.privacy)==null?void 0:Q.method)===M?"default":"outline",size:"sm",className:"h-6 text-[10px] flex-1 capitalize",onClick:()=>a({...i,privacy:{...i.privacy,method:M}}),children:M},M)})}),n.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Additional selectors for this scenario (additive with global)"})]})]})]}),n.jsxs("details",{className:"group",children:[n.jsxs("summary",{className:"text-xs font-medium cursor-pointer hover:text-primary flex items-center gap-1",children:[n.jsx(ao,{className:"h-3 w-3"}),"Style Override"," ",n.jsxs("span",{className:"text-muted-foreground",children:["(",i.style?"overridden":"inheriting global",")"]})]}),n.jsxs("div",{className:"mt-2 pl-2 border-l-2 border-border space-y-2",children:[n.jsxs("label",{className:"flex items-center gap-2 text-xs",children:[n.jsx("input",{type:"checkbox",checked:!!i.style,onChange:M=>{if(M.target.checked)a({...i,style:{frame:"none",shadow:"medium",padding:40}});else{const{style:Q,...le}=i;a(le)}},className:"rounded h-3.5 w-3.5"}),"Override global style config for this scenario"]}),i.style&&n.jsxs("div",{className:"space-y-2 pt-1",children:[n.jsxs("div",{className:"space-y-1",children:[n.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Frame"}),n.jsx("div",{className:"flex gap-1",children:["none","macos","windows"].map(M=>{var Q;return n.jsx(T,{variant:((Q=i.style)==null?void 0:Q.frame)===M?"default":"outline",size:"sm",className:"h-6 text-[10px] flex-1 capitalize",onClick:()=>a({...i,style:{...i.style,frame:M}}),children:M==="none"?"None":M==="macos"?"macOS":"Windows"},M)})})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Shadow"}),n.jsx("div",{className:"flex gap-1",children:["none","small","medium","large"].map(M=>{var Q;return n.jsx(T,{variant:((Q=i.style)==null?void 0:Q.shadow)===M?"default":"outline",size:"sm",className:"h-6 text-[10px] flex-1 capitalize",onClick:()=>a({...i,style:{...i.style,shadow:M}}),children:M},M)})})]})]})]})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[n.jsxs("div",{children:[n.jsx(q,{htmlFor:"scenario-description",className:"text-xs",children:"Description"}),n.jsx(uo,{id:"scenario-description",value:((Rd=i._local)==null?void 0:Rd.description)||"",onChange:M=>a({...i,_local:{...i._local||{},description:M.target.value}}),placeholder:"Optional description",rows:2,className:"text-sm"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"scenario-tags",className:"text-xs",children:"Tags"}),n.jsx(ve,{id:"scenario-tags",value:((Pd=(_d=i._local)==null?void 0:_d.tags)==null?void 0:Pd.join(", "))||"",onChange:M=>{const Q=M.target.value.split(",").map(le=>le.trim()).filter(Boolean);a({...i,_local:{...i._local||{},tags:Q}})},placeholder:"tag1, tag2",className:"h-8 text-sm"}),((Td=i._local)==null?void 0:Td.tags)&&i._local.tags.length>0&&n.jsx("div",{className:"flex gap-1 flex-wrap mt-1",children:i._local.tags.map(M=>n.jsx(ue,{variant:"secondary",className:"text-[10px] h-5",children:M},M))})]})]})]})}),n.jsxs(nr,{value:"steps",className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center justify-between py-1",children:[n.jsxs("span",{className:"text-xs text-muted-foreground",children:[((Ad=i.steps)==null?void 0:Ad.length)||0," steps"]}),n.jsxs(T,{onClick:Ce,size:"sm",className:"h-7 text-xs",children:[n.jsx(as,{className:"h-3 w-3 mr-1"}),"Add"]})]}),n.jsxs("div",{className:"border rounded-md divide-y",children:[(Od=i.steps)==null?void 0:Od.map((M,Q)=>{var Te;const le=M.key||M.captureKey,ne=le?U[le]:null,de=M.action==="screenshot"||M.action==="clip";return n.jsxs("div",{className:"flex items-center gap-2 p-2 hover:bg-accent/30 group",children:[n.jsxs("span",{className:"text-[10px] text-muted-foreground w-4 shrink-0",children:["#",Q+1]}),de&&ne?n.jsx("div",{className:"w-12 h-8 shrink-0 rounded overflow-hidden bg-muted cursor-pointer",onClick:()=>t(`/assets/${e}/default/${le}`),children:n.jsx("img",{src:ne,alt:"",className:"w-full h-full object-cover"})}):n.jsx("div",{className:"w-12 h-8 shrink-0 rounded bg-muted/50 flex items-center justify-center",children:n.jsx("span",{className:"text-[8px] text-muted-foreground",children:"—"})}),n.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[n.jsx(ue,{variant:"outline",className:"text-[10px] h-5 shrink-0",children:M.action}),M.key&&n.jsx(ue,{variant:"secondary",className:"text-[10px] h-5 shrink-0",children:M.key}),M.selector&&n.jsx("code",{className:"text-[10px] text-muted-foreground truncate font-mono",children:M.selector}),M.url&&n.jsx("span",{className:"text-[10px] text-muted-foreground truncate",children:M.url}),M.text&&n.jsxs("span",{className:"text-[10px] text-muted-foreground truncate italic",children:['"',M.text,'"']}),de&&!ne&&n.jsx("span",{className:"text-[10px] text-muted-foreground italic",children:"not generated"})]}),n.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[n.jsx(T,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>pn(Q,"up"),disabled:Q===0,title:"Move up",children:n.jsx(Yc,{className:"h-3 w-3"})}),n.jsx(T,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>pn(Q,"down"),disabled:Q===(((Te=i.steps)==null?void 0:Te.length)||0)-1,title:"Move down",children:n.jsx(zs,{className:"h-3 w-3"})}),n.jsx(T,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>Oe(Q),title:"Edit",children:n.jsx(Gy,{className:"h-3 w-3"})}),n.jsx(T,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>ls(Q),title:"Duplicate",children:n.jsx(rn,{className:"h-3 w-3"})}),n.jsx(T,{variant:"ghost",size:"icon",className:"h-6 w-6 text-destructive hover:text-destructive",onClick:()=>Ge(Q),title:"Delete",children:n.jsx(ln,{className:"h-3 w-3"})})]})]},Q)}),(!i.steps||i.steps.length===0)&&n.jsxs("div",{className:"text-center text-muted-foreground py-6",children:[n.jsx("p",{className:"text-sm",children:"No steps yet."}),n.jsxs(T,{onClick:Ce,variant:"outline",size:"sm",className:"mt-2 h-7 text-xs",children:[n.jsx(as,{className:"h-3 w-3 mr-1"}),"Add First Step"]})]})]}),n.jsx(j1,{open:h,onOpenChange:x,step:j!==null?i.steps[j]:null,onSave:ki,assetUrl:j!==null&&i.steps[j]?U[i.steps[j].key||i.steps[j].captureKey||""]:void 0}),n.jsx(st,{open:w,onOpenChange:N,children:n.jsxs(nt,{children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:"Delete Scenario"}),n.jsx(ot,{children:"Are you sure you want to delete this scenario? This action cannot be undone."})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>N(!1),children:"Cancel"}),n.jsx(T,{variant:"destructive",onClick:()=>{N(!1),pe()},children:"Delete"})]})]})})]}),n.jsx(nr,{value:"assets",className:"space-y-4",forceMount:!0,children:n.jsx(S1,{scenarioKey:g},`assets-${Tt}`)})]}),n.jsx(ho,{open:Se,onOpenChange:Ie,scenarioKeys:e?[e]:[],onConfirm:async M=>{var Q;try{const le=M.reduce((Te,cs)=>Te+cs.assets.length,0),ne=await fetch("/api/jobs/publish",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:e?[e]:[],selectedGroups:M})}),de=await ne.json();if(ne.status===401||de.authRequired){Ie(!1),je({title:"Authentication Required",description:de.error||"Please reconnect to publish.",variant:"destructive"}),Nt(!0);return}ne.ok&&de.ok?(je({title:"Job Created",description:`Publishing ${le} asset(s). Monitor progress in the panel below.`}),Ie(!1),(Q=de.job)!=null&&Q.id&&r(de.job.id,e||void 0),De(Te=>Te+1),setTimeout(()=>De(0),1e4)):je({title:"Error",description:de.error||"Failed to create publish job",variant:"destructive"})}catch{je({title:"Error",description:"Failed to connect to server",variant:"destructive"})}}}),n.jsx(wi,{open:mt,onOpenChange:Nt,onAuthenticated:se}),n.jsx(st,{open:b,onOpenChange:O,children:n.jsxs(nt,{className:"max-w-lg",children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:"Run Scenario"}),n.jsx(ot,{children:"Choose output format and variant options"})]}),n.jsxs("div",{className:"py-4 space-y-5",children:[n.jsxs("div",{className:"space-y-3",children:[n.jsx(q,{className:"text-sm font-medium",children:"Output Format"}),n.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[n.jsx("button",{type:"button",onClick:()=>v("step-by-step-images"),className:`p-3 rounded-lg border-2 text-left transition-all ${D==="step-by-step-images"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(fn,{className:"h-4 w-4"}),n.jsx("span",{className:"font-medium text-sm",children:"Screenshots"})]})}),n.jsx("button",{type:"button",onClick:()=>v("summary-video"),className:`p-3 rounded-lg border-2 text-left transition-all ${D==="summary-video"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(io,{className:"h-4 w-4"}),n.jsx("span",{className:"font-medium text-sm",children:"Video"})]})})]})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(q,{className:"text-sm font-medium",children:"Visual Diffing"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Compare against approved baselines"})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[F===null&&E&&n.jsx("span",{className:"text-xs text-muted-foreground",children:"(config default: on)"}),F===null&&!E&&n.jsx("span",{className:"text-xs text-muted-foreground",children:"(config default: off)"}),n.jsx("input",{type:"checkbox",checked:F===null?E:F,onChange:M=>$(M.target.checked),className:"rounded h-4 w-4"})]})]}),(F===!0||F===null&&E)&&n.jsx("div",{className:"text-xs text-amber-600 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 rounded-md p-2",children:"Diff results will appear in the job log after completion"})]}),n.jsx("div",{className:"space-y-2",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(q,{className:"text-sm font-medium",children:"Privacy Masking"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Hide sensitive elements during capture"})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[z===null&&n.jsxs("span",{className:"text-xs text-muted-foreground",children:["(config default: ",fe?"on":"off",")"]}),n.jsx("input",{type:"checkbox",checked:z===null?fe:!z,onChange:M=>W(M.target.checked?null:!0),className:"rounded h-4 w-4"})]})]})}),n.jsx("div",{className:"space-y-2",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(q,{className:"text-sm font-medium",children:"Style Processing"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Apply frames, shadows, and backgrounds"})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[J===null&&n.jsxs("span",{className:"text-xs text-muted-foreground",children:["(config default: ",ge?"on":"off",")"]}),n.jsx("input",{type:"checkbox",checked:J===null?ge:!J,onChange:M=>G(M.target.checked?null:!0),className:"rounded h-4 w-4"})]})]})}),n.jsx("div",{className:"space-y-2",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(q,{className:"text-sm font-medium",children:"Output Crop"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:(Ld=(zd=i.output)==null?void 0:zd.crop)!=null&&Ld.enabled?`Cropping to ${(Md=i.output.crop.region)==null?void 0:Md.width}×${(Id=i.output.crop.region)==null?void 0:Id.height}px`:"No crop configured"})]}),n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{O(!1),kt(!0)},children:[n.jsx(ra,{className:"h-3 w-3 mr-1"}),(Fd=(Dd=i.output)==null?void 0:Dd.crop)!=null&&Fd.enabled?"Edit":"Configure"]})]})}),(()=>{const M=(o==null?void 0:o.dimensions)||{},Q=Object.keys(M);if(Q.length===0)return n.jsx("div",{className:"text-sm text-muted-foreground bg-muted/50 rounded-md p-3",children:n.jsx("p",{children:"No variants configured. Will run with default settings."})});let le=1;return Q.forEach(ne=>{var Te;const de=Object.keys(((Te=M[ne])==null?void 0:Te.options)||{});le*=de.length||1}),n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"border rounded-lg overflow-hidden",children:n.jsxs("div",{className:"flex",children:[n.jsx("button",{type:"button",onClick:()=>_(!0),className:`flex-1 py-3 px-4 text-sm font-medium transition-all ${y?"bg-primary text-primary-foreground":"bg-muted/30 hover:bg-muted/50"}`,children:n.jsxs("div",{className:"flex flex-col items-center gap-1",children:[n.jsx("span",{className:"text-lg",children:"🎯"}),n.jsxs("span",{children:["All ",le," Variants"]}),n.jsx("span",{className:`text-xs ${y?"text-primary-foreground/70":"text-muted-foreground"}`,children:Q.map(ne=>{var de;return((de=M[ne])==null?void 0:de.label)||ne}).join(" × ")})]})}),n.jsx("button",{type:"button",onClick:()=>_(!1),className:`flex-1 py-3 px-4 text-sm font-medium transition-all border-l ${y?"bg-muted/30 hover:bg-muted/50":"bg-primary text-primary-foreground"}`,children:n.jsxs("div",{className:"flex flex-col items-center gap-1",children:[n.jsx("span",{className:"text-lg",children:"☝️"}),n.jsx("span",{children:"Single Variant"}),n.jsx("span",{className:`text-xs ${y?"text-muted-foreground":"text-primary-foreground/70"}`,children:"Choose specific options"})]})})]})}),!y&&n.jsx("div",{className:"space-y-3 p-3 bg-muted/30 rounded-lg",children:Q.map(ne=>{const de=M[ne],Te=(de==null?void 0:de.options)||{},cs=Object.keys(Te);return n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-sm font-medium",children:(de==null?void 0:de.label)||ne}),n.jsxs($m,{value:L[ne]||cs[0]||"",onValueChange:et=>{V(xt=>({...xt,[ne]:et}))},children:[n.jsx(pd,{className:"w-full",children:n.jsx(Vm,{placeholder:`Select ${(de==null?void 0:de.label)||ne}`})}),n.jsx(md,{children:cs.map(et=>{const xt=Te[et];return n.jsx(xd,{value:et,children:(xt==null?void 0:xt.name)||(xt==null?void 0:xt.label)||et},et)})})]})]},ne)})}),y&&n.jsxs("div",{className:"text-sm bg-green-500/10 dark:bg-green-500/20 border border-green-500/30 rounded-md p-3",children:[n.jsxs("p",{className:"font-medium text-green-700 dark:text-green-400 mb-2",children:["✓ Will capture ",le," variant",le>1?"s":"",":"]}),n.jsx("div",{className:"space-y-1 text-xs text-muted-foreground",children:Q.map(ne=>{var Te;const de=Object.keys(((Te=M[ne])==null?void 0:Te.options)||{});return n.jsxs("div",{children:[n.jsx("span",{className:"font-mono",children:ne}),":"," ",de.join(", ")]},ne)})})]})]})})()]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>O(!1),children:"Cancel"}),n.jsxs(T,{onClick:async()=>{const M=(o==null?void 0:o.dimensions)||{},Q=Object.keys(M);if(y&&Q.length>0){const le=await fetch("/api/jobs/run-all-variations",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKey:e,dimensions:Q,format:D})});if(le.ok){const ne=await le.json();for(const de of ne.jobs)r(de.id,e);O(!1),De(de=>de+1),setTimeout(()=>De(0),1e4)}else{const ne=await le.json();je({title:"Error",description:ne.error||"Failed to start jobs",variant:"destructive"})}}else{const le=await fetch("/api/jobs/run",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:[e],format:D,variant:Object.keys(L).length>0?L:void 0,diff:F,noPrivacy:z===!0?!0:void 0,noStyle:J===!0?!0:void 0})});if(le.ok){const ne=await le.json();r(ne.job.id,e),O(!1),De(de=>de+1),setTimeout(()=>De(0),1e4)}else je({title:"Error",description:"Failed to start job",variant:"destructive"})}},children:[n.jsx(Ts,{className:"h-4 w-4 mr-2"}),y?"Run All Variations":"Run"]})]})]})}),n.jsx(st,{open:S,onOpenChange:P,children:n.jsxs(nt,{children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:"Record Visual"}),n.jsx(ot,{children:"Start a recording session for this scenario. The recorder will open in your terminal."})]}),n.jsx("div",{className:"py-4",children:n.jsxs("div",{className:"text-sm text-muted-foreground space-y-2",children:[n.jsx("p",{children:"This will start a recording job that:"}),n.jsxs("ul",{className:"list-disc list-inside space-y-1 ml-2",children:[n.jsx("li",{children:"Opens Chrome with remote debugging"}),n.jsx("li",{children:"Connects to the active browser session"}),n.jsx("li",{children:"Allows you to capture steps using keyboard shortcuts"})]}),n.jsx("p",{className:"mt-4 font-medium",children:"Keyboard shortcuts:"}),n.jsxs("ul",{className:"list-disc list-inside space-y-1 ml-2",children:[n.jsxs("li",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded text-xs",children:"C"})," ","- Capture screenshot/clip"]}),n.jsxs("li",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded text-xs",children:"Q"})," ","- Quit and save"]})]})]})}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>P(!1),children:"Cancel"}),n.jsx(T,{onClick:async()=>{try{const M=await fetch("/api/jobs/record",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:i==null?void 0:i.name,scenarioKey:e})}),Q=await M.json();M.ok?(je({title:"Success",description:"Recording job started. Check Jobs page and your terminal.",variant:"success"}),P(!1),De(le=>le+1),setTimeout(()=>De(0),1e4)):je({title:"Error",description:Q.error||"Failed to start recording",variant:"destructive"})}catch{je({title:"Error",description:"Failed to start recording",variant:"destructive"})}},children:"Start Recording"})]})]})}),n.jsx(P1,{open:$t,onOpenChange:kt,imageUrl:Object.values(U)[0]||null,currentCrop:($d=i.output)==null?void 0:$d.crop,scenarioName:i.name,onSave:M=>{a({...i,output:{...i.output,crop:M||void 0}})}})]}):n.jsx("div",{className:"p-8",children:n.jsx(he,{children:n.jsx(ke,{children:n.jsx(be,{children:"Scenario Not Found"})})})})}function Nh(e){const t=e.split("-");return t.length>=2?t[0]:"other"}function A1(e){return e==="other"?"Other":e.split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function O1(){const e=Os(),{toast:t}=Pt(),[,s]=d.useState([]),[r,i]=d.useState(!0),[a,o]=d.useState({}),[l,c]=d.useState(new Set),[u,m]=d.useState(!1),[f,g]=d.useState(new Set),[R,k]=d.useState(!1),[C,j]=d.useState(!1),[p,h]=d.useState(!1),{trackJob:x}=ji(),w=U=>{g(X=>{const Z=new Set(X);return Z.has(U)?Z.delete(U):Z.add(U),Z})},N=U=>{const X=U.every(Z=>f.has(Z));g(Z=>{const ce=new Set(Z);return X?U.forEach(ie=>ce.delete(ie)):U.forEach(ie=>ce.add(ie)),ce})},S=()=>{const U=Object.keys(a);g(new Set(U))},P=()=>{g(new Set)},b=async()=>{if(f.size!==0)try{const U=await fetch("/api/assets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:Array.from(f)})}),X=await U.json();U.ok?(t({title:"Success",description:`Deleted assets for ${X.deletedScenarios||f.size} scenario(s)`,variant:"success"}),k(!1),P(),D()):t({title:"Error",description:X.error||"Failed to delete selected assets",variant:"destructive"})}catch(U){console.error("Failed to delete selected assets:",U),t({title:"Error",description:"Failed to delete selected assets",variant:"destructive"})}},O=async()=>{try{const U=await fetch("/api/assets",{method:"DELETE"}),X=await U.json();U.ok?(t({title:"Success",description:`Deleted ${X.deleted} asset file(s)`,variant:"success"}),m(!1),D()):t({title:"Error",description:X.error||"Failed to delete assets",variant:"destructive"})}catch(U){console.error("Failed to delete assets:",U),t({title:"Error",description:"Failed to delete assets",variant:"destructive"})}},D=async()=>{i(!0);try{const Z=(await(await fetch("/api/output")).json()).groups||[];s(Z);const ce=[...new Set(Z.map(ae=>ae.scenarioKey))],ie={};if(await Promise.all(ce.map(async ae=>{try{const mt=(await(await fetch(`/api/output/${ae}/versions`)).json()).versions||[];mt.length===0&&mt.push({timestamp:"default",label:"Default",date:new Date().toISOString(),assetCount:0,isLatest:!0});const Nt=mt[0].timestamp,Yt=mt[0].variants||[],$t=Yt.length>0?Yt[0].name:null;let kt=[];try{const Tt=$t?`/api/output/${ae}/version/${Nt}/variant/${$t}`:`/api/output/${ae}/version/${Nt}`;kt=((await(await fetch(Tt)).json()).assets||[]).filter(B=>!B.isSentinel)}catch{const Tt=Z.find(Vt=>Vt.scenarioKey===ae);kt=(Tt==null?void 0:Tt.assets)||[]}ie[ae]={scenarioKey:ae,versions:mt,selectedVersion:Nt,selectedVariant:$t,assets:kt,availableVariants:Yt}}catch(Se){console.error(`Failed to fetch versions for ${ae}:`,Se)}})),o(ie),l.size===0){const ae=new Set;Object.values(ie).forEach(Se=>ae.add(Nh(Se.scenarioKey))),c(ae)}i(!1)}catch(U){console.error("Failed to load assets:",U),i(!1)}};d.useEffect(()=>{D()},[]);const v=async(U,X)=>{o(Se=>({...Se,[U]:{...Se[U],selectedVersion:X}}));const Z=a[U],ce=Z==null?void 0:Z.versions.find(Se=>Se.timestamp===X),ie=(ce==null?void 0:ce.variants)||[],ae=ie.length>0?ie[0].name:null;try{const Se=ae?`/api/output/${U}/version/${X}/variant/${ae}`:`/api/output/${U}/version/${X}`,Nt=((await(await fetch(Se)).json()).assets||[]).filter(Ft=>!Ft.isSentinel);o(Ft=>({...Ft,[U]:{...Ft[U],selectedVersion:X,selectedVariant:ae,availableVariants:ie,assets:Nt}}))}catch(Se){console.error(`Failed to fetch assets for ${U}/${X}:`,Se)}},L=async(U,X)=>{const Z=a[U];if(Z){o(ce=>({...ce,[U]:{...ce[U],selectedVariant:X}}));try{const ce=`/api/output/${U}/version/${Z.selectedVersion}/variant/${X}`,Se=((await(await fetch(ce)).json()).assets||[]).filter(Ie=>!Ie.isSentinel);o(Ie=>({...Ie,[U]:{...Ie[U],selectedVariant:X,assets:Se}}))}catch(ce){console.error(`Failed to fetch assets for ${U}/${Z.selectedVersion}/${X}:`,ce)}}},V=U=>U<1024?`${U} B`:U<1024*1024?`${(U/1024).toFixed(1)} KB`:`${(U/(1024*1024)).toFixed(1)} MB`,y=U=>{if(U==="latest"||U==="default")return U;const X=U.match(/(\d{4})-(\d{2})-(\d{2})_(\d{2})-(\d{2})-(\d{2})/);return X?new Date(parseInt(X[1]),parseInt(X[2])-1,parseInt(X[3]),parseInt(X[4]),parseInt(X[5]),parseInt(X[6])).toLocaleString():U},_=U=>U.endsWith(".mp4")?n.jsx(io,{className:"h-4 w-4"}):n.jsx(fn,{className:"h-4 w-4"}),F=Object.values(a),[$,E]=d.useState(""),[A,z]=d.useState("name"),[W,J]=d.useState(!0),G=d.useMemo(()=>{let U=[...F];if($){const X=$.toLowerCase();U=U.filter(Z=>Z.scenarioKey.toLowerCase().includes(X)||Z.assets.some(ce=>ce.captureKey.toLowerCase().includes(X)))}return U.sort((X,Z)=>{let ce=0;switch(A){case"name":ce=X.scenarioKey.localeCompare(Z.scenarioKey);break;case"assets":ce=X.assets.length-Z.assets.length;break;case"versions":ce=X.versions.length-Z.versions.length;break}return W?ce:-ce}),U},[F,$,A,W]),fe=d.useMemo(()=>{const U={};for(const Z of G){const ce=Nh(Z.scenarioKey);U[ce]||(U[ce]=[]),U[ce].push(Z)}return Object.entries(U).sort(([Z],[ce])=>Z==="other"?1:ce==="other"?-1:Z.localeCompare(ce)).map(([Z,ce])=>({key:Z,name:A1(Z),scenarios:ce,totalAssets:ce.reduce((ie,ae)=>ie+ae.assets.length,0),isExpanded:l.has(Z)}))},[G,l]),ye=U=>{c(X=>{const Z=new Set(X);return Z.has(U)?Z.delete(U):Z.add(U),Z})},ge=U=>{A===U?J(!W):(z(U),J(!0))},Re=F.reduce((U,X)=>U+X.assets.length,0);return n.jsxs("div",{"data-testid":"studio-assets","data-loaded":"true",className:"p-5 space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 pb-3",children:[n.jsxs("div",{children:[n.jsx("h1",{className:"text-xl font-bold tracking-tight",children:"Assets"}),n.jsxs("p",{className:"text-xs text-muted-foreground mt-1 font-normal",children:[F.length," scenario(s) · ",Re," asset(s)"]})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx(T,{variant:"outline",size:"icon",onClick:D,disabled:r,title:"Refresh",children:n.jsx(_t,{className:`h-4 w-4 ${r?"animate-spin":""}`})}),f.size>0?n.jsxs(n.Fragment,{children:[n.jsxs(T,{variant:"default",size:"sm",onClick:()=>j(!0),children:[n.jsx(on,{className:"h-3.5 w-3.5 mr-1.5"}),"Publish Selected (",f.size,")"]}),n.jsxs(T,{variant:"outline",size:"sm",onClick:()=>k(!0),className:"text-destructive hover:text-destructive",children:[n.jsx(ps,{className:"h-3.5 w-3.5 mr-1.5"}),"Delete Selected (",f.size,")"]})]}):n.jsxs(T,{variant:"outline",size:"sm",onClick:()=>m(!0),title:"Delete all assets",className:"text-destructive hover:text-destructive",children:[n.jsx(ps,{className:"h-3.5 w-3.5 mr-1.5"}),"Delete All"]})]})]}),F.length>0&&n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[n.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-md",children:[n.jsx(Zc,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),n.jsx(ve,{placeholder:"Search assets...",value:$,onChange:U=>E(U.target.value),className:"pl-9 h-9"})]}),n.jsxs("div",{className:"flex items-center gap-1 text-xs",children:[n.jsx(Gc,{className:"h-3.5 w-3.5 text-muted-foreground mr-1"}),n.jsxs(T,{variant:A==="name"?"secondary":"ghost",size:"sm",className:"h-8 text-xs",onClick:()=>ge("name"),children:["Name ",A==="name"&&(W?"↑":"↓")]}),n.jsxs(T,{variant:A==="assets"?"secondary":"ghost",size:"sm",className:"h-8 text-xs",onClick:()=>ge("assets"),children:["Assets ",A==="assets"&&(W?"↑":"↓")]}),n.jsxs(T,{variant:A==="versions"?"secondary":"ghost",size:"sm",className:"h-8 text-xs",onClick:()=>ge("versions"),children:["Versions ",A==="versions"&&(W?"↑":"↓")]})]}),$&&n.jsxs("span",{className:"text-xs text-muted-foreground",children:[G.length," of ",F.length," scenarios"]})]}),n.jsx("div",{className:"flex items-center gap-3 text-xs",children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(T,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:f.size===F.length?P:S,children:f.size===F.length?n.jsxs(n.Fragment,{children:[n.jsx(Qc,{className:"h-3 w-3 mr-1"}),"Deselect All"]}):n.jsxs(n.Fragment,{children:[n.jsx(ed,{className:"h-3 w-3 mr-1"}),"Select All"]})}),f.size>0&&n.jsxs("span",{className:"text-muted-foreground",children:[f.size," selected"]})]})})]}),r?n.jsx("div",{className:"text-muted-foreground",children:"Loading assets..."}):F.length===0?n.jsx(he,{children:n.jsxs(ke,{children:[n.jsx(be,{children:"No Assets"}),n.jsx(at,{children:"Run a scenario to generate assets"})]})}):G.length===0?n.jsx(he,{children:n.jsxs(me,{className:"py-8 text-center",children:[n.jsxs("p",{className:"text-muted-foreground",children:['No assets match "',$,'"']}),n.jsx(T,{variant:"link",onClick:()=>E(""),children:"Clear search"})]})}):n.jsx("div",{className:"space-y-3",children:fe.map(U=>{const X=U.scenarios.map(ie=>ie.scenarioKey),Z=X.every(ie=>f.has(ie)),ce=X.some(ie=>f.has(ie));return n.jsxs(he,{className:"overflow-hidden",children:[n.jsxs("div",{className:"flex items-center gap-2 p-4 border-b border-border/50",children:[n.jsx(ns,{checked:Z,indeterminate:ce&&!Z,onCheckedChange:()=>N(X),onClick:ie=>ie.stopPropagation(),className:"h-4 w-4"}),n.jsxs("button",{onClick:()=>ye(U.key),className:"flex-1 flex items-center gap-3 text-left hover:bg-accent/50 transition-colors rounded-md px-2 py-1 -my-1",children:[U.isExpanded?n.jsx(zs,{className:"h-4 w-4 text-muted-foreground"}):n.jsx(Ps,{className:"h-4 w-4 text-muted-foreground"}),U.isExpanded?n.jsx(fi,{className:"h-5 w-5 text-primary"}):n.jsx(Xp,{className:"h-5 w-5 text-muted-foreground"}),n.jsxs("div",{className:"flex-1",children:[n.jsx("span",{className:"font-medium",children:U.name}),n.jsxs("span",{className:"text-xs text-muted-foreground ml-2",children:[U.scenarios.length," scenario(s) ·"," ",U.totalAssets," asset(s)"]})]})]})]}),U.isExpanded&&n.jsx("div",{className:"divide-y divide-border/50",children:U.scenarios.map(ie=>n.jsxs("div",{className:"p-4",children:[n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(ns,{checked:f.has(ie.scenarioKey),onCheckedChange:()=>w(ie.scenarioKey),className:"h-4 w-4"}),n.jsx("span",{className:"font-medium text-sm",children:ie.scenarioKey.includes("/")?ie.scenarioKey.split("/").slice(1).join("/"):ie.scenarioKey}),n.jsxs(ue,{variant:"outline",className:"text-[10px]",children:[ie.assets.length," asset(s)"]}),(()=>{var Se,Ie;const ae=ie.versions.find(mt=>mt.timestamp===ie.selectedVersion);return n.jsxs(n.Fragment,{children:[((Se=ae==null?void 0:ae.privacy)==null?void 0:Se.enabled)&&n.jsxs(ue,{variant:"secondary",className:"text-[10px] gap-0.5",children:[n.jsx(xr,{className:"h-2.5 w-2.5"}),ae.privacy.method||"privacy"]}),((Ie=ae==null?void 0:ae.style)==null?void 0:Ie.enabled)&&n.jsxs(ue,{variant:"secondary",className:"text-[10px] gap-0.5",children:[n.jsx(ao,{className:"h-2.5 w-2.5"}),ae.style.frame!=="none"?ae.style.frame:"styled"]})]})})()]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(hi,{className:"h-3.5 w-3.5 text-muted-foreground"}),n.jsx("select",{value:ie.selectedVersion,onChange:ae=>v(ie.scenarioKey,ae.target.value),className:"h-7 px-2 text-xs rounded-md border border-gray-600 bg-gray-800 text-white focus:outline-none focus:ring-2 focus:ring-blue-500",children:ie.versions.map(ae=>n.jsx("option",{value:ae.timestamp,children:ae.timestamp==="latest"?"Latest":ae.timestamp==="default"?"Default":y(ae.timestamp)},ae.timestamp))}),ie.availableVariants.length>0&&ie.selectedVariant&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-muted-foreground text-xs",children:"/"}),n.jsx("select",{value:ie.selectedVariant,onChange:ae=>L(ie.scenarioKey,ae.target.value),className:"h-7 px-2 text-xs rounded-md border border-gray-600 bg-gray-800 text-white focus:outline-none focus:ring-2 focus:ring-blue-500 capitalize",children:ie.availableVariants.map(ae=>n.jsxs("option",{value:ae.name,children:[ae.name," (",ae.assetCount,")"]},ae.name))})]})]})]}),ie.assets.length===0?n.jsx("p",{className:"text-sm text-muted-foreground text-center py-3",children:"No assets in this version"}):n.jsx("div",{className:"grid gap-3 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4",children:ie.assets.map(ae=>n.jsxs("div",{className:"border rounded-md p-2.5 space-y-1.5 cursor-pointer hover:border-primary transition-colors group",onClick:()=>e(`/assets/${ie.scenarioKey}/${ie.selectedVersion}/${ae.captureKey}`),children:[n.jsx(fo,{url:ae.url,filename:ae.filename,size:"sm",showControls:!1}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[_(ae.filename),n.jsx("span",{className:"font-medium text-xs truncate",children:ae.captureKey})]}),n.jsx(ue,{variant:"outline",className:"text-[9px]",children:V(ae.size)})]})]},ae.captureKey))})]},ie.scenarioKey))})]},U.key)})}),n.jsx(st,{open:R,onOpenChange:k,children:n.jsxs(nt,{children:[n.jsxs(Xe,{children:[n.jsx(Ze,{className:"text-destructive",children:"Delete Selected Assets?"}),n.jsxs(ot,{children:["This will permanently delete all assets for"," ",f.size," selected scenario(s). This action cannot be undone."]})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>k(!1),children:"Cancel"}),n.jsxs(T,{variant:"destructive",onClick:b,children:[n.jsx(ps,{className:"h-4 w-4 mr-2"}),"Delete Selected"]})]})]})}),n.jsx(st,{open:u,onOpenChange:m,children:n.jsxs(nt,{children:[n.jsxs(Xe,{children:[n.jsx(Ze,{className:"text-destructive",children:"Delete All Assets?"}),n.jsxs(ot,{children:["This will permanently delete all ",Re," captured asset files from the output folder. This action cannot be undone."]})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>m(!1),children:"Cancel"}),n.jsxs(T,{variant:"destructive",onClick:O,children:[n.jsx(ps,{className:"h-4 w-4 mr-2"}),"Delete All"]})]})]})}),n.jsx(ho,{open:C,onOpenChange:j,scenarioKeys:Array.from(f),onConfirm:async U=>{var X;try{const Z=U.reduce((ae,Se)=>ae+Se.assets.length,0),ce=await fetch("/api/jobs/publish",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:Array.from(f),selectedGroups:U})}),ie=await ce.json();if(ce.status===401||ie.authRequired){j(!1),t({title:"Authentication Required",description:ie.error||"Please reconnect to publish.",variant:"destructive"}),h(!0);return}ce.ok&&ie.ok?(t({title:"Job Created",description:`Publishing ${Z} asset(s). Monitor progress in the panel below.`}),j(!1),(X=ie.job)!=null&&X.id&&x(ie.job.id)):t({title:"Error",description:ie.error||"Failed to create publish job",variant:"destructive"})}catch{t({title:"Error",description:"Failed to connect to server",variant:"destructive"})}}}),n.jsx(wi,{open:p,onOpenChange:h,onAuthenticated:()=>{t({title:"Connected",description:"Successfully connected. You can now publish.",variant:"success"}),D()}})]})}function z1(){const{toast:e}=Pt(),t=d.useRef(!0),[s,r]=d.useState(null),[i,a]=d.useState(!0),[o,l]=d.useState(!1),[c,u]=d.useState(!1),[m,f]=d.useState(null),[g,R]=d.useState(!1),[k,C]=d.useState(!1);d.useEffect(()=>()=>{t.current=!1},[]);const j=d.useCallback(async(P=!0)=>{try{P&&a(!0);const b=await fetch("/api/settings");if(!b.ok)throw new Error("Failed to fetch settings");const D=(await b.json()).settings||{};if(!t.current)return;r({isAuthenticated:D.isAuthenticated||!1,projectId:D.projectId||null,projectName:D.projectName||null,workspaceName:D.workspaceName||null,platformUrl:D.platformUrl||null,user:D.user||null,linkedAt:D.linkedAt||null,apiKeyValid:!!D.isAuthenticated,apiKeyWarning:void 0})}catch(b){console.error("Failed to load status:",b),t.current&&e({title:"Error",description:"Failed to load connection status",variant:"destructive"})}finally{t.current&&a(!1)}},[e]);d.useEffect(()=>{j()},[j]);const p=async()=>{l(!0);try{const P=await fetch("/api/auth/refresh",{method:"POST"}),b=await P.json();if(!t.current)return;if(P.status===401||b.authRequired){r(O=>O?{...O,apiKeyValid:!1,apiKeyWarning:b.error||"Please re-authenticate"}:null),e({title:"Authentication Required",description:b.error||"Please re-link to platform",variant:"destructive"});return}b.ok?(r(O=>O?{...O,projectId:b.projectId||O.projectId,projectName:b.projectName||O.projectName,workspaceName:b.workspaceName||O.workspaceName,user:b.user||O.user,linkedAt:b.linkedAt||O.linkedAt,apiKeyValid:!0,apiKeyWarning:void 0}:null),e({title:"Refreshed",description:"Connection info updated from platform",variant:"success"})):b.warning&&(r(O=>O?{...O,apiKeyValid:"unknown",apiKeyWarning:b.warning}:null),e({title:"Warning",description:b.warning}))}catch(P){console.error("Refresh failed:",P),e({title:"Refresh Failed",description:"Could not refresh connection info",variant:"destructive"})}finally{t.current&&l(!1)}},h=async()=>{u(!0);try{const P=await fetch("/api/auth/verify"),b=await P.json();if(!t.current)return;P.status===401?(r(O=>O?{...O,apiKeyValid:!1,apiKeyWarning:b.error||"API key is invalid or expired"}:null),e({title:"Connection Invalid",description:b.error||"Please re-authenticate",variant:"destructive"})):b.valid==="unknown"?(r(O=>O?{...O,apiKeyValid:"unknown",apiKeyWarning:b.warning}:null),e({title:"Status Unknown",description:b.warning||"Could not verify - platform may be unreachable"})):(r(O=>O?{...O,projectId:b.projectId||O.projectId,projectName:b.projectName||O.projectName,workspaceName:b.workspaceName||O.workspaceName,user:b.user||O.user,apiKeyValid:!0,apiKeyWarning:void 0}:null),e({title:"Connection Verified",description:"Your connection is active",variant:"success"}))}catch(P){console.error("Verification failed:",P),e({title:"Verification Failed",description:"Could not verify connection",variant:"destructive"})}finally{t.current&&u(!1)}},x=async()=>{C(!0),f(null);try{const P=await fetch("/api/auth/start",{method:"POST"}),b=await P.json();if(!P.ok||!b.ok)throw new Error(b.error||"Failed to start authentication");if(!t.current)return;const O={authUrl:b.authUrl,authToken:b.authToken,expiresAt:b.expiresAt};f(O);try{await fetch("/api/auth/open-browser",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({authUrl:b.authUrl})}),e({title:"Browser Opened",description:"Complete the sign-in in your browser"})}catch{e({title:"Browser Error",description:"Copy the URL below and paste in your browser"})}R(!0)}catch(P){console.error("Auth start failed:",P),e({title:"Error",description:P instanceof Error?P.message:"Failed to start authentication",variant:"destructive"}),C(!1)}};d.useEffect(()=>{if(!g||!m)return;let P=0;const b=150,O=setInterval(async()=>{if(P++,P>b){R(!1),f(null),C(!1),e({title:"Authentication Timeout",description:"Please try again",variant:"destructive"});return}try{const v=await(await fetch(`/api/auth/status?token=${encodeURIComponent(m.authToken)}`)).json();if(!t.current)return;v.status==="completed"?(clearInterval(O),R(!1),f(null),C(!1),await j(!1),e({title:"Connected!",description:`Successfully linked to ${v.projectName||"project"}`,variant:"success"})):(v.status==="expired"||v.status==="invalid")&&(clearInterval(O),R(!1),f(null),C(!1),e({title:"Authentication Failed",description:v.error||"Session expired. Please try again.",variant:"destructive"}))}catch(D){console.error("Polling error:",D)}},2e3);return()=>{clearInterval(O)}},[g,m,j,e]);const w=()=>{R(!1),f(null),C(!1)},N=async()=>{if(m!=null&&m.authUrl)try{await navigator.clipboard.writeText(m.authUrl),e({title:"Copied",description:"Auth URL copied to clipboard"})}catch{e({title:"Error",description:"Failed to copy",variant:"destructive"})}},S=P=>{if(!P)return"Never";try{return new Date(P).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return"Invalid date"}};return i?n.jsx("div",{className:"flex items-center justify-center h-full",children:n.jsxs("div",{className:"text-center",children:[n.jsx(_e,{className:"h-8 w-8 animate-spin text-muted-foreground mx-auto mb-3"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading connection status..."})]})}):n.jsxs("div",{"data-testid":"studio-connection","data-loaded":"true",className:"p-6 max-w-3xl mx-auto space-y-6",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Platform Connection"}),n.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Manage your connection to the Reshot platform"})]}),n.jsx(T,{variant:"outline",size:"icon",onClick:()=>j(!1),disabled:i,title:"Refresh",children:n.jsx(_t,{className:Y("h-4 w-4",i&&"animate-spin")})})]}),n.jsxs(he,{children:[n.jsx(ke,{className:"pb-3",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(be,{className:"text-base font-medium",children:"Connection Status"}),n.jsx(ue,{variant:s!=null&&s.isAuthenticated?"default":"secondary",className:Y((s==null?void 0:s.isAuthenticated)&&(s==null?void 0:s.apiKeyValid)===!0&&"bg-green-600",(s==null?void 0:s.isAuthenticated)&&(s==null?void 0:s.apiKeyValid)===!1&&"bg-red-600",(s==null?void 0:s.isAuthenticated)&&(s==null?void 0:s.apiKeyValid)==="unknown"&&"bg-yellow-600"),children:s!=null&&s.isAuthenticated?(s==null?void 0:s.apiKeyValid)===!0?n.jsxs(n.Fragment,{children:[n.jsx(vt,{className:"h-3 w-3 mr-1"}),"Connected"]}):(s==null?void 0:s.apiKeyValid)===!1?n.jsxs(n.Fragment,{children:[n.jsx(Jt,{className:"h-3 w-3 mr-1"}),"Invalid"]}):n.jsxs(n.Fragment,{children:[n.jsx(Jt,{className:"h-3 w-3 mr-1"}),"Unverified"]}):n.jsxs(n.Fragment,{children:[n.jsx(s0,{className:"h-3 w-3 mr-1"}),"Not Connected"]})})]})}),n.jsx(me,{className:"space-y-4",children:s!=null&&s.isAuthenticated?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[n.jsxs("div",{className:"space-y-1",children:[n.jsxs(q,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n.jsx(Cy,{className:"h-3 w-3"}),"Project"]}),n.jsx("p",{className:"text-sm font-medium",children:s.projectName||"Unknown Project"}),s.projectId&&n.jsx("p",{className:"text-xs text-muted-foreground font-mono truncate",children:s.projectId})]}),s.workspaceName&&n.jsxs("div",{className:"space-y-1",children:[n.jsxs(q,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n.jsx(ur,{className:"h-3 w-3"}),"Workspace"]}),n.jsx("p",{className:"text-sm font-medium",children:s.workspaceName})]}),s.user&&n.jsxs("div",{className:"space-y-1",children:[n.jsxs(q,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n.jsx(n0,{className:"h-3 w-3"}),"Linked User"]}),n.jsx("p",{className:"text-sm font-medium",children:s.user.fullName||s.user.email||"Unknown"}),s.user.fullName&&s.user.email&&n.jsx("p",{className:"text-xs text-muted-foreground",children:s.user.email})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs(q,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n.jsx(Ey,{className:"h-3 w-3"}),"Linked On"]}),n.jsx("p",{className:"text-sm",children:S(s.linkedAt)})]})]}),s.apiKeyWarning&&n.jsx("div",{className:"p-3 rounded-md bg-yellow-500/10 border border-yellow-500/30",children:n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(Jt,{className:"h-4 w-4 text-yellow-500 mt-0.5 shrink-0"}),n.jsxs("div",{children:[n.jsx("p",{className:"text-sm font-medium text-yellow-600",children:"Connection Issue"}),n.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:s.apiKeyWarning})]})]})}),n.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-2",children:[n.jsxs(T,{variant:"outline",size:"sm",onClick:h,disabled:c,children:[c?n.jsx(_e,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):n.jsx(xr,{className:"h-3.5 w-3.5 mr-1.5"}),"Verify"]}),n.jsxs(T,{variant:"outline",size:"sm",onClick:p,disabled:o,children:[o?n.jsx(_e,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):n.jsx(_t,{className:"h-3.5 w-3.5 mr-1.5"}),"Sync Info"]}),n.jsxs(T,{variant:"outline",size:"sm",onClick:x,disabled:k,children:[n.jsx(Ma,{className:"h-3.5 w-3.5 mr-1.5"}),"Re-link"]}),s.platformUrl&&n.jsxs(T,{variant:"ghost",size:"sm",onClick:()=>window.open(s.platformUrl,"_blank"),children:[n.jsx(an,{className:"h-3.5 w-3.5 mr-1.5"}),"Platform"]})]})]}):n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-sm text-muted-foreground",children:"Connect to the Reshot platform to publish your captured visuals and sync with your team."}),n.jsxs(T,{onClick:x,disabled:k,children:[k?n.jsx(_e,{className:"h-4 w-4 mr-2 animate-spin"}):n.jsx(Ma,{className:"h-4 w-4 mr-2"}),"Connect to Platform"]})]})})]}),m&&n.jsxs(he,{className:"border-primary/50 bg-primary/5",children:[n.jsxs(ke,{className:"pb-3",children:[n.jsxs(be,{className:"text-base font-medium flex items-center gap-2",children:[n.jsx(_e,{className:"h-4 w-4 animate-spin text-primary"}),"Waiting for Authentication"]}),n.jsx(at,{children:"Complete the sign-in process in your browser window"})]}),n.jsxs(me,{className:"space-y-4",children:[n.jsxs("div",{className:"p-3 rounded-md bg-background border",children:[n.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"If the browser didn't open, copy this URL and paste it in your browser:"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(ve,{value:m.authUrl,readOnly:!0,className:"text-xs font-mono bg-muted"}),n.jsx(T,{variant:"outline",size:"icon",onClick:N,children:n.jsx(rn,{className:"h-4 w-4"})})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(T,{variant:"outline",size:"sm",onClick:w,children:"Cancel"}),n.jsxs(T,{variant:"outline",size:"sm",onClick:()=>window.open(m.authUrl,"_blank"),children:[n.jsx(an,{className:"h-3.5 w-3.5 mr-1.5"}),"Open Browser"]})]})]})]}),n.jsxs(he,{className:"bg-muted/30",children:[n.jsx(ke,{className:"pb-2",children:n.jsx(be,{className:"text-sm font-medium",children:"How It Works"})}),n.jsxs(me,{className:"text-sm text-muted-foreground space-y-2",children:[n.jsxs("p",{children:[n.jsx("strong",{children:"1. Connect:"})," Link this CLI to your Reshot platform project"]}),n.jsxs("p",{children:[n.jsx("strong",{children:"2. Capture:"})," Record and capture visuals locally in your workspace"]}),n.jsxs("p",{children:[n.jsx("strong",{children:"3. Commit:"})," Bundle scenarios and publish to the platform"]}),n.jsx("p",{className:"pt-2 text-xs",children:"Your captured assets remain local until you publish them. Re-link anytime to switch projects."})]})]})]})}function L1(){const{toast:e}=Pt(),[t,s]=d.useState([]),[r,i]=d.useState(!0),[a,o]=d.useState(null),[l,c]=d.useState("all"),u=d.useRef(null),[m,f]=d.useState(!0),g=d.useRef(0),[R,k]=d.useState(!1),[,C]=d.useState(null);d.useEffect(()=>{fetch("/api/settings").then(v=>v.json()).then(v=>{var L;C(((L=v.settings)==null?void 0:L.isAuthenticated)||!1)}).catch(()=>C(!1))},[]),d.useEffect(()=>{if(a&&u.current&&m){const v=a.logs.length;v>g.current&&(u.current.scrollTop=u.current.scrollHeight),g.current=v}},[a==null?void 0:a.logs,m]);const j=d.useCallback(()=>{if(u.current){const{scrollTop:v,scrollHeight:L,clientHeight:V}=u.current,y=L-v-V<50;f(y)}},[]),p=d.useCallback(async()=>{i(!0);try{const L=await(await fetch("/api/jobs?limit=50")).json();if(s(L.jobs||[]),i(!1),a){const V=L.jobs.find(y=>y.id===a.id);V&&o(V)}}catch(v){console.error("Failed to load jobs:",v),i(!1)}},[a==null?void 0:a.id]);d.useEffect(()=>{if(p(),!t.some(V=>V.status==="running"||V.status==="pending"))return;const L=setInterval(p,2e3);return()=>clearInterval(L)},[p,t.some(v=>v.status==="running")]);const h=d.useCallback(v=>{o(v),g.current=0,f(!0),fetch(`/api/jobs/${v.id}`).then(L=>L.json()).then(L=>{L.job&&o(L.job)}).catch(()=>{})},[]),x=d.useCallback(()=>{C(!0),e({title:"Connected",description:"Successfully connected to Reshot platform. You can now publish.",variant:"success"})},[e]),w=async(v,L)=>{L&&L.stopPropagation();try{const V=await fetch(`/api/jobs/${v}/cancel`,{method:"POST",headers:{"Content-Type":"application/json"}}),y=await V.json();V.ok?(e({title:"Success",description:"Job cancelled",variant:"success"}),p()):e({title:"Error",description:y.error||"Failed to cancel job",variant:"destructive"})}catch{e({title:"Error",description:"Failed to cancel job",variant:"destructive"})}},N=async(v,L)=>{var V;L&&L.stopPropagation();try{const y=v.metadata||{};let _,F;switch(v.type){case"run":_="/api/jobs/run",F={scenarioKeys:y.scenarioKeys,variant:y.variant,format:y.format,diff:y.diff};break;case"publish":_="/api/jobs/publish",F={scenarioKeys:y.scenarioKeys,selectedGroups:y.selectedGroups,commitMessage:y.commitMessage};break;case"record":_="/api/jobs/record",F={...y};break;default:e({title:"Error",description:`Unknown job type: ${v.type}`,variant:"destructive"});return}const $=await fetch(_,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F)}),E=await $.json();if($.ok)if(e({title:"Retried",description:`New ${v.type} job created`,variant:"success"}),E.jobId||(V=E.job)!=null&&V.id){const A=E.jobId||E.job.id;await p(),s(z=>{const W=z.find(J=>J.id===A);return W&&o(W),z})}else await p();else e({title:"Error",description:E.error||"Failed to retry job",variant:"destructive"})}catch{e({title:"Error",description:"Failed to retry job",variant:"destructive"})}},S=v=>{switch(v){case"running":return n.jsx(_e,{className:"h-3 w-3 animate-spin"});case"success":return n.jsx(vt,{className:"h-3 w-3 text-green-500"});case"failed":return n.jsx(Da,{className:"h-3 w-3 text-destructive"});case"cancelled":return n.jsx(Vo,{className:"h-3 w-3 text-orange-500"});default:return n.jsx(hi,{className:"h-3 w-3 text-muted-foreground"})}},P=v=>{const L={pending:"secondary",running:"default",cancelled:"secondary",success:"default",failed:"destructive"};let V=v.status;if(v.status==="running"){const y=tr(v.logs);y&&(V=`${y.current}/${y.total}`)}return n.jsx(ue,{variant:L[v.status]||"secondary",className:"text-[10px] h-4 px-1.5",children:V})},b=v=>{switch(v){case"run":return n.jsx(Ts,{className:"h-3 w-3"});case"publish":return n.jsx(on,{className:"h-3 w-3"});case"record":return n.jsx(_n,{className:"h-3 w-3"});default:return null}},O=(v,L)=>{if(!L)return"Running...";const V=new Date(L).getTime()-new Date(v).getTime(),y=Math.floor(V/1e3);return y<60?`${y}s`:`${Math.floor(y/60)}m ${y%60}s`},D=l==="all"?t:t.filter(v=>v.type===l);return r&&t.length===0?n.jsx("div",{className:"p-8",children:n.jsx("div",{className:"text-muted-foreground",children:"Loading jobs..."})}):n.jsxs("div",{"data-testid":"studio-jobs","data-loaded":"true",className:"p-5 space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 pb-3",children:[n.jsxs("div",{children:[n.jsx("h1",{className:"text-xl font-bold tracking-tight",children:"Jobs"}),n.jsx("p",{className:"text-xs text-muted-foreground mt-1 font-normal",children:"Execution history and status"})]}),n.jsx(T,{variant:"outline",size:"icon",onClick:p,className:"shadow-sm",title:"Refresh",disabled:r,children:n.jsx(_t,{className:`h-4 w-4 ${r?"animate-spin":""}`})})]}),n.jsx("div",{className:"flex gap-2",children:["all","run","publish","record"].map(v=>n.jsx(T,{variant:l===v?"default":"outline",size:"sm",onClick:()=>c(v),children:v.charAt(0).toUpperCase()+v.slice(1)},v))}),n.jsxs("div",{className:"grid gap-3 lg:grid-cols-3",children:[n.jsx("div",{className:"lg:col-span-2 space-y-2",children:D.length===0?n.jsx(he,{className:"dagster-card",children:n.jsx(me,{className:"py-12 text-center",children:n.jsx("p",{className:"text-muted-foreground",children:"No jobs found"})})}):D.map(v=>n.jsxs(he,{className:Y("dagster-card cursor-pointer group transition-all",(a==null?void 0:a.id)===v.id&&"ring-2 ring-primary bg-primary/5"),onClick:()=>h(v),children:[n.jsx(ke,{className:"pb-2.5 px-4 pt-3",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.jsx("div",{className:Y("p-1.5 rounded-md",v.type==="run"&&"bg-blue-500/10",v.type==="publish"&&"bg-green-500/10",v.type==="record"&&"bg-purple-500/10"),children:b(v.type)}),n.jsxs("div",{children:[n.jsx(be,{className:"text-xs font-semibold",children:v.type.charAt(0).toUpperCase()+v.type.slice(1)}),v.scenarioKey&&n.jsx(at,{className:"text-[10px] font-mono mt-0.5 text-muted-foreground",children:v.scenarioKey})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[v.status==="running"&&n.jsxs(T,{variant:"ghost",size:"sm",className:"h-6 px-2 text-[10px] text-orange-500 hover:text-orange-600 hover:bg-orange-500/10",onClick:L=>w(v.id,L),children:[n.jsx(Vo,{className:"h-3 w-3 mr-1"}),"Cancel"]}),(v.status==="failed"||v.status==="cancelled")&&n.jsxs(T,{variant:"ghost",size:"sm",className:"h-6 px-2 text-[10px] text-blue-500 hover:text-blue-600 hover:bg-blue-500/10",onClick:L=>N(v,L),children:[n.jsx(Wl,{className:"h-3 w-3 mr-1"}),"Retry"]}),S(v.status),P(v)]})]})}),n.jsxs(me,{className:"px-4 pb-3",children:[n.jsxs("div",{className:"flex items-center justify-between text-[10px] text-muted-foreground",children:[n.jsx("span",{className:"font-mono",children:new Date(v.createdAt).toLocaleString()}),n.jsx("span",{className:"font-medium",children:O(v.createdAt,v.status==="running"?new Date().toISOString():v.updatedAt)})]}),(v.status==="running"||v.status==="pending")&&(()=>{const L=tr(v.logs);if(!L)return null;const V=Math.round(L.current/L.total*100);return n.jsxs("div",{className:"mt-2 space-y-1",children:[n.jsx(Fa,{value:V,className:"h-1.5"}),n.jsxs("div",{className:"flex items-center justify-between text-[10px] text-muted-foreground",children:[n.jsxs("span",{children:[L.current,"/",L.total," completed"]}),n.jsxs("span",{children:[V,"%"]})]})]})})()]})]},v.id))}),a&&n.jsxs("div",{className:"space-y-2",children:[n.jsxs(he,{className:"dagster-card",children:[n.jsxs(ke,{className:"px-4 py-3 border-b border-border/50 flex flex-row items-center justify-between",children:[n.jsx(be,{className:"text-xs font-semibold",children:"Job Details"}),n.jsxs("div",{className:"flex items-center gap-2",children:[a.status==="running"&&n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-[10px] text-orange-500 border-orange-500/30 hover:bg-orange-500/10",onClick:()=>w(a.id),children:[n.jsx(Vo,{className:"h-3 w-3 mr-1"}),"Cancel Job"]}),(a.status==="failed"||a.status==="cancelled")&&n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-[10px] text-blue-500 border-blue-500/30 hover:bg-blue-500/10",onClick:()=>N(a),children:[n.jsx(Wl,{className:"h-3 w-3 mr-1"}),"Retry Job"]})]})]}),n.jsxs(me,{className:"space-y-3 px-4 py-3",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-[10px] font-medium text-muted-foreground uppercase tracking-wide mb-1",children:"Type"}),n.jsx("div",{className:"text-xs font-semibold",children:a.type})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-[10px] font-medium text-muted-foreground uppercase tracking-wide mb-1",children:"Status"}),n.jsx("div",{className:"mt-1",children:P(a)})]}),(a.status==="running"||a.status==="pending")&&(()=>{const v=tr(a.logs);if(!v)return null;const L=Math.round(v.current/v.total*100);return n.jsxs("div",{children:[n.jsx("div",{className:"text-[10px] font-medium text-muted-foreground uppercase tracking-wide mb-1",children:"Progress"}),n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(Fa,{value:L,className:"h-2"}),n.jsxs("div",{className:"flex items-center justify-between text-xs",children:[n.jsxs("span",{className:"text-muted-foreground",children:[v.current,"/",v.total," completed"]}),n.jsxs("span",{className:"font-semibold",children:[L,"%"]})]})]})]})})(),a.scenarioKey&&n.jsxs("div",{children:[n.jsx("div",{className:"text-[10px] font-medium text-muted-foreground uppercase tracking-wide mb-1",children:"Scenario"}),n.jsx(Kt,{to:`/scenarios/${a.scenarioKey}`,className:"text-xs font-mono text-primary hover:underline font-medium",children:a.scenarioKey})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-[10px] font-medium text-muted-foreground uppercase tracking-wide mb-1",children:"Started"}),n.jsx("div",{className:"text-xs font-mono",children:new Date(a.createdAt).toLocaleString()})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-[10px] font-medium text-muted-foreground uppercase tracking-wide mb-1",children:"Duration"}),n.jsx("div",{className:"text-xs font-semibold",children:O(a.createdAt,a.status==="running"?new Date().toISOString():a.updatedAt)})]})]})]}),n.jsxs(he,{className:"dagster-card",children:[n.jsxs(ke,{className:"px-4 py-3 border-b border-border/50 flex flex-row items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(be,{className:"text-xs font-semibold",children:"Logs"}),a.status==="running"&&n.jsxs(ue,{variant:"outline",className:"text-[9px] h-4 animate-pulse",children:[n.jsx(_e,{className:"h-2 w-2 mr-1 animate-spin"}),"Live"]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[!m&&n.jsx(T,{variant:"ghost",size:"sm",className:"h-6 text-[10px]",onClick:()=>{f(!0),u.current&&(u.current.scrollTop=u.current.scrollHeight)},children:"Jump to bottom"}),n.jsx(T,{variant:"ghost",size:"sm",className:"h-6 px-2",onClick:()=>{fetch(`/api/jobs/${a.id}`).then(v=>v.json()).then(v=>{v.job&&o(v.job)})},children:n.jsx(_t,{className:"h-3 w-3"})})]})]}),n.jsx(me,{className:"px-4 py-3",children:n.jsx("div",{ref:u,onScroll:j,className:"bg-background/50 rounded-md p-3 font-mono text-[10px] max-h-80 overflow-y-auto border border-border/30",children:a.logs.length===0?n.jsx("div",{className:"text-muted-foreground text-center py-4",children:a.status==="running"?"Waiting for logs...":"No logs available"}):n.jsx("div",{className:"space-y-0.5",children:a.logs.map((v,L)=>{const V=Im(v.message),y=V.includes("⚠ Diff Detected")||V.includes("% changed"),_=V.includes("✔ No changes"),F=V.includes("Diff Summary:"),$=V.includes("📥 Fetching baselines")||V.includes("baseline"),E=V.includes("🔍 Computing visual diffs");let A="";return V.includes("[error]")?A="text-destructive":V.includes("[stderr]")?A="text-orange-500":y?A="text-amber-500 font-medium":_?A="text-green-500":F||E||$?A="text-cyan-500":V.includes("✔")&&(A="text-green-500"),n.jsxs("div",{className:"text-muted-foreground leading-relaxed",children:[n.jsx("span",{className:"text-muted-foreground/40 text-[9px]",children:new Date(v.timestamp).toLocaleTimeString()})," ",n.jsx("span",{className:A,children:V})]},L)})})})})]})]})]}),n.jsx(wi,{open:R,onOpenChange:k,onAuthenticated:x})]})}function M1(){var b,O,D;const{scenarioKey:e,variationSlug:t,captureKey:s}=Kp(),r=Os(),{toast:i}=Pt(),[a,o]=d.useState(null),[l,c]=d.useState(!0),[u,m]=d.useState(null),[f,g]=d.useState(!1),[R,k]=d.useState(""),[C,j]=d.useState({}),[p,h]=d.useState([]),[x,w]=d.useState(null);d.useEffect(()=>{if(!e||!t||!s){c(!1);return}fetch(`/api/output/${e}/${t}`).then(v=>v.json()).then(v=>{var V;const L=(V=v.assets)==null?void 0:V.find(y=>y.filename.replace(/\.[^/.]+$/,"")===s||y.captureKey===s);L&&(o(L),k(L.captureKey||s)),c(!1)}).catch(v=>{console.error("Failed to load asset:",v),c(!1)})},[e,t,s]),d.useEffect(()=>{!e||!s||fetch(`/api/config/scenarios/${e}`).then(v=>v.json()).then(v=>{const L=v.scenario;if(L!=null&&L.steps){const V=L.steps.findIndex(y=>{var _;return y.key===s||y.captureKey===s||((_=y.path)==null?void 0:_.replace(/\.[^/.]+$/,""))===s});V!==-1&&m({step:L.steps[V],index:V})}}).catch(v=>{console.error("Failed to load scenario:",v)})},[e,s]),d.useEffect(()=>{!e||!t||fetch(`/api/output/${e}/${t}/sentinels`).then(v=>v.json()).then(v=>{if(v.files&&v.files.length>0){const L=v.files.map((V,y)=>{var F,$;const _=($=(F=v.sentinelsManifest)==null?void 0:F.sentinels)==null?void 0:$.find(E=>E.filename===V);return{filename:V,label:(_==null?void 0:_.label)||`Step ${y}`,stepIndex:(_==null?void 0:_.stepIndex)??y,url:`${v.basePath}/${V}`,hasDiff:!1,diffPercent:void 0}});h(L)}}).catch(v=>{console.error("Failed to load sentinels:",v)})},[e,t]),d.useEffect(()=>{e&&fetch(`/api/output/${e}/versions`).then(v=>v.json()).then(v=>{const L=v.versions||[],V=L.find(y=>y.timestamp===t)||L[0];if(V){const y={};V.privacy&&(y.privacy=V.privacy),V.style&&(y.style=V.style),j(y)}}).catch(()=>{})},[e,t]),d.useEffect(()=>{!e||!t||p.length===0||fetch(`/api/output/${e}/versions`).then(v=>v.json()).then(v=>{const L=v.versions||[];if(L.length>0){const V=L[0].timestamp;return fetch(`/api/output/${e}/version/${V}/diff-manifest`)}return null}).then(v=>v==null?void 0:v.json()).then(v=>{var L;(L=v==null?void 0:v.manifest)!=null&&L.assets&&h(V=>V.map(y=>{const _=`${t}/sentinels/${y.filename.replace(".png","")}`,F=v.manifest.assets[_];return{...y,hasDiff:F&&!F.match,diffPercent:F==null?void 0:F.diffPercent}}))}).catch(v=>{console.error("Failed to load diff manifest:",v)})},[e,t,p.length]);const N=v=>v<1024?`${v} B`:v<1024*1024?`${(v/1024).toFixed(1)} KB`:`${(v/(1024*1024)).toFixed(1)} MB`,S=()=>{a!=null&&a.path&&(navigator.clipboard.writeText(a.path),i({title:"Copied",description:"File path copied to clipboard",variant:"success"}))},P=async()=>{i({title:"Info",description:"Capture key editing will be available in a future release",variant:"default"}),g(!1)};return l?n.jsx("div",{className:"p-8",children:n.jsx("div",{className:"text-muted-foreground",children:"Loading asset..."})}):a?n.jsxs("div",{"data-testid":"studio-asset-detail","data-loaded":"true",className:"p-5 space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 pb-3",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsxs(T,{variant:"ghost",size:"sm",onClick:()=>r("/assets"),className:"shadow-sm",children:[n.jsx(Bl,{className:"h-3.5 w-3.5 mr-1.5"}),"Back"]}),n.jsxs("div",{children:[n.jsx("h1",{className:"text-xl font-bold tracking-tight",children:a.filename}),n.jsxs("p",{className:"text-xs text-muted-foreground mt-1 font-mono",children:[e," / ",t]})]})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsxs(T,{variant:"outline",size:"sm",onClick:S,className:"shadow-sm",children:[n.jsx(rn,{className:"h-3.5 w-3.5 mr-1.5"}),"Copy Path"]}),n.jsxs("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground shadow-sm",children:[n.jsx(an,{className:"h-3.5 w-3.5"}),"Open"]})]})]}),n.jsxs("div",{className:"grid gap-4 lg:grid-cols-3",children:[n.jsxs("div",{className:"lg:col-span-2 space-y-4",children:[n.jsxs(he,{children:[n.jsx(ke,{children:n.jsx(be,{children:"Preview"})}),n.jsx(me,{children:n.jsx("div",{className:"flex items-center justify-center min-h-[400px] bg-muted rounded-md",children:n.jsx(fo,{url:a.url,filename:a.filename,size:"lg"})})})]}),p.length>0&&n.jsxs(he,{children:[n.jsxs(ke,{children:[n.jsxs(be,{className:"text-sm flex items-center gap-2",children:["Sentinel Frames",p.some(v=>v.hasDiff)&&n.jsxs(ue,{variant:"destructive",className:"text-xs",children:[n.jsx(Qp,{className:"h-3 w-3 mr-1"}),"Changes Detected"]})]}),n.jsx(at,{children:"Captured at each step during recording for visual comparison"})]}),n.jsxs(me,{children:[n.jsx("div",{className:"flex gap-2 overflow-x-auto pb-2",children:p.map(v=>{var L;return n.jsxs("button",{onClick:()=>w((x==null?void 0:x.filename)===v.filename?null:v),className:Y("flex-shrink-0 w-24 h-16 rounded border-2 overflow-hidden relative group",v.hasDiff?"border-red-500":"border-transparent",(x==null?void 0:x.filename)===v.filename&&"ring-2 ring-primary"),title:v.label,children:[n.jsx("img",{src:v.url,alt:v.label,className:"w-full h-full object-cover"}),v.hasDiff&&n.jsxs("div",{className:"absolute top-0 right-0 bg-red-500 text-white text-[10px] px-1 rounded-bl",children:[(L=v.diffPercent)==null?void 0:L.toFixed(1),"%"]}),n.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/60 text-white text-[10px] px-1 py-0.5 opacity-0 group-hover:opacity-100 transition-opacity truncate",children:v.label})]},v.filename)})}),x&&n.jsxs("div",{className:"mt-4 border rounded-lg p-4 bg-muted/50",children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("div",{className:"text-sm font-medium",children:x.label}),x.hasDiff&&n.jsxs(ue,{variant:"destructive",children:[(b=x.diffPercent)==null?void 0:b.toFixed(2),"% different"]})]}),n.jsx("img",{src:x.url,alt:x.label,className:"w-full rounded border"})]})]})]})]}),n.jsxs("div",{className:"space-y-4",children:[n.jsxs(he,{children:[n.jsx(ke,{children:n.jsx(be,{children:"Metadata"})}),n.jsxs(me,{className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Capture Key"}),f?n.jsxs("div",{className:"flex gap-2 mt-1",children:[n.jsx(ve,{value:R,onChange:v=>k(v.target.value),className:"font-mono text-sm"}),n.jsx(T,{size:"sm",onClick:P,children:"Save"}),n.jsx(T,{size:"sm",variant:"outline",onClick:()=>{g(!1),k(a.captureKey||s||"")},children:"Cancel"})]}):n.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[n.jsx("code",{className:"text-sm font-mono bg-muted px-2 py-1 rounded flex-1",children:a.captureKey||s}),n.jsx(T,{variant:"ghost",size:"sm",onClick:()=>g(!0),children:"Edit"})]})]}),n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"File Size"}),n.jsx("div",{className:"text-sm font-medium mt-1",children:N(a.size)})]}),n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Modified"}),n.jsx("div",{className:"text-sm font-medium mt-1",children:new Date(a.mtime).toLocaleString()})]}),n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"File Path"}),n.jsx("div",{className:"text-xs font-mono bg-muted px-2 py-1 rounded mt-1 break-all",children:a.relativePath})]}),u&&n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Linked Step"}),n.jsx("div",{className:"mt-1",children:n.jsxs(Kt,{to:`/scenarios/${e}?step=${u.index}`,className:"inline-flex items-center gap-1.5 text-sm text-primary hover:underline",children:[n.jsx(Rn,{className:"h-3.5 w-3.5"}),"Step #",u.index+1,": ",u.step.action]})}),u.step.selector&&n.jsx("div",{className:"text-xs font-mono bg-muted px-2 py-1 rounded mt-1",children:u.step.selector}),u.step.clip&&n.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Clip: ",JSON.stringify(u.step.clip)]})]}),n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Variation Context"}),n.jsx("div",{className:"mt-1",children:n.jsx(ue,{variant:"secondary",children:t})})]}),((O=C.privacy)==null?void 0:O.enabled)&&n.jsxs("div",{children:[n.jsxs(q,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n.jsx(xr,{className:"h-3 w-3"}),"Privacy Masking"]}),n.jsxs("div",{className:"text-sm font-medium mt-1 capitalize",children:[C.privacy.method||"redact",C.privacy.selectorCount!=null&&n.jsxs("span",{className:"text-muted-foreground font-normal",children:[" ","(",C.privacy.selectorCount," selector",C.privacy.selectorCount!==1?"s":"",")"]})]})]}),((D=C.style)==null?void 0:D.enabled)&&n.jsxs("div",{children:[n.jsxs(q,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n.jsx(ao,{className:"h-3 w-3"}),"Style Processing"]}),n.jsxs("div",{className:"text-sm font-medium mt-1",children:[C.style.frame!=="none"&&n.jsxs("span",{className:"capitalize",children:[C.style.frame," frame"]}),C.style.shadow!=="none"&&n.jsxs("span",{children:[C.style.frame!=="none"?", ":"",C.style.shadow," shadow"]}),(!C.style.frame||C.style.frame==="none")&&(!C.style.shadow||C.style.shadow==="none")&&n.jsx("span",{children:"Custom style applied"})]})]})]})]}),u&&n.jsxs(he,{children:[n.jsx(ke,{children:n.jsx(be,{children:"Step Details"})}),n.jsxs(me,{className:"space-y-2 text-sm",children:[n.jsxs("div",{children:[n.jsx("span",{className:"text-muted-foreground",children:"Action:"})," ",n.jsx(ue,{variant:"outline",children:u.step.action})]}),u.step.selectorPadding!==void 0&&n.jsxs("div",{children:[n.jsx("span",{className:"text-muted-foreground",children:"Selector Padding:"})," ",u.step.selectorPadding,"px"]}),u.step.deviceScaleFactor!==void 0&&n.jsxs("div",{children:[n.jsx("span",{className:"text-muted-foreground",children:"Device Scale Factor:"})," ",u.step.deviceScaleFactor]})]})]})]})]})]}):n.jsx("div",{className:"p-8",children:n.jsxs(he,{children:[n.jsxs(ke,{children:[n.jsx(be,{children:"Asset Not Found"}),n.jsx(at,{children:"The requested asset could not be found."})]}),n.jsx(me,{children:n.jsxs(T,{onClick:()=>r("/assets"),variant:"outline",children:[n.jsx(Bl,{className:"h-4 w-4 mr-2"}),"Back to Assets"]})})]})})}function I1({visualKey:e,visualTitle:t,targetUrl:s,targetId:r,scenarioUrl:i,onRecordingComplete:a}){const{status:o,steps:l,isConnected:c,start:u,stop:m,capture:f,removeStep:g}=bm(),{toast:R}=Pt(),[k,C]=d.useState(!1),[j,p]=d.useState(!1),[h,x]=d.useState(!1),[w,N]=d.useState(null),S=d.useRef(null);d.useEffect(()=>{S.current&&(S.current.scrollTop=S.current.scrollHeight)},[l]);const P=async()=>{C(!0);try{await u({visualKey:e,title:t||"Untitled Visual",targetUrl:s,targetId:r,scenarioUrl:i})}catch(v){R({title:"Error",description:v.message,variant:"destructive"})}finally{C(!1)}},b=async v=>{v?p(!0):x(!0);try{await m(v),R({title:v?"Recording Saved":"Recording Cancelled",description:v?"Your scenario has been saved.":"Recording was discarded.",variant:v?"success":"default"}),v&&a?a(o.visualKey):a&&a()}catch(L){R({title:"Error",description:L.message,variant:"destructive"})}finally{p(!1),x(!1)}},O=async()=>{try{await f({outputFilename:`${o.visualKey}-${Date.now()}.png`}),R({title:"Screenshot Captured",variant:"success"})}catch(v){R({title:"Error",description:v.message,variant:"destructive"})}},D=async v=>{N(v);try{await g(v),R({title:"Step Removed",variant:"success"})}catch(L){R({title:"Error",description:L.message,variant:"destructive"})}finally{N(null)}};return n.jsxs("div",{className:"space-y-4",children:[n.jsxs(he,{className:o.active?"border-green-500/50":"",children:[n.jsx(ke,{className:"pb-3",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(be,{className:"text-sm font-medium",children:o.active?"Recording Active":"Ready to Record"}),o.active&&n.jsx(ue,{variant:"default",className:"animate-pulse bg-red-500",children:"LIVE"})]}),c?n.jsx(ue,{variant:"outline",className:"text-green-500 border-green-500/30",children:"System Connected"}):n.jsx(ue,{variant:"destructive",children:"System Disconnected"})]})}),n.jsx(me,{children:o.active?n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"flex gap-2",children:n.jsxs(T,{onClick:O,variant:"secondary",className:"flex-1",children:[n.jsx(na,{className:"mr-2 h-4 w-4 fill-current"}),"Capture Screen"]})}),n.jsxs("div",{className:"flex gap-2",children:[n.jsxs(T,{onClick:()=>b(!1),variant:"outline",disabled:h||j,className:"flex-1",children:[h?n.jsx(_e,{className:"mr-2 h-4 w-4 animate-spin"}):n.jsx(ln,{className:"mr-2 h-4 w-4"}),"Cancel"]}),n.jsxs(T,{onClick:()=>b(!0),variant:"default",disabled:j||h,className:"flex-1 bg-green-600 hover:bg-green-700",children:[j?n.jsx(_e,{className:"mr-2 h-4 w-4 animate-spin"}):n.jsx(Hr,{className:"mr-2 h-4 w-4"}),"Stop & Save"]})]}),n.jsxs("p",{className:"text-xs text-muted-foreground text-center",children:[l.length," step",l.length!==1?"s":""," recorded"]})]}):n.jsxs(T,{onClick:P,disabled:k||!c,className:"w-full",children:[k?n.jsx(_e,{className:"mr-2 h-4 w-4 animate-spin"}):n.jsx(_n,{className:"mr-2 h-4 w-4"}),"Start Recording"]})})]}),o.active&&n.jsxs(he,{className:"h-64 flex flex-col",children:[n.jsx(ke,{className:"py-3 border-b bg-muted/30",children:n.jsx(be,{className:"text-xs font-mono uppercase text-muted-foreground",children:"Live Action Log"})}),n.jsxs("div",{ref:S,className:"flex-1 overflow-y-auto p-4 space-y-2 font-mono text-xs",children:[l.length===0&&n.jsx("div",{className:"text-center text-muted-foreground py-8",children:"Interact with the browser window to see actions here..."}),l.map((v,L)=>n.jsxs("div",{className:"group flex items-start gap-2 p-2 rounded bg-muted/50 border border-transparent hover:border-border transition-colors",children:[n.jsxs("div",{className:"mt-0.5 text-muted-foreground",children:[v.action==="click"&&n.jsx(Jy,{className:"h-3 w-3"}),v.action==="type"&&n.jsx(t0,{className:"h-3 w-3"}),v.action==="screenshot"&&n.jsx(Oy,{className:"h-3 w-3"})]}),n.jsxs("div",{className:"flex-1 break-all",children:[n.jsx("span",{className:"font-bold text-primary",children:v.action.toUpperCase()}),n.jsx("span",{className:"mx-2 text-muted-foreground",children:"→"}),n.jsx("span",{className:"bg-background px-1 rounded border",children:v.selector||"page"}),v.text&&n.jsxs("div",{className:"mt-1 text-muted-foreground",children:['Value: "',v.text,'"']})]}),n.jsx("button",{onClick:()=>D(L),disabled:w!==null,className:"opacity-0 group-hover:opacity-100 transition-opacity p-1 hover:bg-red-100 hover:text-red-600 rounded",title:"Remove this step",children:w===L?n.jsx(_e,{className:"h-3 w-3 animate-spin"}):n.jsx(ps,{className:"h-3 w-3"})})]},L))]})]})]})}function D1(){const e=Os(),{status:t,isConnected:s,error:r,diagnostics:i}=bm(),{toast:a}=Pt(),[o,l]=d.useState([]),[c,u]=d.useState(""),[m,f]=d.useState(""),[g,R]=d.useState(""),[k,C]=d.useState("new"),[j,p]=d.useState(null),[h,x]=d.useState(!1),[w,N]=d.useState([]),[S,P]=d.useState(""),[b,O]=d.useState(!1),[D,v]=d.useState(null),[L,V]=d.useState(!1),y=d.useCallback(async()=>{x(!0);try{const fe=await(await fetch("/api/recorder/check-chrome")).json();p(fe)}catch{p({ok:!1,chromeAvailable:!1,error:"Failed to check Chrome status"})}finally{x(!1)}},[]),_=d.useCallback(async()=>{O(!0);try{const fe=await(await fetch("/api/recorder/tabs")).json();if(fe.ok&&fe.tabs){const ye=fe.tabs.filter(ge=>!ge.isOurUI&&!ge.isChrome);N(ye),P(ge=>!ge&&ye.length>0?ye[0].id:ge&&ye.some(Re=>Re.id===ge)?ge:ye.length>0?ye[0].id:"")}}catch(G){console.error("Failed to load tabs:",G)}finally{O(!1)}},[]),F=d.useCallback(async()=>{try{const fe=await(await fetch("/api/recorder/session-status")).json();fe.ok&&v(fe)}catch(G){console.error("Failed to check session status:",G)}},[]),$=d.useCallback(async()=>{V(!0);try{const fe=await(await fetch("/api/recorder/save-session",{method:"POST"})).json();fe.ok?(a({title:"Session Saved",description:"Your authenticated session has been saved. Future captures will use your login state."}),F()):a({title:"Save Failed",description:fe.error||"Could not save session. Make sure Chrome is running with your app logged in.",variant:"destructive"})}catch{a({title:"Error",description:"Failed to connect to server",variant:"destructive"})}finally{V(!1)}},[a,F]),E=d.useCallback(async()=>{var G;try{const ye=await(await fetch("/api/config")).json();(G=ye.config)!=null&&G.scenarios&&l(ye.config.scenarios)}catch(fe){console.error("Failed to load scenarios:",fe)}},[]);d.useEffect(()=>{E(),y(),F()},[y,F]),d.useEffect(()=>{j!=null&&j.chromeAvailable&&_()},[j==null?void 0:j.chromeAvailable,_]);const A=()=>{if(k==="existing"&&c){const G=o.find(fe=>fe.key===c);return{visualKey:c,title:(G==null?void 0:G.name)||c}}return k==="new"&&m.trim()?{visualKey:m.toLowerCase().replace(/[^a-z0-9\s-]/g,"").trim().replace(/\s+/g,"-").replace(/-+/g,"-"),title:m.trim()}:{visualKey:void 0,title:void 0}},{visualKey:z,title:W}=A(),J=w.find(G=>G.id===S);return n.jsxs("div",{"data-testid":"studio-recorder","data-loaded":"true",className:"p-8 space-y-6 max-w-4xl mx-auto",children:[n.jsxs("div",{children:[n.jsx("h1",{className:"text-3xl font-bold",children:"Recording Studio"}),n.jsx("p",{className:"text-muted-foreground mt-2",children:"Capture screenshots and user interactions from your application"})]}),n.jsxs(he,{className:j!=null&&j.hasValidTab?"border-green-500/50 bg-green-500/5":j!=null&&j.chromeAvailable?"border-yellow-500/50 bg-yellow-500/5":"border-red-500/50 bg-red-500/5",children:[n.jsx(ke,{className:"pb-3",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs(be,{className:"text-sm font-medium flex items-center gap-2",children:[n.jsx(Yp,{className:"h-4 w-4"}),"Chrome Browser Status"]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(T,{variant:"ghost",size:"icon",onClick:y,disabled:h,title:"Refresh",children:n.jsx(_t,{className:`h-4 w-4 ${h?"animate-spin":""}`})}),j&&n.jsx(ue,{variant:j.hasValidTab?"default":j.chromeAvailable?"secondary":"destructive",children:j.hasValidTab?n.jsxs(n.Fragment,{children:[n.jsx(vt,{className:"h-3 w-3 mr-1"}),"Ready"]}):j.chromeAvailable?n.jsxs(n.Fragment,{children:[n.jsx(Jt,{className:"h-3 w-3 mr-1"}),"Needs Tab"]}):n.jsxs(n.Fragment,{children:[n.jsx(Jt,{className:"h-3 w-3 mr-1"}),"Not Running"]})})]})]})}),n.jsxs(me,{className:"space-y-3",children:[!(j!=null&&j.chromeAvailable)&&n.jsxs("div",{className:"space-y-3",children:[n.jsx("div",{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground",children:n.jsx(ue,{variant:"secondary",children:"Not Connected"})}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"To enable recording, launch a dedicated Chrome instance:"}),n.jsxs("div",{className:"bg-background rounded-md p-3 border space-y-2",children:[n.jsx("p",{className:"text-xs font-medium text-foreground",children:"Run this command in your Terminal:"}),n.jsxs("div",{className:"relative",children:[n.jsx("code",{className:"block bg-muted px-3 py-2 pr-10 rounded text-xs font-mono break-all select-all",children:'/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --remote-debugging-port=9222 --user-data-dir="$HOME/.reshot/chrome-debug"'}),n.jsx(T,{variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 -translate-y-1/2 h-7 w-7",onClick:()=>{navigator.clipboard.writeText('/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --remote-debugging-port=9222 --user-data-dir="$HOME/.reshot/chrome-debug"'),a({title:"Copied",description:"Command copied to clipboard"})},title:"Copy command",children:n.jsx(rn,{className:"h-3.5 w-3.5"})})]}),n.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Note: This launches a separate Chrome profile. You do not need to close your main browser."})]})]}),(j==null?void 0:j.chromeAvailable)&&!j.hasValidTab&&n.jsxs("div",{className:"space-y-2",children:[n.jsx("p",{className:"text-sm text-yellow-600 font-medium",children:"Chrome is running, but no valid tabs found."}),n.jsx("p",{className:"text-xs text-muted-foreground",children:'Please open a tab and navigate to your application, then click "Refresh" above.'})]}),(j==null?void 0:j.hasValidTab)&&n.jsxs("div",{className:"space-y-3",children:[n.jsx("p",{className:"text-sm text-green-600 font-medium",children:"✓ Chrome is ready for recording!"}),w.length>0&&n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs font-medium",children:"Select Tab to Record:"}),n.jsx("div",{className:"space-y-1.5",children:w.map(G=>n.jsxs("div",{onClick:()=>P(G.id),className:`flex items-center gap-2 text-xs px-3 py-2 rounded cursor-pointer transition-colors ${S===G.id?"bg-primary text-primary-foreground":"bg-muted/50 hover:bg-muted"}`,children:[n.jsx(ur,{className:"h-3 w-3 flex-shrink-0"}),n.jsxs("div",{className:"truncate flex-1",children:[n.jsx("div",{className:"font-medium truncate",children:G.title||"Untitled"}),n.jsx("div",{className:`text-[10px] truncate ${S===G.id?"text-primary-foreground/70":"text-muted-foreground"}`,children:G.url})]}),S===G.id&&n.jsx(vt,{className:"h-3 w-3 flex-shrink-0"})]},G.id))}),n.jsxs(T,{variant:"ghost",size:"sm",onClick:_,disabled:b,className:"text-xs",children:[n.jsx(_t,{className:`h-3 w-3 mr-1 ${b?"animate-spin":""}`}),"Refresh Tabs"]})]}),w.length===0&&n.jsx("p",{className:"text-xs text-muted-foreground",children:"No recordable tabs found. Open your application in Chrome."})]})]})]}),(j==null?void 0:j.chromeAvailable)&&n.jsxs(he,{className:D!=null&&D.hasSession?"border-blue-500/30":"border-muted",children:[n.jsxs(ke,{className:"pb-3",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs(be,{className:"text-sm font-medium flex items-center gap-2",children:[n.jsx(La,{className:"h-4 w-4"}),"Authentication Session"]}),(D==null?void 0:D.hasSession)&&n.jsx(ue,{variant:D.isStale?"secondary":"default",children:D.isStale?"Stale":"Active"})]}),n.jsx(at,{className:"text-xs",children:"Save your logged-in session so captures can access authenticated pages"})]}),n.jsxs(me,{className:"space-y-3",children:[D!=null&&D.hasSession?n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center gap-2 text-sm text-green-600",children:[n.jsx(vt,{className:"h-4 w-4"}),n.jsx("span",{children:"Session saved"})]}),n.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[n.jsxs("p",{children:[D.cookieCount," cookies stored"]}),n.jsxs("p",{children:["Saved"," ",D.ageHours?`${D.ageHours}h ago`:"recently"]}),D.isStale&&n.jsx("p",{className:"text-yellow-600",children:"Session may be expired - consider saving a fresh one"})]})]}):n.jsx("div",{className:"text-xs text-muted-foreground",children:n.jsx("p",{children:"No saved session. Log into your app in Chrome, then save your session."})}),n.jsx(T,{variant:D!=null&&D.hasSession?"outline":"default",size:"sm",onClick:$,disabled:L||!(j!=null&&j.chromeAvailable),className:"w-full",children:L?n.jsxs(n.Fragment,{children:[n.jsx(_t,{className:"h-3 w-3 mr-2 animate-spin"}),"Saving..."]}):n.jsxs(n.Fragment,{children:[n.jsx(La,{className:"h-3 w-3 mr-2"}),D!=null&&D.hasSession?"Update Session":"Save Session"]})})]})]}),n.jsxs(he,{className:s?"border-green-500/30":"border-red-500/30",children:[n.jsx(ke,{className:"pb-3",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs(be,{className:"text-sm font-medium flex items-center gap-2",children:[n.jsx(Ia,{className:"h-4 w-4"}),"Server Connection"]}),n.jsx(ue,{variant:s?"default":"destructive",children:s?n.jsxs(n.Fragment,{children:[n.jsx(vt,{className:"h-3 w-3 mr-1"}),"Connected"]}):n.jsxs(n.Fragment,{children:[n.jsx(Jt,{className:"h-3 w-3 mr-1"}),"Disconnected"]})})]})}),n.jsx(me,{children:n.jsx("p",{className:"text-xs text-muted-foreground",children:s?"Real-time events will be captured and displayed.":"Connection lost. Please refresh the page."})})]}),r&&n.jsx(he,{className:"border-red-500/50 bg-red-50/10",children:n.jsx(me,{className:"pt-4",children:n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(Jt,{className:"h-5 w-5 text-red-500 mt-0.5"}),n.jsxs("div",{children:[n.jsx("p",{className:"font-medium text-red-600",children:"Recording Error"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:r})]})]})})}),!t.active&&n.jsxs(he,{children:[n.jsxs(ke,{children:[n.jsxs(be,{className:"text-sm font-medium flex items-center gap-2",children:[n.jsx(_n,{className:"h-4 w-4"}),"Configure Recording Session"]}),n.jsx(at,{children:"Choose to record a new visual or edit an existing scenario"})]}),n.jsxs(me,{className:"space-y-4",children:[n.jsxs("div",{className:"flex gap-2",children:[n.jsx(T,{variant:k==="new"?"default":"outline",size:"sm",onClick:()=>C("new"),children:"New Visual"}),n.jsxs(T,{variant:k==="existing"?"default":"outline",size:"sm",onClick:()=>C("existing"),disabled:o.length===0,children:["Edit Existing (",o.length,")"]})]}),k==="new"&&n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{htmlFor:"visual-title",children:"Visual Title"}),n.jsx(ve,{id:"visual-title",placeholder:"e.g., Admin Dashboard View",value:m,onChange:G=>f(G.target.value)}),m&&n.jsxs("p",{className:"text-xs text-muted-foreground",children:["Key:"," ",n.jsx("code",{className:"bg-muted px-1 rounded",children:z})]})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsxs(q,{htmlFor:"visual-url",children:["Scenario URL"," ",n.jsx("span",{className:"text-muted-foreground text-xs",children:"(optional)"})]}),n.jsx(ve,{id:"visual-url",placeholder:"https://your-app.com/page (uses tab URL if blank)",value:g,onChange:G=>R(G.target.value)}),n.jsx("p",{className:"text-xs text-muted-foreground",children:g?"This URL will be saved with the scenario.":"Leave blank to use the URL from the selected Chrome tab."})]})]}),k==="existing"&&o.length>0&&n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{children:"Select Scenario"}),n.jsx("div",{className:"grid gap-2",children:o.map(G=>{var fe;return n.jsxs("div",{onClick:()=>u(G.key),className:`p-3 rounded-md border cursor-pointer transition-colors ${c===G.key?"border-primary bg-primary/5":"border-border hover:border-primary/50"}`,children:[n.jsx("p",{className:"font-medium text-sm",children:G.name}),n.jsxs("p",{className:"text-xs text-muted-foreground",children:[G.key," • ",((fe=G.steps)==null?void 0:fe.length)||0," steps"]})]},G.key)})})]})]})]}),n.jsx(I1,{visualKey:z,visualTitle:W,targetUrl:J==null?void 0:J.url,targetId:S,scenarioUrl:k==="new"&&g.trim()?g.trim():void 0,onRecordingComplete:G=>{a({title:"Recording Complete",description:"Scenario has been saved.",variant:"success"});const fe=G||z;fe?setTimeout(()=>{e(`/scenarios/${fe}`)},500):fetch("/api/config").then(ye=>ye.json()).then(ye=>{var ge;if((ge=ye.config)!=null&&ge.scenarios){l(ye.config.scenarios);const Re=ye.config.scenarios[ye.config.scenarios.length-1];Re!=null&&Re.key?e(`/scenarios/${Re.key}`):e("/scenarios")}}).catch(()=>{e("/scenarios")})}}),i.length>0&&n.jsxs(he,{children:[n.jsx(ke,{className:"py-3 border-b",children:n.jsxs(be,{className:"text-xs font-mono uppercase text-muted-foreground flex items-center gap-2",children:[n.jsx(e0,{className:"h-3 w-3"}),"Diagnostic Log (",i.length,")"]})}),n.jsx(me,{className:"p-0 max-h-48 overflow-y-auto",children:n.jsx("div",{className:"font-mono text-xs divide-y divide-border",children:i.slice(-20).map((G,fe)=>n.jsxs("div",{className:`px-4 py-2 ${G.level==="error"?"bg-red-50/10 text-red-600":G.level==="warn"?"bg-yellow-50/10 text-yellow-600":"text-muted-foreground"}`,children:[n.jsxs("span",{className:"opacity-50",children:["[",new Date(G.timestamp).toLocaleTimeString(),"]"]})," ",G.message]},fe))})})]}),n.jsxs(he,{className:"bg-muted/30",children:[n.jsx(ke,{children:n.jsx(be,{className:"text-sm font-medium",children:"How to Record"})}),n.jsx(me,{className:"text-sm text-muted-foreground space-y-4",children:n.jsxs("ol",{className:"list-decimal list-inside space-y-3",children:[n.jsxs("li",{children:[n.jsx("strong",{children:"Launch a dedicated Chrome instance"})," with debugging enabled:",n.jsxs("div",{className:"relative mt-1",children:[n.jsx("code",{className:"block bg-background px-2 py-1.5 pr-10 rounded text-xs font-mono select-all",children:'/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --remote-debugging-port=9222 --user-data-dir="$HOME/.reshot/chrome-debug"'}),n.jsx(T,{variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 -translate-y-1/2 h-6 w-6",onClick:()=>{navigator.clipboard.writeText('/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --remote-debugging-port=9222 --user-data-dir="$HOME/.reshot/chrome-debug"'),a({title:"Copied",description:"Command copied to clipboard"})},title:"Copy command",children:n.jsx(rn,{className:"h-3 w-3"})})]}),n.jsx("p",{className:"text-xs text-muted-foreground/70 mt-1 italic",children:"This uses a separate Chrome profile. Your main browser stays untouched."})]}),n.jsxs("li",{children:[n.jsx("strong",{children:"Navigate to your application"})," in the Chrome window that opens"]}),n.jsxs("li",{children:[n.jsx("strong",{children:'Click "Refresh"'})," in the Chrome Status card above to verify connection"]}),n.jsxs("li",{children:["Configure a new visual or select an existing scenario, then click"," ",n.jsx("strong",{children:'"Start Recording"'})]}),n.jsxs("li",{children:["Interact with your app - clicks and inputs will be captured. Click"," ",n.jsx("strong",{children:'"Capture Screen"'})," for screenshots."]}),n.jsxs("li",{children:["Click ",n.jsx("strong",{children:'"Stop & Save"'})," when finished"]})]})})]})]})}const ca=d.forwardRef(({checked:e,onCheckedChange:t,className:s,disabled:r},i)=>n.jsx("button",{ref:i,role:"switch","aria-checked":e,disabled:r,onClick:()=>t(!e),className:Y("inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background","disabled:cursor-not-allowed disabled:opacity-50",e?"bg-primary":"bg-muted",s),children:n.jsx("span",{className:Y("pointer-events-none h-5 w-5 rounded-full bg-foreground shadow-lg transition-transform duration-150",e?"translate-x-5":"translate-x-0.5")})}));ca.displayName="Switch";const js=d.forwardRef(({selected:e,onClick:t,label:s,children:r,className:i},a)=>n.jsxs("button",{ref:a,onClick:t,className:Y("group flex flex-col items-center gap-1.5 rounded-lg p-3 cursor-pointer transition-all duration-150","active:scale-[0.98]",e?"ring-2 ring-primary bg-primary/5 border-transparent":"border border-border/40 bg-card/30 hover:bg-card/60 hover:border-border/60 hover:shadow-[0_2px_8px_rgba(0,0,0,0.2)]",i),children:[n.jsx("div",{className:"w-full h-12 flex items-center justify-center",children:r}),n.jsx("span",{className:"text-xs text-muted-foreground group-hover:text-foreground transition-colors duration-150",children:s})]}));js.displayName="OptionCard";function Wi(e,t,s){const r=(e-t)/(s-t)*100;return`linear-gradient(to right, hsl(262 83% 58%) ${r}%, hsl(217 33% 17%) ${r}%)`}const F1=[{key:"locale",label:"Language",description:"Internationalization (i18n)",icon:ur},{key:"role",label:"User Role",description:"RBAC / Permissions",icon:tm},{key:"theme",label:"Theme",description:"Light/Dark mode",icon:Xc}];function $1(){var je,B,oe,se,re,qe,De,At;const[e,t]=d.useState(null),[s,r]=d.useState(!0),[i,a]=d.useState(!1),[o,l]=d.useState(null),[c,u]=d.useState(!1),[m,f]=d.useState(!1),[g,R]=d.useState(""),[k,C]=d.useState(""),[j,p]=d.useState(""),[h,x]=d.useState({}),[w,N]=d.useState(null),[S,P]=d.useState(!1),[b,O]=d.useState({enabled:!1,method:"redact",blurRadius:8,selectors:[]}),[D,v]=d.useState(""),[L,V]=d.useState(!1),[y,_]=d.useState({enabled:!1,frame:"none",shadow:"medium",padding:40,background:"transparent",borderRadius:0}),[F,$]=d.useState(!1),[E,A]=d.useState(null),[z,W]=d.useState(!1),[J,G]=d.useState([]),[fe,ye]=d.useState([]),[ge,Re]=d.useState(""),[U,X]=d.useState(null),{toast:Z}=Pt(),ce=d.useCallback(async()=>{try{const ee=await(await fetch("/api/config")).json();t(ee.config);const Ce=await(await fetch("/api/viewports")).json();x(Ce.all||{});const Ge=await(await fetch("/api/output-template")).json();G(Ge.presets||[]),ye(Ge.availableVariables||[]),Re(Ge.currentTemplate||"");const pn=await(await fetch("/api/privacy")).json();O(pn);const mn=await(await fetch("/api/style")).json();_(mn)}catch(I){console.error("Failed to load config:",I),Z({title:"Error",description:"Failed to load configuration",variant:"destructive"})}finally{r(!1)}},[Z]);d.useEffect(()=>{ce()},[ce]);const ie=d.useCallback(async I=>{if(!I){X(null);return}try{const pe=await(await fetch("/api/output-template/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({template:I})})).json();X(pe)}catch{X({valid:!1,error:"Failed to validate"})}},[]);d.useEffect(()=>{const I=setTimeout(()=>{ge&&ie(ge)},500);return()=>clearTimeout(I)},[ge,ie]),d.useEffect(()=>{if(!y.enabled)return;const I=setTimeout(async()=>{W(!0);try{const ee=await fetch("/api/style/preview",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({style:y})}),pe=await ee.json();ee.ok&&pe.preview&&A(pe.preview)}catch{}finally{W(!1)}},600);return()=>clearTimeout(I)},[y]);const ae=async()=>{var I;if(e){a(!0);try{const ee=await fetch("/api/config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(ge&&ge!==((I=e.output)==null?void 0:I.template)&&await fetch("/api/output-template",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({template:ge})}),ee.ok)Z({title:"Saved",description:"Configuration updated successfully",variant:"success"});else throw new Error("Failed to save")}catch{Z({title:"Error",description:"Failed to save configuration",variant:"destructive"})}finally{a(!1)}}},Se=(I,ee)=>{e&&t({...e,[I]:ee})},Ie=(I,ee)=>{e&&t({...e,viewport:{width:I,height:ee}})},mt=(I,ee,pe)=>{var Ge;if(!e||!I.trim())return;const Ce=I.toLowerCase().replace(/\s+/g,"-"),Oe=((Ge=e.variants)==null?void 0:Ge.dimensions)||{};if(Oe[Ce]){Z({title:"Already exists",description:`Dimension "${Ce}" already exists`,variant:"destructive"});return}t({...e,variants:{...e.variants,dimensions:{...Oe,[Ce]:{label:ee||I,description:pe,options:{}}}}}),l(Ce),u(!1),R("")},Nt=I=>{var pe;if(!e)return;const ee={...(pe=e.variants)==null?void 0:pe.dimensions};delete ee[I],t({...e,variants:{...e.variants,dimensions:ee}}),o===I&&l(Object.keys(ee)[0]||null)},Ft=(I,ee,pe)=>{var ls;if(!e||!ee.trim())return;const Ce=ee.toLowerCase().replace(/\s+/g,"-"),Oe=((ls=e.variants)==null?void 0:ls.dimensions)||{},Ge=Oe[I];if(Ge){if(Ge.options[Ce]){Z({title:"Already exists",description:`Option "${Ce}" already exists`,variant:"destructive"});return}t({...e,variants:{...e.variants,dimensions:{...Oe,[I]:{...Ge,options:{...Ge.options,[Ce]:{name:pe||ee,inject:[]}}}}}}),f(!1),C(""),p("")}},Yt=(I,ee)=>{var Ge;if(!e)return;const pe=((Ge=e.variants)==null?void 0:Ge.dimensions)||{},Ce=pe[I];if(!Ce)return;const Oe={...Ce.options};delete Oe[ee],t({...e,variants:{...e.variants,dimensions:{...pe,[I]:{...Ce,options:Oe}}}})},$t=(I,ee,pe,Ce,Oe)=>{var mn;if(!e)return;const Ge=((mn=e.variants)==null?void 0:mn.dimensions)||{},ls=Ge[I];if(!ls)return;const pn=ls.options[ee];if(!pn)return;const ki=Ce||Oe?[{method:pe,key:Ce,value:Oe}]:[];t({...e,variants:{...e.variants,dimensions:{...Ge,[I]:{...ls,options:{...ls.options,[ee]:{...pn,inject:ki}}}}}})};if(s)return n.jsx("div",{className:"h-full flex items-center justify-center",children:n.jsx(_e,{className:"h-6 w-6 animate-spin text-muted-foreground"})});if(!e)return n.jsx("div",{className:"p-6",children:n.jsx(he,{children:n.jsxs(me,{className:"py-12 text-center",children:[n.jsx(Ia,{className:"h-10 w-10 mx-auto mb-3 opacity-30"}),n.jsx("p",{className:"text-muted-foreground",children:"No configuration found."}),n.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Create a docsync.config.json file to get started."})]})})});const kt=((je=e.variants)==null?void 0:je.dimensions)||{},Tt=Object.keys(kt),Vt=o?kt[o]:null;return n.jsxs("div",{"data-testid":"studio-config","data-loaded":"true",className:"h-full flex flex-col",children:[n.jsxs("div",{className:"shrink-0 px-4 py-3 border-b flex items-center justify-between bg-card",children:[n.jsxs("div",{children:[n.jsx("h1",{className:"text-sm font-semibold",children:"Configuration"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"docsync.config.json"})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx(T,{variant:"ghost",size:"sm",onClick:ce,className:"h-7",children:n.jsx(_t,{className:"h-3 w-3"})}),n.jsxs(T,{size:"sm",onClick:ae,disabled:i,className:"h-7",children:[i?n.jsx(_e,{className:"h-3 w-3 animate-spin"}):n.jsx(Hr,{className:"h-3 w-3 mr-1"}),"Save"]})]})]}),n.jsxs("div",{className:"flex-1 overflow-auto p-4 space-y-4",children:[n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[n.jsxs("div",{className:"space-y-1",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Base URL"}),n.jsx(ve,{value:e.baseUrl,onChange:I=>Se("baseUrl",I.target.value),placeholder:"http://localhost:3000",className:"h-8 text-sm"})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Asset Directory"}),n.jsx(ve,{value:e.assetDir,onChange:I=>Se("assetDir",I.target.value),placeholder:".reshot/output",className:"h-8 text-sm"})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Viewport"}),n.jsxs("div",{className:"flex gap-1",children:[n.jsx(T,{variant:e.viewport.width===1280?"default":"outline",size:"sm",className:"h-8 text-xs flex-1",onClick:()=>Ie(1280,720),children:"720p"}),n.jsx(T,{variant:e.viewport.width===1920?"default":"outline",size:"sm",className:"h-8 text-xs flex-1",onClick:()=>Ie(1920,1080),children:"1080p"})]})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Options"}),n.jsxs("div",{className:"flex items-center gap-3 h-8",children:[n.jsxs("label",{className:"flex items-center gap-1.5 text-xs cursor-pointer",children:[n.jsx(ns,{checked:e.headless,onCheckedChange:I=>Se("headless",!!I)}),"Headless"]}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"text-xs text-muted-foreground",children:"×"}),n.jsx(ve,{type:"number",value:e.concurrency,onChange:I=>Se("concurrency",parseInt(I.target.value)||1),className:"h-7 w-12 text-xs text-center",min:1,max:8})]})]})]})]}),n.jsxs(he,{children:[n.jsx(ke,{className:"py-3 px-4",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx($y,{className:"h-4 w-4 text-muted-foreground"}),n.jsxs("div",{children:[n.jsx(be,{className:"text-sm",children:"Visual Diffing"}),n.jsx(at,{className:"text-xs",children:"Compare generated assets against approved baselines"})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-xs text-muted-foreground",children:(B=e.diffing)!=null&&B.enabled?"Enabled":"Disabled"}),n.jsx(ca,{checked:((oe=e.diffing)==null?void 0:oe.enabled)??!1,onCheckedChange:I=>{var ee,pe;return t({...e,diffing:{enabled:I,threshold:((ee=e.diffing)==null?void 0:ee.threshold)??.1,includeAA:((pe=e.diffing)==null?void 0:pe.includeAA)??!1}})}})]})]})}),((se=e.diffing)==null?void 0:se.enabled)&&n.jsx(me,{className:"pt-0 pb-4 px-4 space-y-4 border-t",children:n.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsxs(q,{className:"text-xs text-muted-foreground",children:["Sensitivity Threshold:"," ",((((re=e.diffing)==null?void 0:re.threshold)??.1)*100).toFixed(0),"%"]}),n.jsx("input",{type:"range",min:"0",max:"100",value:(((qe=e.diffing)==null?void 0:qe.threshold)??.1)*100,onChange:I=>t({...e,diffing:{...e.diffing,threshold:parseInt(I.target.value)/100}}),className:"slider-primary w-full",style:{background:Wi((((De=e.diffing)==null?void 0:De.threshold)??.1)*100,0,100)}}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Lower = more sensitive. 10% is recommended."})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Options"}),n.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[n.jsx(ns,{checked:((At=e.diffing)==null?void 0:At.includeAA)??!1,onCheckedChange:I=>t({...e,diffing:{...e.diffing,includeAA:!!I}})}),"Include anti-aliasing in diff"]}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"When disabled, minor rendering differences are ignored."})]})]})})]}),n.jsxs(he,{children:[n.jsx(ke,{className:"py-3 px-4",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(xr,{className:"h-4 w-4 text-muted-foreground"}),n.jsxs("div",{children:[n.jsx(be,{className:"text-sm",children:"Privacy Masking"}),n.jsx(at,{className:"text-xs",children:"Hide or redact sensitive elements before capture"})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-xs text-muted-foreground",children:b.enabled?"Enabled":"Disabled"}),n.jsx(ca,{checked:b.enabled,onCheckedChange:I=>O({...b,enabled:I})})]})]})}),b.enabled&&n.jsxs(me,{className:"pt-0 pb-4 px-4 space-y-4 border-t",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Default Method"}),n.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[n.jsx(js,{selected:b.method==="redact",onClick:()=>O({...b,method:"redact"}),label:"Redact",children:n.jsxs("div",{className:"w-full flex flex-col gap-1.5 px-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[9px] text-muted-foreground",children:"Email"}),n.jsx("div",{className:"w-14 h-2.5 bg-foreground rounded-sm"})]}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[9px] text-muted-foreground",children:"Phone"}),n.jsx("div",{className:"w-10 h-2.5 bg-foreground rounded-sm"})]})]})}),n.jsx(js,{selected:b.method==="blur",onClick:()=>O({...b,method:"blur"}),label:"Blur",children:n.jsxs("div",{className:"w-full flex flex-col gap-1.5 px-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[9px] text-muted-foreground",children:"Email"}),n.jsx("span",{className:"text-[9px] text-muted-foreground select-none",style:{filter:"blur(3px)"},children:"j@acme.co"})]}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[9px] text-muted-foreground",children:"Phone"}),n.jsx("span",{className:"text-[9px] text-muted-foreground select-none",style:{filter:"blur(3px)"},children:"555-0123"})]})]})}),n.jsx(js,{selected:b.method==="hide",onClick:()=>O({...b,method:"hide"}),label:"Hide",children:n.jsxs("div",{className:"w-full flex flex-col gap-1.5 px-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[9px] text-muted-foreground",children:"Email"}),n.jsx("div",{className:"w-14 h-3 border border-dashed border-muted-foreground/30 rounded-sm"})]}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[9px] text-muted-foreground",children:"Phone"}),n.jsx("div",{className:"w-10 h-3 border border-dashed border-muted-foreground/30 rounded-sm"})]})]})}),n.jsx(js,{selected:b.method==="remove",onClick:()=>O({...b,method:"remove"}),label:"Remove",children:n.jsxs("div",{className:"w-full flex flex-col gap-1.5 px-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[9px] text-muted-foreground",children:"Email"}),n.jsx("span",{className:"text-[8px] italic text-muted-foreground/30",children:"removed"})]}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[9px] text-muted-foreground",children:"Phone"}),n.jsx("span",{className:"text-[8px] italic text-muted-foreground/30",children:"removed"})]})]})})]})]}),b.method==="blur"&&n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"bg-muted/50 rounded-lg p-3 flex items-center justify-center",children:n.jsx("span",{className:"text-sm text-muted-foreground font-mono select-none",style:{filter:`blur(${b.blurRadius}px)`},children:"john@acme.com"})}),n.jsxs(q,{className:"text-xs text-muted-foreground",children:["Blur Radius: ",b.blurRadius,"px"]}),n.jsx("input",{type:"range",min:"1",max:"100",value:b.blurRadius,onChange:I=>O({...b,blurRadius:parseInt(I.target.value)}),className:"slider-primary w-full",style:{background:Wi(b.blurRadius,1,100)}})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsxs(q,{className:"text-xs text-muted-foreground",children:["CSS Selectors (",b.selectors.length,")"]}),b.selectors.length>0&&n.jsx("div",{className:"space-y-1",children:b.selectors.map((I,ee)=>{const pe=typeof I=="string"?I:I.selector,Ce=typeof I=="object"?I.method:void 0;return n.jsxs("div",{className:"flex items-center gap-2 bg-muted/50 rounded px-2 py-1",children:[n.jsx("code",{className:"text-xs font-mono flex-1 truncate",children:pe}),Ce&&n.jsx(ue,{variant:"secondary",className:"text-[10px]",children:Ce}),n.jsx(T,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 text-muted-foreground hover:text-destructive",onClick:()=>{const Oe=[...b.selectors];Oe.splice(ee,1),O({...b,selectors:Oe})},children:n.jsx(ln,{className:"h-3 w-3"})})]},ee)})}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx(ve,{value:D,onChange:I=>v(I.target.value),placeholder:".pii-email, [data-sensitive], .user-avatar",className:"h-7 text-xs font-mono",onKeyDown:I=>{I.key==="Enter"&&D.trim()&&(O({...b,selectors:[...b.selectors,D.trim()]}),v(""))}}),n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!D.trim(),onClick:()=>{D.trim()&&(O({...b,selectors:[...b.selectors,D.trim()]}),v(""))},children:[n.jsx(as,{className:"h-3 w-3 mr-1"}),"Add"]})]})]}),n.jsx("div",{className:"pt-2 border-t border-border/20",children:n.jsxs(T,{size:"sm",className:"h-7 text-xs",disabled:L,onClick:async()=>{V(!0);try{const I=await fetch("/api/privacy",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)});if(I.ok)Z({title:"Saved",description:"Privacy configuration updated",variant:"success"});else{const ee=await I.json();Z({title:"Error",description:ee.error||"Failed to save",variant:"destructive"})}}catch{Z({title:"Error",description:"Failed to save privacy config",variant:"destructive"})}finally{V(!1)}},children:[L?n.jsx(_e,{className:"h-3 w-3 animate-spin mr-1"}):n.jsx(Hr,{className:"h-3 w-3 mr-1"}),"Save Privacy Config"]})})]})]}),n.jsxs(he,{children:[n.jsx(ke,{className:"py-3 px-4",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(ao,{className:"h-4 w-4 text-muted-foreground"}),n.jsxs("div",{children:[n.jsx(be,{className:"text-sm",children:"Style & Framing"}),n.jsx(at,{className:"text-xs",children:"Add frames, shadows, and backgrounds to screenshots"})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-xs text-muted-foreground",children:y.enabled?"Enabled":"Disabled"}),n.jsx(ca,{checked:y.enabled,onCheckedChange:I=>_({...y,enabled:I})})]})]})}),y.enabled&&n.jsxs(me,{className:"pt-0 pb-4 px-4 space-y-4 border-t",children:[n.jsx("div",{className:"space-y-2 pt-3",children:E?n.jsxs("div",{className:`border rounded-md p-2 bg-muted/30 relative ${z?"opacity-50":""}`,children:[n.jsx("img",{src:E,alt:"Style preview",className:"max-w-full h-auto rounded"}),z&&n.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:n.jsx(_e,{className:"h-5 w-5 animate-spin text-primary"})})]}):n.jsxs("div",{className:"rounded-lg border border-border/30 bg-gradient-to-b from-muted/20 to-muted/10 preview-grid-bg flex items-center justify-center relative p-6",style:{minHeight:200},children:[n.jsx("div",{className:"relative overflow-hidden transition-all duration-150",style:{background:y.background,padding:`${Math.min(y.padding,40)*.4}px`,borderRadius:`${y.borderRadius*.5}px`,boxShadow:y.shadow==="small"?"0 1px 2px rgba(0,0,0,0.3)":y.shadow==="medium"?"0 4px 6px -1px rgba(0,0,0,0.3)":y.shadow==="large"?"0 10px 25px -5px rgba(0,0,0,0.4)":"none"},children:n.jsxs("div",{className:"w-64 rounded overflow-hidden",style:{borderRadius:`${Math.max(y.borderRadius*.3,2)}px`},children:[y.frame==="macos"&&n.jsxs("div",{className:"bg-[#2a2a2a] px-2.5 py-1.5 flex items-center gap-1",children:[n.jsx("span",{className:"w-[7px] h-[7px] rounded-full bg-[#ff5f57] inline-block"}),n.jsx("span",{className:"w-[7px] h-[7px] rounded-full bg-[#febc2e] inline-block"}),n.jsx("span",{className:"w-[7px] h-[7px] rounded-full bg-[#28c840] inline-block"})]}),y.frame==="windows"&&n.jsx("div",{className:"bg-[#2a2a2a] px-2 py-1 flex items-center justify-end",children:n.jsxs("span",{className:"text-[8px] text-muted-foreground flex gap-1.5",children:[n.jsx("span",{children:"—"}),n.jsx("span",{children:"□"}),n.jsx("span",{children:"×"})]})}),n.jsxs("div",{className:"bg-[#1e1e2e] p-2.5 space-y-2",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground/20"}),n.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground/20"}),n.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground/20"}),n.jsx("div",{className:"flex-1"}),n.jsx("div",{className:"w-8 h-1.5 rounded bg-muted-foreground/15"})]}),n.jsxs("div",{className:"space-y-1.5 pt-1",children:[n.jsx("div",{className:"w-3/4 h-1.5 rounded bg-muted-foreground/15"}),n.jsx("div",{className:"w-full h-1.5 rounded bg-muted-foreground/10"}),n.jsx("div",{className:"w-5/6 h-1.5 rounded bg-muted-foreground/10"}),n.jsx("div",{className:"w-2/3 h-1.5 rounded bg-muted-foreground/10"})]})]})]})}),z&&n.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/50 rounded-lg",children:n.jsx(_e,{className:"h-5 w-5 animate-spin text-primary"})})]})}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Frame"}),n.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[n.jsx(js,{selected:y.frame==="none",onClick:()=>_({...y,frame:"none"}),label:"None",children:n.jsx("div",{className:"w-full h-10 rounded bg-gradient-to-br from-muted/60 to-muted/30"})}),n.jsx(js,{selected:y.frame==="macos",onClick:()=>_({...y,frame:"macos"}),label:"macOS",children:n.jsxs("div",{className:"w-full rounded overflow-hidden",children:[n.jsxs("div",{className:"bg-[#2a2a2a] px-1.5 py-1 flex items-center gap-[3px]",children:[n.jsx("span",{className:"w-[6px] h-[6px] rounded-full bg-[#ff5f57] inline-block"}),n.jsx("span",{className:"w-[6px] h-[6px] rounded-full bg-[#febc2e] inline-block"}),n.jsx("span",{className:"w-[6px] h-[6px] rounded-full bg-[#28c840] inline-block"})]}),n.jsx("div",{className:"h-6 bg-gradient-to-br from-muted/60 to-muted/30"})]})}),n.jsx(js,{selected:y.frame==="windows",onClick:()=>_({...y,frame:"windows"}),label:"Windows",children:n.jsxs("div",{className:"w-full rounded overflow-hidden",children:[n.jsx("div",{className:"bg-[#2a2a2a] px-1.5 py-1 flex items-center justify-end",children:n.jsxs("span",{className:"text-[9px] text-muted-foreground flex gap-1",children:[n.jsx("span",{children:"—"}),n.jsx("span",{children:"□"}),n.jsx("span",{children:"×"})]})}),n.jsx("div",{className:"h-6 bg-gradient-to-br from-muted/60 to-muted/30"})]})})]})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Shadow"}),n.jsx("div",{className:"grid grid-cols-4 gap-2",children:[{key:"none",label:"None",shadow:"shadow-none"},{key:"small",label:"Small",shadow:"shadow-sm"},{key:"medium",label:"Medium",shadow:"shadow-md"},{key:"large",label:"Large",shadow:"shadow-xl"}].map(({key:I,label:ee,shadow:pe})=>n.jsx(js,{selected:y.shadow===I,onClick:()=>_({...y,shadow:I}),label:ee,children:n.jsx("div",{className:`w-10 h-7 rounded bg-card border border-border/50 ${pe}`})},I))})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsxs(q,{className:"text-xs text-muted-foreground",children:["Padding: ",y.padding,"px"]}),n.jsx("input",{type:"range",min:"0",max:"200",value:y.padding,onChange:I=>_({...y,padding:parseInt(I.target.value)||0}),className:"slider-primary w-full",style:{background:Wi(y.padding,0,200)}})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsxs(q,{className:"text-xs text-muted-foreground",children:["Border Radius: ",y.borderRadius,"px"]}),n.jsx("input",{type:"range",min:"0",max:"50",value:y.borderRadius,onChange:I=>_({...y,borderRadius:parseInt(I.target.value)||0}),className:"slider-primary w-full",style:{background:Wi(y.borderRadius,0,50)}})]})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Background"}),n.jsx("div",{className:"flex gap-2 flex-wrap",children:["transparent","#ffffff","#f5f5f5","#1a1a2e","#0f172a","linear-gradient(135deg, #667eea, #764ba2)","linear-gradient(135deg, #f093fb, #f5576c)","linear-gradient(135deg, #4facfe, #00f2fe)"].map(I=>n.jsx("button",{onClick:()=>_({...y,background:I}),className:`w-8 h-8 rounded-md transition-all duration-150 cursor-pointer shrink-0 hover:scale-110 active:scale-100 ${I==="transparent"?"checkerboard":""} ${y.background===I?"ring-2 ring-primary ring-offset-2 ring-offset-background":"border border-border hover:border-primary/50"}`,style:I!=="transparent"?{background:I}:void 0,title:I},I))}),n.jsx(ve,{value:y.background,onChange:I=>_({...y,background:I.target.value}),placeholder:"transparent, #hex, or linear-gradient(...)",className:"h-7 text-xs font-mono"})]}),n.jsx("div",{className:"pt-2 border-t border-border/20",children:n.jsxs(T,{size:"sm",className:"h-7 text-xs",disabled:F,onClick:async()=>{$(!0);try{const I=await fetch("/api/style",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(y)});if(I.ok)Z({title:"Saved",description:"Style configuration updated",variant:"success"});else{const ee=await I.json();Z({title:"Error",description:ee.error||"Failed to save",variant:"destructive"})}}catch{Z({title:"Error",description:"Failed to save style config",variant:"destructive"})}finally{$(!1)}},children:[F?n.jsx(_e,{className:"h-3 w-3 animate-spin mr-1"}):n.jsx(Hr,{className:"h-3 w-3 mr-1"}),"Save Style Config"]})})]})]}),n.jsxs(he,{children:[n.jsx(ke,{className:"py-3 px-4",children:n.jsx("div",{className:"flex items-center justify-between",children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(oh,{className:"h-4 w-4 text-muted-foreground"}),n.jsxs("div",{children:[n.jsx(be,{className:"text-sm",children:"Viewport Presets"}),n.jsx(at,{className:"text-xs",children:"Device sizes for responsive screenshots"})]})]})})}),n.jsx(me,{className:"pt-0 pb-4 px-4 border-t",children:n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"grid grid-cols-4 gap-2",children:Object.entries(h).filter(([I,ee])=>["desktop","tablet","mobile"].includes(ee.category)).slice(0,8).map(([I,ee])=>{const pe=e.viewport.width===ee.width&&e.viewport.height===ee.height,Ce=ee.category==="mobile"?Xy:ee.category==="tablet"?Zy:oh;return n.jsxs(T,{variant:pe?"default":"outline",size:"sm",className:"h-auto py-2 px-3 flex flex-col items-start",onClick:()=>Ie(ee.width,ee.height),children:[n.jsxs("div",{className:"flex items-center gap-1.5 w-full",children:[n.jsx(Ce,{className:"h-3 w-3"}),n.jsx("span",{className:"text-xs font-medium truncate",children:ee.name})]}),n.jsxs("span",{className:"text-[10px] text-muted-foreground mt-0.5",children:[ee.width,"×",ee.height]})]},I)})}),n.jsxs("div",{className:"flex items-center gap-2 pt-2 border-t",children:[n.jsx(q,{className:"text-xs text-muted-foreground whitespace-nowrap",children:"Custom:"}),n.jsx(ve,{type:"number",value:e.viewport.width,onChange:I=>Ie(parseInt(I.target.value)||1280,e.viewport.height),className:"h-7 w-20 text-xs",placeholder:"Width"}),n.jsx("span",{className:"text-xs text-muted-foreground",children:"×"}),n.jsx(ve,{type:"number",value:e.viewport.height,onChange:I=>Ie(e.viewport.width,parseInt(I.target.value)||720),className:"h-7 w-20 text-xs",placeholder:"Height"}),n.jsx("div",{className:"flex-1"}),n.jsx(q,{className:"text-xs text-muted-foreground",children:"Scale:"}),n.jsxs("select",{value:e.viewport.deviceScaleFactor||2,onChange:I=>t({...e,viewport:{...e.viewport,deviceScaleFactor:parseFloat(I.target.value)}}),className:"h-7 px-2 text-xs border rounded bg-background",children:[n.jsx("option",{value:"1",children:"1x"}),n.jsx("option",{value:"2",children:"2x (Retina)"}),n.jsx("option",{value:"3",children:"3x"})]})]})]})})]}),n.jsxs(he,{children:[n.jsx(ke,{className:"py-3 px-4",children:n.jsx("div",{className:"flex items-center justify-between",children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(zy,{className:"h-4 w-4 text-muted-foreground"}),n.jsxs("div",{children:[n.jsx(be,{className:"text-sm",children:"Output Path Template"}),n.jsx(at,{className:"text-xs",children:"Customize where captured assets are saved"})]})]})})}),n.jsxs(me,{className:"pt-0 pb-4 px-4 border-t space-y-4",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Quick Presets"}),n.jsx("div",{className:"flex flex-wrap gap-1.5",children:J.slice(0,6).map(I=>n.jsx(T,{variant:ge===I.template?"default":"outline",size:"sm",className:"h-6 text-xs px-2",onClick:()=>Re(I.template),title:I.description,children:I.name},I.name))})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Custom Template"}),n.jsxs("div",{className:"relative",children:[n.jsx(ve,{value:ge,onChange:I=>Re(I.target.value),placeholder:"./docs/assets/{{locale}}/{{scenario}}/{{name}}.{{ext}}",className:`h-8 text-sm font-mono pr-8 ${(U==null?void 0:U.valid)===!1?"border-red-500":""}`}),U&&n.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2",children:U.valid?n.jsx("span",{className:"text-green-500 text-xs",children:"✓"}):n.jsx("span",{className:"text-red-500 text-xs",children:"✗"})})]}),(U==null?void 0:U.error)&&n.jsx("p",{className:"text-xs text-red-500",children:U.error}),(U==null?void 0:U.warning)&&n.jsx("p",{className:"text-xs text-yellow-600",children:U.warning})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Available Variables"}),n.jsx("div",{className:"flex flex-wrap gap-1",children:fe.slice(0,12).map(I=>n.jsx(ue,{variant:"secondary",className:"text-[10px] cursor-pointer hover:bg-accent",onClick:()=>Re(ee=>ee+`{{${I.name}}}`),title:I.description,children:`{{${I.name}}}`},I.name))}),n.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Click a variable to insert it into the template"})]})]})]}),n.jsxs(he,{children:[n.jsx(ke,{className:"py-3 px-4",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx(be,{className:"text-sm",children:"Variants"}),n.jsx(at,{className:"text-xs",children:"Configure locales, roles, themes"})]}),n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>u(!0),children:[n.jsx(as,{className:"h-3 w-3 mr-1"}),"Add"]})]})}),n.jsx(me,{className:"p-0",children:Tt.length===0?n.jsxs("div",{className:"py-8 text-center border-t",children:[n.jsx(ur,{className:"h-8 w-8 mx-auto mb-2 opacity-20"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"No variants configured"}),n.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Add locale, role, or theme dimensions"})]}):n.jsxs("div",{className:"flex border-t",children:[n.jsx("div",{className:"w-48 border-r shrink-0",children:Tt.map(I=>{const ee=kt[I],pe=I==="locale"?ur:I==="role"?tm:I==="theme"?Xc:Ia,Ce=Object.keys(ee.options).length;return n.jsxs("button",{onClick:()=>l(I),className:`w-full px-3 py-2 text-left flex items-center gap-2 hover:bg-accent/50 transition-colors ${o===I?"bg-accent":""}`,children:[n.jsx(pe,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium truncate",children:ee.label}),n.jsxs("div",{className:"text-xs text-muted-foreground",children:[Ce," option",Ce!==1?"s":""]})]}),n.jsx(Ps,{className:"h-3.5 w-3.5 opacity-40"})]},I)})}),n.jsx("div",{className:"flex-1 min-w-0",children:Vt&&o?n.jsxs("div",{children:[n.jsxs("div",{className:"px-4 py-3 border-b bg-muted/30 flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"font-medium text-sm",children:Vt.label}),n.jsx("div",{className:"text-xs text-muted-foreground",children:Vt.description||"No description"})]}),n.jsxs("div",{className:"flex gap-1",children:[n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>f(!0),children:[n.jsx(as,{className:"h-3 w-3 mr-1"}),"Option"]}),n.jsx(T,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-destructive hover:text-destructive",onClick:()=>Nt(o),children:n.jsx(ps,{className:"h-3 w-3"})})]})]}),n.jsx("div",{className:"divide-y",children:Object.keys(Vt.options).length===0?n.jsx("div",{className:"py-6 text-center text-muted-foreground text-sm",children:"No options yet. Add one to get started."}):Object.entries(Vt.options).map(([I,ee])=>{var Ce;const pe=((Ce=ee.inject)==null?void 0:Ce[0])||{method:"localStorage",key:"",value:""};return n.jsx("div",{className:"px-4 py-3",children:n.jsxs("div",{className:"flex items-start gap-3",children:[n.jsx("div",{className:"shrink-0 pt-0.5",children:n.jsx(ue,{variant:"secondary",className:"text-xs",children:I})}),n.jsxs("div",{className:"flex-1 space-y-2 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium",children:ee.name}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("select",{value:pe.method,onChange:Oe=>$t(o,I,Oe.target.value,pe.key||"",pe.value||""),className:"h-7 text-xs rounded border bg-background px-2",children:[n.jsx("option",{value:"localStorage",children:"localStorage"}),n.jsx("option",{value:"cookie",children:"cookie"}),n.jsx("option",{value:"urlParam",children:"URL param"}),n.jsx("option",{value:"browser",children:"browser"}),n.jsx("option",{value:"header",children:"header"})]}),n.jsx(ve,{value:pe.key||"",onChange:Oe=>$t(o,I,pe.method,Oe.target.value,pe.value||""),placeholder:"key",className:"h-7 text-xs w-24"}),n.jsx(ve,{value:pe.value||"",onChange:Oe=>$t(o,I,pe.method,pe.key||"",Oe.target.value),placeholder:"value",className:"h-7 text-xs flex-1"})]})]}),n.jsx(T,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>Yt(o,I),children:n.jsx(ln,{className:"h-3 w-3"})})]})},I)})})]}):n.jsx("div",{className:"py-12 text-center text-muted-foreground text-sm",children:"Select a dimension to edit"})})]})})]})]}),n.jsx(st,{open:c,onOpenChange:u,children:n.jsxs(nt,{className:"max-w-sm",children:[n.jsx(Xe,{children:n.jsx(Ze,{children:"Add Variant Dimension"})}),n.jsxs("div",{className:"space-y-4 py-2",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Quick Add"}),n.jsx("div",{className:"grid grid-cols-3 gap-2",children:F1.map(I=>{const ee=kt[I.key],pe=I.icon;return n.jsxs(T,{variant:"outline",size:"sm",disabled:!!ee,onClick:()=>mt(I.key,I.label,I.description),className:"h-auto py-2 flex-col gap-1",children:[n.jsx(pe,{className:"h-4 w-4"}),n.jsx("span",{className:"text-xs",children:I.label})]},I.key)})})]}),n.jsxs("div",{className:"relative",children:[n.jsx("div",{className:"absolute inset-0 flex items-center",children:n.jsx("span",{className:"w-full border-t"})}),n.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:n.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"or custom"})})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs",children:"Custom Dimension Key"}),n.jsx(ve,{value:g,onChange:I=>R(I.target.value),placeholder:"e.g., viewport, env, feature",className:"h-8"})]})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"ghost",size:"sm",onClick:()=>u(!1),children:"Cancel"}),n.jsx(T,{size:"sm",onClick:()=>mt(g,g,""),disabled:!g.trim(),children:"Add"})]})]})}),n.jsx(st,{open:m,onOpenChange:f,children:n.jsxs(nt,{className:"max-w-sm",children:[n.jsx(Xe,{children:n.jsx(Ze,{children:"Add Option"})}),n.jsxs("div",{className:"space-y-3 py-2",children:[n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(q,{className:"text-xs",children:"Option Key"}),n.jsx(ve,{value:k,onChange:I=>C(I.target.value),placeholder:o==="locale"?"e.g., en, ko, ja":o==="role"?"e.g., admin, user":"e.g., light, dark",className:"h-8"})]}),n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(q,{className:"text-xs",children:"Display Name"}),n.jsx(ve,{value:j,onChange:I=>p(I.target.value),placeholder:o==="locale"?"e.g., English, 한국어":o==="role"?"e.g., Administrator":"e.g., Light Mode",className:"h-8"})]})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"ghost",size:"sm",onClick:()=>u(!1),children:"Cancel"}),n.jsx(T,{size:"sm",onClick:()=>o&&Ft(o,k,j),disabled:!k.trim(),children:"Add Option"})]})]})})]})}function V1(){return n.jsx(V0,{children:n.jsx(Ij,{children:n.jsx(yy,{children:n.jsx(c1,{children:n.jsxs("div",{className:"min-h-screen bg-background",children:[n.jsx(U1,{}),n.jsx(d1,{})]})})})})})}function U1(){const e=On(),t=Os(),[s,r]=d.useState("Project"),[i,a]=d.useState(!1),[o,l]=d.useState(!1),[c,u]=d.useState("not-running"),m=d.useRef(null),f=()=>{fetch("/api/status").then(h=>h.json()).then(h=>{var x,w;(x=h.settings)!=null&&x.projectName&&r(h.settings.projectName),a(((w=h.settings)==null?void 0:w.isAuthenticated)||!1)}).catch(()=>{})};d.useEffect(()=>{f()},[]);const g=d.useCallback(()=>{fetch("/api/recorder/check-chrome").then(h=>h.json()).then(h=>{h.chromeAvailable&&h.hasValidTab?u("ready"):h.chromeAvailable?u("no-tabs"):u("not-running")}).catch(()=>u("not-running"))},[]);d.useEffect(()=>(g(),m.current=setInterval(g,12e3),()=>{m.current&&clearInterval(m.current)}),[g]),d.useEffect(()=>{const h=x=>{if((x.metaKey||x.ctrlKey)&&x.key>="1"&&x.key<="9"){x.preventDefault();const w=["/","/recorder","/config"],N=parseInt(x.key)-1;w[N]&&t(w[N])}};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[t]);const R=[{path:"/",label:"Home",icon:My,shortcut:"1"}],k=[{path:"/scenarios",label:"All Scenarios",icon:Rn},{path:"/assets",label:"Assets",icon:fn},{path:"/jobs",label:"Jobs",icon:By}],C=()=>{const h=e.pathname;if(h==="/")return{title:"Overview",breadcrumb:null};if(h.startsWith("/scenarios/"))return{title:h.split("/")[2],breadcrumb:"Scenarios"};if(h.startsWith("/assets/"))return{title:"Asset",breadcrumb:"Assets"};const x=[...R,...k,{path:"/config",label:"Settings"}].find(w=>h===w.path||h.startsWith(w.path+"/"));return{title:(x==null?void 0:x.label)||"Page",breadcrumb:null}},{title:j,breadcrumb:p}=C();return n.jsxs("div",{className:"flex h-screen bg-background",children:[n.jsxs("aside",{className:"w-[200px] border-r border-sidebar-border bg-sidebar-background flex flex-col",children:[n.jsx("div",{className:"h-12 flex items-center px-3 border-b border-sidebar-border",children:n.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[n.jsx("div",{className:"w-6 h-6 rounded-md bg-primary/20 flex items-center justify-center",children:n.jsx(Ty,{className:"h-3.5 w-3.5 text-primary"})}),n.jsx("div",{className:"flex-1 min-w-0",children:n.jsx("p",{className:"text-[13px] font-medium text-sidebar-foreground truncate",children:s})})]})}),n.jsxs("nav",{className:"flex-1 py-2 px-2 space-y-0.5 overflow-y-auto linear-scrollbar",children:[R.map(h=>{const x=h.icon,w=e.pathname===h.path||h.path!=="/"&&e.pathname.startsWith(h.path);return n.jsxs(Kt,{to:h.path,className:Y("group flex items-center gap-2.5 px-2 py-1.5 rounded-md text-[13px] transition-colors",w?"bg-sidebar-accent text-sidebar-foreground":"text-muted-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground"),children:[n.jsx(x,{className:Y("h-4 w-4 shrink-0",w?"text-primary":"text-muted-foreground group-hover:text-sidebar-foreground")}),n.jsx("span",{className:"flex-1",children:h.label}),h.shortcut&&n.jsxs("span",{className:"kbd opacity-0 group-hover:opacity-100 transition-opacity",children:["⌘",h.shortcut]})]},h.path)}),n.jsx("div",{className:"h-px bg-sidebar-border my-2"}),n.jsxs(Kt,{to:"/recorder",className:Y("flex items-center gap-2.5 px-2 py-2 rounded-md text-[13px] transition-colors border",e.pathname==="/recorder"?"bg-primary text-primary-foreground border-primary":"border-primary/30 text-primary hover:bg-primary/10 hover:border-primary/50"),children:[n.jsx(_n,{className:"h-4 w-4 shrink-0"}),n.jsx("span",{className:"flex-1 font-medium",children:"Record New Scenario"})]}),n.jsx("div",{className:"h-px bg-sidebar-border my-2"}),k.map(h=>{const x=h.icon,w=e.pathname.startsWith(h.path);return n.jsxs(Kt,{to:h.path,className:Y("flex items-center gap-2.5 px-2 py-1.5 rounded-md text-[13px] transition-colors",w?"bg-sidebar-accent/50 text-sidebar-foreground":"text-muted-foreground/70 hover:bg-sidebar-accent/30 hover:text-muted-foreground"),children:[n.jsx(x,{className:"h-4 w-4 shrink-0"}),n.jsx("span",{children:h.label})]},h.path)})]}),n.jsxs("div",{className:"p-2 border-t border-sidebar-border space-y-0.5",children:[n.jsxs(Kt,{to:"/config",className:Y("group flex items-center gap-2.5 px-2 py-1.5 rounded-md text-[13px] transition-colors",e.pathname==="/config"?"bg-sidebar-accent text-sidebar-foreground":"text-muted-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground"),children:[n.jsx(Ia,{className:"h-4 w-4 shrink-0"}),n.jsx("span",{className:"flex-1",children:"Settings"}),n.jsx("span",{className:"kbd opacity-0 group-hover:opacity-100 transition-opacity",children:"⌘5"})]}),n.jsxs("button",{onClick:()=>l(!0),className:Y("w-full flex items-center gap-2.5 px-2 py-1.5 rounded-md text-[13px] transition-colors","text-muted-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground"),children:[n.jsx("div",{className:Y("status-dot",i?"status-dot-success":"status-dot-neutral")}),n.jsx("span",{className:"flex-1 text-left",children:i?"Connected":"Not connected"}),!i&&n.jsx(em,{className:"h-3.5 w-3.5 opacity-50"})]}),n.jsxs("button",{onClick:()=>t("/recorder"),className:Y("w-full flex items-center gap-2.5 px-2 py-1.5 rounded-md text-[13px] transition-colors","text-muted-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground"),children:[n.jsx("div",{className:Y("status-dot",c==="ready"?"status-dot-success":c==="no-tabs"?"status-dot-warning":"status-dot-neutral")}),n.jsx("span",{className:"flex-1 text-left",children:c==="ready"?"Chrome ready":c==="no-tabs"?"Chrome: no tabs":"Chrome: not running"}),n.jsx(Yp,{className:"h-3.5 w-3.5 opacity-50"})]})]}),n.jsx(wi,{open:o,onOpenChange:l,onAuthenticated:f})]}),n.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[n.jsxs("header",{className:"h-12 border-b border-border bg-background/50 backdrop-blur-sm flex items-center justify-between px-4",children:[n.jsxs("div",{className:"flex items-center gap-2 text-[13px]",children:[p&&n.jsxs(n.Fragment,{children:[n.jsx(Kt,{to:`/${p.toLowerCase()}`,className:"text-muted-foreground hover:text-foreground transition-colors",children:p}),n.jsx(Ps,{className:"h-3.5 w-3.5 text-muted-foreground/50"})]}),n.jsx("span",{className:"font-medium text-foreground",children:j})]}),n.jsxs("button",{onClick:()=>l(!0),className:"flex items-center gap-2 text-[13px] text-muted-foreground hover:text-foreground transition-colors px-2 py-1 rounded-md hover:bg-sidebar-accent/50",children:[n.jsx("div",{className:Y("w-2 h-2 rounded-full",i?"bg-green-500":"bg-neutral-400")}),n.jsx("span",{children:s})]})]}),n.jsx("main",{className:"flex-1 overflow-auto bg-background linear-scrollbar",children:n.jsxs(uy,{children:[n.jsx(us,{path:"/",element:n.jsx(p1,{})}),n.jsx(us,{path:"/recorder",element:n.jsx(D1,{})}),n.jsx(us,{path:"/connection",element:n.jsx(z1,{})}),n.jsx(us,{path:"/scenarios",element:n.jsx(x1,{})}),n.jsx(us,{path:"/scenarios/:key",element:n.jsx(T1,{})}),n.jsx(us,{path:"/assets",element:n.jsx(O1,{})}),n.jsx(us,{path:"/assets/:scenarioKey/:variationSlug/:captureKey",element:n.jsx(M1,{})}),n.jsx(us,{path:"/jobs",element:n.jsx(L1,{})}),n.jsx(us,{path:"/config",element:n.jsx($1,{})})]})})]})]})}window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{localStorage.getItem("reshot-theme")||(document.documentElement.classList.toggle("dark",e.matches),document.documentElement.style.colorScheme=e.matches?"dark":"light")});Ho.createRoot(document.getElementById("root")).render(n.jsx(Oh.StrictMode,{children:n.jsx(V1,{})}));
507
+ */const l0=H("ZoomOut",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]);function sm(e){var t,s,r="";if(typeof e=="string"||typeof e=="number")r+=e;else if(typeof e=="object")if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(s=sm(e[t]))&&(r&&(r+=" "),r+=s)}else for(s in e)e[s]&&(r&&(r+=" "),r+=s);return r}function nm(){for(var e,t,s=0,r="",i=arguments.length;s<i;s++)(e=arguments[s])&&(t=sm(e))&&(r&&(r+=" "),r+=t);return r}const td="-",c0=e=>{const t=u0(e),{conflictingClassGroups:s,conflictingClassGroupModifiers:r}=e;return{getClassGroupId:o=>{const l=o.split(td);return l[0]===""&&l.length!==1&&l.shift(),rm(l,t)||d0(o)},getConflictingClassGroupIds:(o,l)=>{const c=s[o]||[];return l&&r[o]?[...c,...r[o]]:c}}},rm=(e,t)=>{var o;if(e.length===0)return t.classGroupId;const s=e[0],r=t.nextPart.get(s),i=r?rm(e.slice(1),r):void 0;if(i)return i;if(t.validators.length===0)return;const a=e.join(td);return(o=t.validators.find(({validator:l})=>l(a)))==null?void 0:o.classGroupId},lh=/^\[(.+)\]$/,d0=e=>{if(lh.test(e)){const t=lh.exec(e)[1],s=t==null?void 0:t.substring(0,t.indexOf(":"));if(s)return"arbitrary.."+s}},u0=e=>{const{theme:t,prefix:s}=e,r={nextPart:new Map,validators:[]};return f0(Object.entries(e.classGroups),s).forEach(([a,o])=>{Kl(o,r,a,t)}),r},Kl=(e,t,s,r)=>{e.forEach(i=>{if(typeof i=="string"){const a=i===""?t:ch(t,i);a.classGroupId=s;return}if(typeof i=="function"){if(h0(i)){Kl(i(r),t,s,r);return}t.validators.push({validator:i,classGroupId:s});return}Object.entries(i).forEach(([a,o])=>{Kl(o,ch(t,a),s,r)})})},ch=(e,t)=>{let s=e;return t.split(td).forEach(r=>{s.nextPart.has(r)||s.nextPart.set(r,{nextPart:new Map,validators:[]}),s=s.nextPart.get(r)}),s},h0=e=>e.isThemeGetter,f0=(e,t)=>t?e.map(([s,r])=>{const i=r.map(a=>typeof a=="string"?t+a:typeof a=="object"?Object.fromEntries(Object.entries(a).map(([o,l])=>[t+o,l])):a);return[s,i]}):e,p0=e=>{if(e<1)return{get:()=>{},set:()=>{}};let t=0,s=new Map,r=new Map;const i=(a,o)=>{s.set(a,o),t++,t>e&&(t=0,r=s,s=new Map)};return{get(a){let o=s.get(a);if(o!==void 0)return o;if((o=r.get(a))!==void 0)return i(a,o),o},set(a,o){s.has(a)?s.set(a,o):i(a,o)}}},im="!",m0=e=>{const{separator:t,experimentalParseClassName:s}=e,r=t.length===1,i=t[0],a=t.length,o=l=>{const c=[];let u=0,m=0,f;for(let j=0;j<l.length;j++){let p=l[j];if(u===0){if(p===i&&(r||l.slice(j,j+a)===t)){c.push(l.slice(m,j)),m=j+a;continue}if(p==="/"){f=j;continue}}p==="["?u++:p==="]"&&u--}const g=c.length===0?l:l.substring(m),R=g.startsWith(im),k=R?g.substring(1):g,C=f&&f>m?f-m:void 0;return{modifiers:c,hasImportantModifier:R,baseClassName:k,maybePostfixModifierPosition:C}};return s?l=>s({className:l,parseClassName:o}):o},x0=e=>{if(e.length<=1)return e;const t=[];let s=[];return e.forEach(r=>{r[0]==="["?(t.push(...s.sort(),r),s=[]):s.push(r)}),t.push(...s.sort()),t},g0=e=>({cache:p0(e.cacheSize),parseClassName:m0(e),...c0(e)}),v0=/\s+/,y0=(e,t)=>{const{parseClassName:s,getClassGroupId:r,getConflictingClassGroupIds:i}=t,a=[],o=e.trim().split(v0);let l="";for(let c=o.length-1;c>=0;c-=1){const u=o[c],{modifiers:m,hasImportantModifier:f,baseClassName:g,maybePostfixModifierPosition:R}=s(u);let k=!!R,C=r(k?g.substring(0,R):g);if(!C){if(!k){l=u+(l.length>0?" "+l:l);continue}if(C=r(g),!C){l=u+(l.length>0?" "+l:l);continue}k=!1}const j=x0(m).join(":"),p=f?j+im:j,h=p+C;if(a.includes(h))continue;a.push(h);const x=i(C,k);for(let w=0;w<x.length;++w){const N=x[w];a.push(p+N)}l=u+(l.length>0?" "+l:l)}return l};function j0(){let e=0,t,s,r="";for(;e<arguments.length;)(t=arguments[e++])&&(s=am(t))&&(r&&(r+=" "),r+=s);return r}const am=e=>{if(typeof e=="string")return e;let t,s="";for(let r=0;r<e.length;r++)e[r]&&(t=am(e[r]))&&(s&&(s+=" "),s+=t);return s};function w0(e,...t){let s,r,i,a=o;function o(c){const u=t.reduce((m,f)=>f(m),e());return s=g0(u),r=s.cache.get,i=s.cache.set,a=l,l(c)}function l(c){const u=r(c);if(u)return u;const m=y0(c,s);return i(c,m),m}return function(){return a(j0.apply(null,arguments))}}const ze=e=>{const t=s=>s[e]||[];return t.isThemeGetter=!0,t},om=/^\[(?:([a-z-]+):)?(.+)\]$/i,N0=/^\d+\/\d+$/,k0=new Set(["px","full","screen"]),b0=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,S0=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,C0=/^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/,E0=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,R0=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,ys=e=>er(e)||k0.has(e)||N0.test(e),Ms=e=>gr(e,"length",M0),er=e=>!!e&&!Number.isNaN(Number(e)),Uo=e=>gr(e,"number",er),Er=e=>!!e&&Number.isInteger(Number(e)),_0=e=>e.endsWith("%")&&er(e.slice(0,-1)),xe=e=>om.test(e),Is=e=>b0.test(e),P0=new Set(["length","size","percentage"]),T0=e=>gr(e,P0,lm),A0=e=>gr(e,"position",lm),O0=new Set(["image","url"]),z0=e=>gr(e,O0,D0),L0=e=>gr(e,"",I0),Rr=()=>!0,gr=(e,t,s)=>{const r=om.exec(e);return r?r[1]?typeof t=="string"?r[1]===t:t.has(r[1]):s(r[2]):!1},M0=e=>S0.test(e)&&!C0.test(e),lm=()=>!1,I0=e=>E0.test(e),D0=e=>R0.test(e),F0=()=>{const e=ze("colors"),t=ze("spacing"),s=ze("blur"),r=ze("brightness"),i=ze("borderColor"),a=ze("borderRadius"),o=ze("borderSpacing"),l=ze("borderWidth"),c=ze("contrast"),u=ze("grayscale"),m=ze("hueRotate"),f=ze("invert"),g=ze("gap"),R=ze("gradientColorStops"),k=ze("gradientColorStopPositions"),C=ze("inset"),j=ze("margin"),p=ze("opacity"),h=ze("padding"),x=ze("saturate"),w=ze("scale"),N=ze("sepia"),S=ze("skew"),P=ze("space"),b=ze("translate"),O=()=>["auto","contain","none"],D=()=>["auto","hidden","clip","visible","scroll"],v=()=>["auto",xe,t],L=()=>[xe,t],V=()=>["",ys,Ms],y=()=>["auto",er,xe],_=()=>["bottom","center","left","left-bottom","left-top","right","right-bottom","right-top","top"],F=()=>["solid","dashed","dotted","double","none"],$=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],E=()=>["start","end","center","between","around","evenly","stretch"],A=()=>["","0",xe],z=()=>["auto","avoid","all","avoid-page","page","left","right","column"],W=()=>[er,xe];return{cacheSize:500,separator:":",theme:{colors:[Rr],spacing:[ys,Ms],blur:["none","",Is,xe],brightness:W(),borderColor:[e],borderRadius:["none","","full",Is,xe],borderSpacing:L(),borderWidth:V(),contrast:W(),grayscale:A(),hueRotate:W(),invert:A(),gap:L(),gradientColorStops:[e],gradientColorStopPositions:[_0,Ms],inset:v(),margin:v(),opacity:W(),padding:L(),saturate:W(),scale:W(),sepia:A(),skew:W(),space:L(),translate:L()},classGroups:{aspect:[{aspect:["auto","square","video",xe]}],container:["container"],columns:[{columns:[Is]}],"break-after":[{"break-after":z()}],"break-before":[{"break-before":z()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:[..._(),xe]}],overflow:[{overflow:D()}],"overflow-x":[{"overflow-x":D()}],"overflow-y":[{"overflow-y":D()}],overscroll:[{overscroll:O()}],"overscroll-x":[{"overscroll-x":O()}],"overscroll-y":[{"overscroll-y":O()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:[C]}],"inset-x":[{"inset-x":[C]}],"inset-y":[{"inset-y":[C]}],start:[{start:[C]}],end:[{end:[C]}],top:[{top:[C]}],right:[{right:[C]}],bottom:[{bottom:[C]}],left:[{left:[C]}],visibility:["visible","invisible","collapse"],z:[{z:["auto",Er,xe]}],basis:[{basis:v()}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["wrap","wrap-reverse","nowrap"]}],flex:[{flex:["1","auto","initial","none",xe]}],grow:[{grow:A()}],shrink:[{shrink:A()}],order:[{order:["first","last","none",Er,xe]}],"grid-cols":[{"grid-cols":[Rr]}],"col-start-end":[{col:["auto",{span:["full",Er,xe]},xe]}],"col-start":[{"col-start":y()}],"col-end":[{"col-end":y()}],"grid-rows":[{"grid-rows":[Rr]}],"row-start-end":[{row:["auto",{span:[Er,xe]},xe]}],"row-start":[{"row-start":y()}],"row-end":[{"row-end":y()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":["auto","min","max","fr",xe]}],"auto-rows":[{"auto-rows":["auto","min","max","fr",xe]}],gap:[{gap:[g]}],"gap-x":[{"gap-x":[g]}],"gap-y":[{"gap-y":[g]}],"justify-content":[{justify:["normal",...E()]}],"justify-items":[{"justify-items":["start","end","center","stretch"]}],"justify-self":[{"justify-self":["auto","start","end","center","stretch"]}],"align-content":[{content:["normal",...E(),"baseline"]}],"align-items":[{items:["start","end","center","baseline","stretch"]}],"align-self":[{self:["auto","start","end","center","stretch","baseline"]}],"place-content":[{"place-content":[...E(),"baseline"]}],"place-items":[{"place-items":["start","end","center","baseline","stretch"]}],"place-self":[{"place-self":["auto","start","end","center","stretch"]}],p:[{p:[h]}],px:[{px:[h]}],py:[{py:[h]}],ps:[{ps:[h]}],pe:[{pe:[h]}],pt:[{pt:[h]}],pr:[{pr:[h]}],pb:[{pb:[h]}],pl:[{pl:[h]}],m:[{m:[j]}],mx:[{mx:[j]}],my:[{my:[j]}],ms:[{ms:[j]}],me:[{me:[j]}],mt:[{mt:[j]}],mr:[{mr:[j]}],mb:[{mb:[j]}],ml:[{ml:[j]}],"space-x":[{"space-x":[P]}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":[P]}],"space-y-reverse":["space-y-reverse"],w:[{w:["auto","min","max","fit","svw","lvw","dvw",xe,t]}],"min-w":[{"min-w":[xe,t,"min","max","fit"]}],"max-w":[{"max-w":[xe,t,"none","full","min","max","fit","prose",{screen:[Is]},Is]}],h:[{h:[xe,t,"auto","min","max","fit","svh","lvh","dvh"]}],"min-h":[{"min-h":[xe,t,"min","max","fit","svh","lvh","dvh"]}],"max-h":[{"max-h":[xe,t,"min","max","fit","svh","lvh","dvh"]}],size:[{size:[xe,t,"auto","min","max","fit"]}],"font-size":[{text:["base",Is,Ms]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:["thin","extralight","light","normal","medium","semibold","bold","extrabold","black",Uo]}],"font-family":[{font:[Rr]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:["tighter","tight","normal","wide","wider","widest",xe]}],"line-clamp":[{"line-clamp":["none",er,Uo]}],leading:[{leading:["none","tight","snug","normal","relaxed","loose",ys,xe]}],"list-image":[{"list-image":["none",xe]}],"list-style-type":[{list:["none","disc","decimal",xe]}],"list-style-position":[{list:["inside","outside"]}],"placeholder-color":[{placeholder:[e]}],"placeholder-opacity":[{"placeholder-opacity":[p]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"text-color":[{text:[e]}],"text-opacity":[{"text-opacity":[p]}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...F(),"wavy"]}],"text-decoration-thickness":[{decoration:["auto","from-font",ys,Ms]}],"underline-offset":[{"underline-offset":["auto",ys,xe]}],"text-decoration-color":[{decoration:[e]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:L()}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",xe]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",xe]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-opacity":[{"bg-opacity":[p]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:[..._(),A0]}],"bg-repeat":[{bg:["no-repeat",{repeat:["","x","y","round","space"]}]}],"bg-size":[{bg:["auto","cover","contain",T0]}],"bg-image":[{bg:["none",{"gradient-to":["t","tr","r","br","b","bl","l","tl"]},z0]}],"bg-color":[{bg:[e]}],"gradient-from-pos":[{from:[k]}],"gradient-via-pos":[{via:[k]}],"gradient-to-pos":[{to:[k]}],"gradient-from":[{from:[R]}],"gradient-via":[{via:[R]}],"gradient-to":[{to:[R]}],rounded:[{rounded:[a]}],"rounded-s":[{"rounded-s":[a]}],"rounded-e":[{"rounded-e":[a]}],"rounded-t":[{"rounded-t":[a]}],"rounded-r":[{"rounded-r":[a]}],"rounded-b":[{"rounded-b":[a]}],"rounded-l":[{"rounded-l":[a]}],"rounded-ss":[{"rounded-ss":[a]}],"rounded-se":[{"rounded-se":[a]}],"rounded-ee":[{"rounded-ee":[a]}],"rounded-es":[{"rounded-es":[a]}],"rounded-tl":[{"rounded-tl":[a]}],"rounded-tr":[{"rounded-tr":[a]}],"rounded-br":[{"rounded-br":[a]}],"rounded-bl":[{"rounded-bl":[a]}],"border-w":[{border:[l]}],"border-w-x":[{"border-x":[l]}],"border-w-y":[{"border-y":[l]}],"border-w-s":[{"border-s":[l]}],"border-w-e":[{"border-e":[l]}],"border-w-t":[{"border-t":[l]}],"border-w-r":[{"border-r":[l]}],"border-w-b":[{"border-b":[l]}],"border-w-l":[{"border-l":[l]}],"border-opacity":[{"border-opacity":[p]}],"border-style":[{border:[...F(),"hidden"]}],"divide-x":[{"divide-x":[l]}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":[l]}],"divide-y-reverse":["divide-y-reverse"],"divide-opacity":[{"divide-opacity":[p]}],"divide-style":[{divide:F()}],"border-color":[{border:[i]}],"border-color-x":[{"border-x":[i]}],"border-color-y":[{"border-y":[i]}],"border-color-s":[{"border-s":[i]}],"border-color-e":[{"border-e":[i]}],"border-color-t":[{"border-t":[i]}],"border-color-r":[{"border-r":[i]}],"border-color-b":[{"border-b":[i]}],"border-color-l":[{"border-l":[i]}],"divide-color":[{divide:[i]}],"outline-style":[{outline:["",...F()]}],"outline-offset":[{"outline-offset":[ys,xe]}],"outline-w":[{outline:[ys,Ms]}],"outline-color":[{outline:[e]}],"ring-w":[{ring:V()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:[e]}],"ring-opacity":[{"ring-opacity":[p]}],"ring-offset-w":[{"ring-offset":[ys,Ms]}],"ring-offset-color":[{"ring-offset":[e]}],shadow:[{shadow:["","inner","none",Is,L0]}],"shadow-color":[{shadow:[Rr]}],opacity:[{opacity:[p]}],"mix-blend":[{"mix-blend":[...$(),"plus-lighter","plus-darker"]}],"bg-blend":[{"bg-blend":$()}],filter:[{filter:["","none"]}],blur:[{blur:[s]}],brightness:[{brightness:[r]}],contrast:[{contrast:[c]}],"drop-shadow":[{"drop-shadow":["","none",Is,xe]}],grayscale:[{grayscale:[u]}],"hue-rotate":[{"hue-rotate":[m]}],invert:[{invert:[f]}],saturate:[{saturate:[x]}],sepia:[{sepia:[N]}],"backdrop-filter":[{"backdrop-filter":["","none"]}],"backdrop-blur":[{"backdrop-blur":[s]}],"backdrop-brightness":[{"backdrop-brightness":[r]}],"backdrop-contrast":[{"backdrop-contrast":[c]}],"backdrop-grayscale":[{"backdrop-grayscale":[u]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[m]}],"backdrop-invert":[{"backdrop-invert":[f]}],"backdrop-opacity":[{"backdrop-opacity":[p]}],"backdrop-saturate":[{"backdrop-saturate":[x]}],"backdrop-sepia":[{"backdrop-sepia":[N]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":[o]}],"border-spacing-x":[{"border-spacing-x":[o]}],"border-spacing-y":[{"border-spacing-y":[o]}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["none","all","","colors","opacity","shadow","transform",xe]}],duration:[{duration:W()}],ease:[{ease:["linear","in","out","in-out",xe]}],delay:[{delay:W()}],animate:[{animate:["none","spin","ping","pulse","bounce",xe]}],transform:[{transform:["","gpu","none"]}],scale:[{scale:[w]}],"scale-x":[{"scale-x":[w]}],"scale-y":[{"scale-y":[w]}],rotate:[{rotate:[Er,xe]}],"translate-x":[{"translate-x":[b]}],"translate-y":[{"translate-y":[b]}],"skew-x":[{"skew-x":[S]}],"skew-y":[{"skew-y":[S]}],"transform-origin":[{origin:["center","top","top-right","right","bottom-right","bottom","bottom-left","left","top-left",xe]}],accent:[{accent:["auto",e]}],appearance:[{appearance:["none","auto"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",xe]}],"caret-color":[{caret:[e]}],"pointer-events":[{"pointer-events":["none","auto"]}],resize:[{resize:["none","y","x",""]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scroll-m":[{"scroll-m":L()}],"scroll-mx":[{"scroll-mx":L()}],"scroll-my":[{"scroll-my":L()}],"scroll-ms":[{"scroll-ms":L()}],"scroll-me":[{"scroll-me":L()}],"scroll-mt":[{"scroll-mt":L()}],"scroll-mr":[{"scroll-mr":L()}],"scroll-mb":[{"scroll-mb":L()}],"scroll-ml":[{"scroll-ml":L()}],"scroll-p":[{"scroll-p":L()}],"scroll-px":[{"scroll-px":L()}],"scroll-py":[{"scroll-py":L()}],"scroll-ps":[{"scroll-ps":L()}],"scroll-pe":[{"scroll-pe":L()}],"scroll-pt":[{"scroll-pt":L()}],"scroll-pr":[{"scroll-pr":L()}],"scroll-pb":[{"scroll-pb":L()}],"scroll-pl":[{"scroll-pl":L()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",xe]}],fill:[{fill:[e,"none"]}],"stroke-w":[{stroke:[ys,Ms,Uo]}],stroke:[{stroke:[e,"none"]}],sr:["sr-only","not-sr-only"],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","start","end","top","right","bottom","left"],"inset-x":["right","left"],"inset-y":["top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pt","pr","pb","pl"],px:["pr","pl"],py:["pt","pb"],m:["mx","my","ms","me","mt","mr","mb","ml"],mx:["mr","ml"],my:["mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-s","border-w-e","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-r","border-w-l"],"border-w-y":["border-w-t","border-w-b"],"border-color":["border-color-s","border-color-e","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-r","border-color-l"],"border-color-y":["border-color-t","border-color-b"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-mr","scroll-ml"],"scroll-my":["scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-pr","scroll-pl"],"scroll-py":["scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]}}},$0=w0(F0);function Y(...e){return $0(nm(e))}const cm=d.createContext(void 0);function V0({children:e}){const[t,s]=d.useState([]),r=d.useCallback(a=>{const o=Math.random().toString(36).substring(2,9),l={...a,id:o};s(u=>[...u,l]);const c=a.duration??5e3;c>0&&setTimeout(()=>{s(u=>u.filter(m=>m.id!==o))},c)},[]),i=d.useCallback(a=>{s(o=>o.filter(l=>l.id!==a))},[]);return n.jsxs(cm.Provider,{value:{toasts:t,toast:r,dismiss:i},children:[e,n.jsx(U0,{toasts:t,dismiss:i})]})}function Pt(){const e=d.useContext(cm);if(!e)throw new Error("useToast must be used within ToastProvider");return e}function U0({toasts:e,dismiss:t}){return n.jsx("div",{className:"fixed bottom-0 right-0 z-[100] flex flex-col-reverse gap-2 p-4 max-w-sm w-full",children:e.map(s=>n.jsx(B0,{toast:s,onDismiss:()=>t(s.id)},s.id))})}function B0({toast:e,onDismiss:t}){const s={default:"bg-background border-border",destructive:"bg-destructive text-destructive-foreground border-destructive",success:"bg-green-600 text-white border-green-700"},r={default:"text-muted-foreground",destructive:"text-destructive-foreground/90",success:"text-white/90"},i={default:"text-muted-foreground hover:text-foreground",destructive:"text-destructive-foreground hover:text-destructive-foreground/80",success:"text-white/70 hover:text-white"},a=e.variant||"default";return n.jsx("div",{className:Y("rounded-lg border p-4 shadow-lg transition-all",s[a]),children:n.jsxs("div",{className:"flex items-start justify-between gap-4",children:[n.jsxs("div",{className:"flex-1",children:[e.title&&n.jsx("div",{className:"font-semibold",children:e.title}),e.description&&n.jsx("div",{className:Y("text-sm",r[a]),children:e.description})]}),n.jsx("button",{onClick:t,className:i[a],children:"×"})]})})}const vs=Object.create(null);vs.open="0";vs.close="1";vs.ping="2";vs.pong="3";vs.message="4";vs.upgrade="5";vs.noop="6";const ia=Object.create(null);Object.keys(vs).forEach(e=>{ia[vs[e]]=e});const Hl={type:"error",data:"parser error"},dm=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",um=typeof ArrayBuffer=="function",hm=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,sd=({type:e,data:t},s,r)=>dm&&t instanceof Blob?s?r(t):dh(t,r):um&&(t instanceof ArrayBuffer||hm(t))?s?r(t):dh(new Blob([t]),r):r(vs[e]+(t||"")),dh=(e,t)=>{const s=new FileReader;return s.onload=function(){const r=s.result.split(",")[1];t("b"+(r||""))},s.readAsDataURL(e)};function uh(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}let Bo;function W0(e,t){if(dm&&e.data instanceof Blob)return e.data.arrayBuffer().then(uh).then(t);if(um&&(e.data instanceof ArrayBuffer||hm(e.data)))return t(uh(e.data));sd(e,!1,s=>{Bo||(Bo=new TextEncoder),t(Bo.encode(s))})}const hh="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Lr=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let e=0;e<hh.length;e++)Lr[hh.charCodeAt(e)]=e;const K0=e=>{let t=e.length*.75,s=e.length,r,i=0,a,o,l,c;e[e.length-1]==="="&&(t--,e[e.length-2]==="="&&t--);const u=new ArrayBuffer(t),m=new Uint8Array(u);for(r=0;r<s;r+=4)a=Lr[e.charCodeAt(r)],o=Lr[e.charCodeAt(r+1)],l=Lr[e.charCodeAt(r+2)],c=Lr[e.charCodeAt(r+3)],m[i++]=a<<2|o>>4,m[i++]=(o&15)<<4|l>>2,m[i++]=(l&3)<<6|c&63;return u},H0=typeof ArrayBuffer=="function",nd=(e,t)=>{if(typeof e!="string")return{type:"message",data:fm(e,t)};const s=e.charAt(0);return s==="b"?{type:"message",data:J0(e.substring(1),t)}:ia[s]?e.length>1?{type:ia[s],data:e.substring(1)}:{type:ia[s]}:Hl},J0=(e,t)=>{if(H0){const s=K0(e);return fm(s,t)}else return{base64:!0,data:e}},fm=(e,t)=>{switch(t){case"blob":return e instanceof Blob?e:new Blob([e]);case"arraybuffer":default:return e instanceof ArrayBuffer?e:e.buffer}},pm="",q0=(e,t)=>{const s=e.length,r=new Array(s);let i=0;e.forEach((a,o)=>{sd(a,!1,l=>{r[o]=l,++i===s&&t(r.join(pm))})})},G0=(e,t)=>{const s=e.split(pm),r=[];for(let i=0;i<s.length;i++){const a=nd(s[i],t);if(r.push(a),a.type==="error")break}return r};function Q0(){return new TransformStream({transform(e,t){W0(e,s=>{const r=s.length;let i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);const a=new DataView(i.buffer);a.setUint8(0,126),a.setUint16(1,r)}else{i=new Uint8Array(9);const a=new DataView(i.buffer);a.setUint8(0,127),a.setBigUint64(1,BigInt(r))}e.data&&typeof e.data!="string"&&(i[0]|=128),t.enqueue(i),t.enqueue(s)})}})}let Wo;function Vi(e){return e.reduce((t,s)=>t+s.length,0)}function Ui(e,t){if(e[0].length===t)return e.shift();const s=new Uint8Array(t);let r=0;for(let i=0;i<t;i++)s[i]=e[0][r++],r===e[0].length&&(e.shift(),r=0);return e.length&&r<e[0].length&&(e[0]=e[0].slice(r)),s}function Y0(e,t){Wo||(Wo=new TextDecoder);const s=[];let r=0,i=-1,a=!1;return new TransformStream({transform(o,l){for(s.push(o);;){if(r===0){if(Vi(s)<1)break;const c=Ui(s,1);a=(c[0]&128)===128,i=c[0]&127,i<126?r=3:i===126?r=1:r=2}else if(r===1){if(Vi(s)<2)break;const c=Ui(s,2);i=new DataView(c.buffer,c.byteOffset,c.length).getUint16(0),r=3}else if(r===2){if(Vi(s)<8)break;const c=Ui(s,8),u=new DataView(c.buffer,c.byteOffset,c.length),m=u.getUint32(0);if(m>Math.pow(2,21)-1){l.enqueue(Hl);break}i=m*Math.pow(2,32)+u.getUint32(4),r=3}else{if(Vi(s)<i)break;const c=Ui(s,i);l.enqueue(nd(a?c:Wo.decode(c),t)),r=0}if(i===0||i>e){l.enqueue(Hl);break}}}})}const mm=4;function He(e){if(e)return X0(e)}function X0(e){for(var t in He.prototype)e[t]=He.prototype[t];return e}He.prototype.on=He.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this};He.prototype.once=function(e,t){function s(){this.off(e,s),t.apply(this,arguments)}return s.fn=t,this.on(e,s),this};He.prototype.off=He.prototype.removeListener=He.prototype.removeAllListeners=He.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var s=this._callbacks["$"+e];if(!s)return this;if(arguments.length==1)return delete this._callbacks["$"+e],this;for(var r,i=0;i<s.length;i++)if(r=s[i],r===t||r.fn===t){s.splice(i,1);break}return s.length===0&&delete this._callbacks["$"+e],this};He.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),s=this._callbacks["$"+e],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(s){s=s.slice(0);for(var r=0,i=s.length;r<i;++r)s[r].apply(this,t)}return this};He.prototype.emitReserved=He.prototype.emit;He.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]};He.prototype.hasListeners=function(e){return!!this.listeners(e).length};const oo=typeof Promise=="function"&&typeof Promise.resolve=="function"?t=>Promise.resolve().then(t):(t,s)=>s(t,0),Wt=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),Z0="arraybuffer";function xm(e,...t){return t.reduce((s,r)=>(e.hasOwnProperty(r)&&(s[r]=e[r]),s),{})}const ej=Wt.setTimeout,tj=Wt.clearTimeout;function lo(e,t){t.useNativeTimers?(e.setTimeoutFn=ej.bind(Wt),e.clearTimeoutFn=tj.bind(Wt)):(e.setTimeoutFn=Wt.setTimeout.bind(Wt),e.clearTimeoutFn=Wt.clearTimeout.bind(Wt))}const sj=1.33;function nj(e){return typeof e=="string"?rj(e):Math.ceil((e.byteLength||e.size)*sj)}function rj(e){let t=0,s=0;for(let r=0,i=e.length;r<i;r++)t=e.charCodeAt(r),t<128?s+=1:t<2048?s+=2:t<55296||t>=57344?s+=3:(r++,s+=4);return s}function gm(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function ij(e){let t="";for(let s in e)e.hasOwnProperty(s)&&(t.length&&(t+="&"),t+=encodeURIComponent(s)+"="+encodeURIComponent(e[s]));return t}function aj(e){let t={},s=e.split("&");for(let r=0,i=s.length;r<i;r++){let a=s[r].split("=");t[decodeURIComponent(a[0])]=decodeURIComponent(a[1])}return t}class oj extends Error{constructor(t,s,r){super(t),this.description=s,this.context=r,this.type="TransportError"}}class rd extends He{constructor(t){super(),this.writable=!1,lo(this,t),this.opts=t,this.query=t.query,this.socket=t.socket,this.supportsBinary=!t.forceBase64}onError(t,s,r){return super.emitReserved("error",new oj(t,s,r)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(t){this.readyState==="open"&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const s=nd(t,this.socket.binaryType);this.onPacket(s)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}createUri(t,s={}){return t+"://"+this._hostname()+this._port()+this.opts.path+this._query(s)}_hostname(){const t=this.opts.hostname;return t.indexOf(":")===-1?t:"["+t+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(t){const s=ij(t);return s.length?"?"+s:""}}class lj extends rd{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(t){this.readyState="pausing";const s=()=>{this.readyState="paused",t()};if(this._polling||!this.writable){let r=0;this._polling&&(r++,this.once("pollComplete",function(){--r||s()})),this.writable||(r++,this.once("drain",function(){--r||s()}))}else s()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){const s=r=>{if(this.readyState==="opening"&&r.type==="open"&&this.onOpen(),r.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(r)};G0(t,this.socket.binaryType).forEach(s),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this._poll())}doClose(){const t=()=>{this.write([{type:"close"}])};this.readyState==="open"?t():this.once("open",t)}write(t){this.writable=!1,q0(t,s=>{this.doWrite(s,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const t=this.opts.secure?"https":"http",s=this.query||{};return this.opts.timestampRequests!==!1&&(s[this.opts.timestampParam]=gm()),!this.supportsBinary&&!s.sid&&(s.b64=1),this.createUri(t,s)}}let vm=!1;try{vm=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const cj=vm;function dj(){}class uj extends lj{constructor(t){if(super(t),typeof location<"u"){const s=location.protocol==="https:";let r=location.port;r||(r=s?"443":"80"),this.xd=typeof location<"u"&&t.hostname!==location.hostname||r!==t.port}}doWrite(t,s){const r=this.request({method:"POST",data:t});r.on("success",s),r.on("error",(i,a)=>{this.onError("xhr post error",i,a)})}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",(s,r)=>{this.onError("xhr poll error",s,r)}),this.pollXhr=t}}class gs extends He{constructor(t,s,r){super(),this.createRequest=t,lo(this,r),this._opts=r,this._method=r.method||"GET",this._uri=s,this._data=r.data!==void 0?r.data:null,this._create()}_create(){var t;const s=xm(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");s.xdomain=!!this._opts.xd;const r=this._xhr=this.createRequest(s);try{r.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let i in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(i)&&r.setRequestHeader(i,this._opts.extraHeaders[i])}}catch{}if(this._method==="POST")try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{r.setRequestHeader("Accept","*/*")}catch{}(t=this._opts.cookieJar)===null||t===void 0||t.addCookies(r),"withCredentials"in r&&(r.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(r.timeout=this._opts.requestTimeout),r.onreadystatechange=()=>{var i;r.readyState===3&&((i=this._opts.cookieJar)===null||i===void 0||i.parseCookies(r.getResponseHeader("set-cookie"))),r.readyState===4&&(r.status===200||r.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof r.status=="number"?r.status:0)},0))},r.send(this._data)}catch(i){this.setTimeoutFn(()=>{this._onError(i)},0);return}typeof document<"u"&&(this._index=gs.requestsCount++,gs.requests[this._index]=this)}_onError(t){this.emitReserved("error",t,this._xhr),this._cleanup(!0)}_cleanup(t){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=dj,t)try{this._xhr.abort()}catch{}typeof document<"u"&&delete gs.requests[this._index],this._xhr=null}}_onLoad(){const t=this._xhr.responseText;t!==null&&(this.emitReserved("data",t),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}gs.requestsCount=0;gs.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",fh);else if(typeof addEventListener=="function"){const e="onpagehide"in Wt?"pagehide":"unload";addEventListener(e,fh,!1)}}function fh(){for(let e in gs.requests)gs.requests.hasOwnProperty(e)&&gs.requests[e].abort()}const hj=function(){const e=ym({xdomain:!1});return e&&e.responseType!==null}();class fj extends uj{constructor(t){super(t);const s=t&&t.forceBase64;this.supportsBinary=hj&&!s}request(t={}){return Object.assign(t,{xd:this.xd},this.opts),new gs(ym,this.uri(),t)}}function ym(e){const t=e.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!t||cj))return new XMLHttpRequest}catch{}if(!t)try{return new Wt[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}const jm=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class pj extends rd{get name(){return"websocket"}doOpen(){const t=this.uri(),s=this.opts.protocols,r=jm?{}:xm(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,s,r)}catch(i){return this.emitReserved("error",i)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let s=0;s<t.length;s++){const r=t[s],i=s===t.length-1;sd(r,this.supportsBinary,a=>{try{this.doWrite(r,a)}catch{}i&&oo(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",s=this.query||{};return this.opts.timestampRequests&&(s[this.opts.timestampParam]=gm()),this.supportsBinary||(s.b64=1),this.createUri(t,s)}}const Ko=Wt.WebSocket||Wt.MozWebSocket;class mj extends pj{createSocket(t,s,r){return jm?new Ko(t,s,r):s?new Ko(t,s):new Ko(t)}doWrite(t,s){this.ws.send(s)}}class xj extends rd{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(t){return this.emitReserved("error",t)}this._transport.closed.then(()=>{this.onClose()}).catch(t=>{this.onError("webtransport error",t)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(t=>{const s=Y0(Number.MAX_SAFE_INTEGER,this.socket.binaryType),r=t.readable.pipeThrough(s).getReader(),i=Q0();i.readable.pipeTo(t.writable),this._writer=i.writable.getWriter();const a=()=>{r.read().then(({done:l,value:c})=>{l||(this.onPacket(c),a())}).catch(l=>{})};a();const o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this._writer.write(o).then(()=>this.onOpen())})})}write(t){this.writable=!1;for(let s=0;s<t.length;s++){const r=t[s],i=s===t.length-1;this._writer.write(r).then(()=>{i&&oo(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var t;(t=this._transport)===null||t===void 0||t.close()}}const gj={websocket:mj,webtransport:xj,polling:fj},vj=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,yj=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function Jl(e){if(e.length>8e3)throw"URI too long";const t=e,s=e.indexOf("["),r=e.indexOf("]");s!=-1&&r!=-1&&(e=e.substring(0,s)+e.substring(s,r).replace(/:/g,";")+e.substring(r,e.length));let i=vj.exec(e||""),a={},o=14;for(;o--;)a[yj[o]]=i[o]||"";return s!=-1&&r!=-1&&(a.source=t,a.host=a.host.substring(1,a.host.length-1).replace(/;/g,":"),a.authority=a.authority.replace("[","").replace("]","").replace(/;/g,":"),a.ipv6uri=!0),a.pathNames=jj(a,a.path),a.queryKey=wj(a,a.query),a}function jj(e,t){const s=/\/{2,9}/g,r=t.replace(s,"/").split("/");return(t.slice(0,1)=="/"||t.length===0)&&r.splice(0,1),t.slice(-1)=="/"&&r.splice(r.length-1,1),r}function wj(e,t){const s={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(r,i,a){i&&(s[i]=a)}),s}const ql=typeof addEventListener=="function"&&typeof removeEventListener=="function",aa=[];ql&&addEventListener("offline",()=>{aa.forEach(e=>e())},!1);class en extends He{constructor(t,s){if(super(),this.binaryType=Z0,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,t&&typeof t=="object"&&(s=t,t=null),t){const r=Jl(t);s.hostname=r.host,s.secure=r.protocol==="https"||r.protocol==="wss",s.port=r.port,r.query&&(s.query=r.query)}else s.host&&(s.hostname=Jl(s.host).host);lo(this,s),this.secure=s.secure!=null?s.secure:typeof location<"u"&&location.protocol==="https:",s.hostname&&!s.port&&(s.port=this.secure?"443":"80"),this.hostname=s.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=s.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},s.transports.forEach(r=>{const i=r.prototype.name;this.transports.push(i),this._transportsByName[i]=r}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},s),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=aj(this.opts.query)),ql&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},aa.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(t){const s=Object.assign({},this.opts.query);s.EIO=mm,s.transport=t,this.id&&(s.sid=this.id);const r=Object.assign({},this.opts,{query:s,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this._transportsByName[t](r)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}const t=this.opts.rememberUpgrade&&en.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";const s=this.createTransport(t);s.open(),this.setTransport(s)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",s=>this._onClose("transport close",s))}onOpen(){this.readyState="open",en.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(t){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const s=new Error("server error");s.code=t.data,this._onError(s);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data);break}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this._pingInterval=t.pingInterval,this._pingTimeout=t.pingTimeout,this._maxPayload=t.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const t=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+t,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},t),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this._getWritablePackets();this.transport.send(t),this._prevBufferLen=t.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let s=1;for(let r=0;r<this.writeBuffer.length;r++){const i=this.writeBuffer[r].data;if(i&&(s+=nj(i)),r>0&&s>this._maxPayload)return this.writeBuffer.slice(0,r);s+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const t=Date.now()>this._pingTimeoutTime;return t&&(this._pingTimeoutTime=0,oo(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),t}write(t,s,r){return this._sendPacket("message",t,s,r),this}send(t,s,r){return this._sendPacket("message",t,s,r),this}_sendPacket(t,s,r,i){if(typeof s=="function"&&(i=s,s=void 0),typeof r=="function"&&(i=r,r=null),this.readyState==="closing"||this.readyState==="closed")return;r=r||{},r.compress=r.compress!==!1;const a={type:t,data:s,options:r};this.emitReserved("packetCreate",a),this.writeBuffer.push(a),i&&this.once("flush",i),this.flush()}close(){const t=()=>{this._onClose("forced close"),this.transport.close()},s=()=>{this.off("upgrade",s),this.off("upgradeError",s),t()},r=()=>{this.once("upgrade",s),this.once("upgradeError",s)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?r():t()}):this.upgrading?r():t()),this}_onError(t){if(en.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return this.transports.shift(),this._open();this.emitReserved("error",t),this._onClose("transport error",t)}_onClose(t,s){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),ql&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const r=aa.indexOf(this._offlineEventListener);r!==-1&&aa.splice(r,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,s),this.writeBuffer=[],this._prevBufferLen=0}}}en.protocol=mm;class Nj extends en{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade)for(let t=0;t<this._upgrades.length;t++)this._probe(this._upgrades[t])}_probe(t){let s=this.createTransport(t),r=!1;en.priorWebsocketSuccess=!1;const i=()=>{r||(s.send([{type:"ping",data:"probe"}]),s.once("packet",f=>{if(!r)if(f.type==="pong"&&f.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",s),!s)return;en.priorWebsocketSuccess=s.name==="websocket",this.transport.pause(()=>{r||this.readyState!=="closed"&&(m(),this.setTransport(s),s.send([{type:"upgrade"}]),this.emitReserved("upgrade",s),s=null,this.upgrading=!1,this.flush())})}else{const g=new Error("probe error");g.transport=s.name,this.emitReserved("upgradeError",g)}}))};function a(){r||(r=!0,m(),s.close(),s=null)}const o=f=>{const g=new Error("probe error: "+f);g.transport=s.name,a(),this.emitReserved("upgradeError",g)};function l(){o("transport closed")}function c(){o("socket closed")}function u(f){s&&f.name!==s.name&&a()}const m=()=>{s.removeListener("open",i),s.removeListener("error",o),s.removeListener("close",l),this.off("close",c),this.off("upgrading",u)};s.once("open",i),s.once("error",o),s.once("close",l),this.once("close",c),this.once("upgrading",u),this._upgrades.indexOf("webtransport")!==-1&&t!=="webtransport"?this.setTimeoutFn(()=>{r||s.open()},200):s.open()}onHandshake(t){this._upgrades=this._filterUpgrades(t.upgrades),super.onHandshake(t)}_filterUpgrades(t){const s=[];for(let r=0;r<t.length;r++)~this.transports.indexOf(t[r])&&s.push(t[r]);return s}}let kj=class extends Nj{constructor(t,s={}){const r=typeof t=="object"?t:s;(!r.transports||r.transports&&typeof r.transports[0]=="string")&&(r.transports=(r.transports||["polling","websocket","webtransport"]).map(i=>gj[i]).filter(i=>!!i)),super(t,r)}};function bj(e,t="",s){let r=e;s=s||typeof location<"u"&&location,e==null&&(e=s.protocol+"//"+s.host),typeof e=="string"&&(e.charAt(0)==="/"&&(e.charAt(1)==="/"?e=s.protocol+e:e=s.host+e),/^(https?|wss?):\/\//.test(e)||(typeof s<"u"?e=s.protocol+"//"+e:e="https://"+e),r=Jl(e)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port="80":/^(http|ws)s$/.test(r.protocol)&&(r.port="443")),r.path=r.path||"/";const a=r.host.indexOf(":")!==-1?"["+r.host+"]":r.host;return r.id=r.protocol+"://"+a+":"+r.port+t,r.href=r.protocol+"://"+a+(s&&s.port===r.port?"":":"+r.port),r}const Sj=typeof ArrayBuffer=="function",Cj=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,wm=Object.prototype.toString,Ej=typeof Blob=="function"||typeof Blob<"u"&&wm.call(Blob)==="[object BlobConstructor]",Rj=typeof File=="function"||typeof File<"u"&&wm.call(File)==="[object FileConstructor]";function id(e){return Sj&&(e instanceof ArrayBuffer||Cj(e))||Ej&&e instanceof Blob||Rj&&e instanceof File}function oa(e,t){if(!e||typeof e!="object")return!1;if(Array.isArray(e)){for(let s=0,r=e.length;s<r;s++)if(oa(e[s]))return!0;return!1}if(id(e))return!0;if(e.toJSON&&typeof e.toJSON=="function"&&arguments.length===1)return oa(e.toJSON(),!0);for(const s in e)if(Object.prototype.hasOwnProperty.call(e,s)&&oa(e[s]))return!0;return!1}function _j(e){const t=[],s=e.data,r=e;return r.data=Gl(s,t),r.attachments=t.length,{packet:r,buffers:t}}function Gl(e,t){if(!e)return e;if(id(e)){const s={_placeholder:!0,num:t.length};return t.push(e),s}else if(Array.isArray(e)){const s=new Array(e.length);for(let r=0;r<e.length;r++)s[r]=Gl(e[r],t);return s}else if(typeof e=="object"&&!(e instanceof Date)){const s={};for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(s[r]=Gl(e[r],t));return s}return e}function Pj(e,t){return e.data=Ql(e.data,t),delete e.attachments,e}function Ql(e,t){if(!e)return e;if(e&&e._placeholder===!0){if(typeof e.num=="number"&&e.num>=0&&e.num<t.length)return t[e.num];throw new Error("illegal attachments")}else if(Array.isArray(e))for(let s=0;s<e.length;s++)e[s]=Ql(e[s],t);else if(typeof e=="object")for(const s in e)Object.prototype.hasOwnProperty.call(e,s)&&(e[s]=Ql(e[s],t));return e}const Tj=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],Aj=5;var Ne;(function(e){e[e.CONNECT=0]="CONNECT",e[e.DISCONNECT=1]="DISCONNECT",e[e.EVENT=2]="EVENT",e[e.ACK=3]="ACK",e[e.CONNECT_ERROR=4]="CONNECT_ERROR",e[e.BINARY_EVENT=5]="BINARY_EVENT",e[e.BINARY_ACK=6]="BINARY_ACK"})(Ne||(Ne={}));class Oj{constructor(t){this.replacer=t}encode(t){return(t.type===Ne.EVENT||t.type===Ne.ACK)&&oa(t)?this.encodeAsBinary({type:t.type===Ne.EVENT?Ne.BINARY_EVENT:Ne.BINARY_ACK,nsp:t.nsp,data:t.data,id:t.id}):[this.encodeAsString(t)]}encodeAsString(t){let s=""+t.type;return(t.type===Ne.BINARY_EVENT||t.type===Ne.BINARY_ACK)&&(s+=t.attachments+"-"),t.nsp&&t.nsp!=="/"&&(s+=t.nsp+","),t.id!=null&&(s+=t.id),t.data!=null&&(s+=JSON.stringify(t.data,this.replacer)),s}encodeAsBinary(t){const s=_j(t),r=this.encodeAsString(s.packet),i=s.buffers;return i.unshift(r),i}}function ph(e){return Object.prototype.toString.call(e)==="[object Object]"}class ad extends He{constructor(t){super(),this.reviver=t}add(t){let s;if(typeof t=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");s=this.decodeString(t);const r=s.type===Ne.BINARY_EVENT;r||s.type===Ne.BINARY_ACK?(s.type=r?Ne.EVENT:Ne.ACK,this.reconstructor=new zj(s),s.attachments===0&&super.emitReserved("decoded",s)):super.emitReserved("decoded",s)}else if(id(t)||t.base64)if(this.reconstructor)s=this.reconstructor.takeBinaryData(t),s&&(this.reconstructor=null,super.emitReserved("decoded",s));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+t)}decodeString(t){let s=0;const r={type:Number(t.charAt(0))};if(Ne[r.type]===void 0)throw new Error("unknown packet type "+r.type);if(r.type===Ne.BINARY_EVENT||r.type===Ne.BINARY_ACK){const a=s+1;for(;t.charAt(++s)!=="-"&&s!=t.length;);const o=t.substring(a,s);if(o!=Number(o)||t.charAt(s)!=="-")throw new Error("Illegal attachments");r.attachments=Number(o)}if(t.charAt(s+1)==="/"){const a=s+1;for(;++s&&!(t.charAt(s)===","||s===t.length););r.nsp=t.substring(a,s)}else r.nsp="/";const i=t.charAt(s+1);if(i!==""&&Number(i)==i){const a=s+1;for(;++s;){const o=t.charAt(s);if(o==null||Number(o)!=o){--s;break}if(s===t.length)break}r.id=Number(t.substring(a,s+1))}if(t.charAt(++s)){const a=this.tryParse(t.substr(s));if(ad.isPayloadValid(r.type,a))r.data=a;else throw new Error("invalid payload")}return r}tryParse(t){try{return JSON.parse(t,this.reviver)}catch{return!1}}static isPayloadValid(t,s){switch(t){case Ne.CONNECT:return ph(s);case Ne.DISCONNECT:return s===void 0;case Ne.CONNECT_ERROR:return typeof s=="string"||ph(s);case Ne.EVENT:case Ne.BINARY_EVENT:return Array.isArray(s)&&(typeof s[0]=="number"||typeof s[0]=="string"&&Tj.indexOf(s[0])===-1);case Ne.ACK:case Ne.BINARY_ACK:return Array.isArray(s)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class zj{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){const s=Pj(this.reconPack,this.buffers);return this.finishedReconstruction(),s}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const Lj=Object.freeze(Object.defineProperty({__proto__:null,Decoder:ad,Encoder:Oj,get PacketType(){return Ne},protocol:Aj},Symbol.toStringTag,{value:"Module"}));function ts(e,t,s){return e.on(t,s),function(){e.off(t,s)}}const Mj=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Nm extends He{constructor(t,s,r){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=t,this.nsp=s,r&&r.auth&&(this.auth=r.auth),this._opts=Object.assign({},r),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const t=this.io;this.subs=[ts(t,"open",this.onopen.bind(this)),ts(t,"packet",this.onpacket.bind(this)),ts(t,"error",this.onerror.bind(this)),ts(t,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...t){return t.unshift("message"),this.emit.apply(this,t),this}emit(t,...s){var r,i,a;if(Mj.hasOwnProperty(t))throw new Error('"'+t.toString()+'" is a reserved event name');if(s.unshift(t),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(s),this;const o={type:Ne.EVENT,data:s};if(o.options={},o.options.compress=this.flags.compress!==!1,typeof s[s.length-1]=="function"){const m=this.ids++,f=s.pop();this._registerAckCallback(m,f),o.id=m}const l=(i=(r=this.io.engine)===null||r===void 0?void 0:r.transport)===null||i===void 0?void 0:i.writable,c=this.connected&&!(!((a=this.io.engine)===null||a===void 0)&&a._hasPingExpired());return this.flags.volatile&&!l||(c?(this.notifyOutgoingListeners(o),this.packet(o)):this.sendBuffer.push(o)),this.flags={},this}_registerAckCallback(t,s){var r;const i=(r=this.flags.timeout)!==null&&r!==void 0?r:this._opts.ackTimeout;if(i===void 0){this.acks[t]=s;return}const a=this.io.setTimeoutFn(()=>{delete this.acks[t];for(let l=0;l<this.sendBuffer.length;l++)this.sendBuffer[l].id===t&&this.sendBuffer.splice(l,1);s.call(this,new Error("operation has timed out"))},i),o=(...l)=>{this.io.clearTimeoutFn(a),s.apply(this,l)};o.withError=!0,this.acks[t]=o}emitWithAck(t,...s){return new Promise((r,i)=>{const a=(o,l)=>o?i(o):r(l);a.withError=!0,s.push(a),this.emit(t,...s)})}_addToQueue(t){let s;typeof t[t.length-1]=="function"&&(s=t.pop());const r={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push((i,...a)=>r!==this._queue[0]?void 0:(i!==null?r.tryCount>this._opts.retries&&(this._queue.shift(),s&&s(i)):(this._queue.shift(),s&&s(null,...a)),r.pending=!1,this._drainQueue())),this._queue.push(r),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||this._queue.length===0)return;const s=this._queue[0];s.pending&&!t||(s.pending=!0,s.tryCount++,this.flags=s.flags,this.emit.apply(this,s.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){typeof this.auth=="function"?this.auth(t=>{this._sendConnectPacket(t)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:Ne.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,s){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,s),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(t=>{if(!this.sendBuffer.some(r=>String(r.id)===t)){const r=this.acks[t];delete this.acks[t],r.withError&&r.call(this,new Error("socket has been disconnected"))}})}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case Ne.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case Ne.EVENT:case Ne.BINARY_EVENT:this.onevent(t);break;case Ne.ACK:case Ne.BINARY_ACK:this.onack(t);break;case Ne.DISCONNECT:this.ondisconnect();break;case Ne.CONNECT_ERROR:this.destroy();const r=new Error(t.data.message);r.data=t.data.data,this.emitReserved("connect_error",r);break}}onevent(t){const s=t.data||[];t.id!=null&&s.push(this.ack(t.id)),this.connected?this.emitEvent(s):this.receiveBuffer.push(Object.freeze(s))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const s=this._anyListeners.slice();for(const r of s)r.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&typeof t[t.length-1]=="string"&&(this._lastOffset=t[t.length-1])}ack(t){const s=this;let r=!1;return function(...i){r||(r=!0,s.packet({type:Ne.ACK,id:t,data:i}))}}onack(t){const s=this.acks[t.id];typeof s=="function"&&(delete this.acks[t.id],s.withError&&t.data.unshift(null),s.apply(this,t.data))}onconnect(t,s){this.id=t,this.recovered=s&&this._pid===s,this._pid=s,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(t=>this.emitEvent(t)),this.receiveBuffer=[],this.sendBuffer.forEach(t=>{this.notifyOutgoingListeners(t),this.packet(t)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(t=>t()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:Ne.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const s=this._anyListeners;for(let r=0;r<s.length;r++)if(t===s[r])return s.splice(r,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(t),this}prependAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(t),this}offAnyOutgoing(t){if(!this._anyOutgoingListeners)return this;if(t){const s=this._anyOutgoingListeners;for(let r=0;r<s.length;r++)if(t===s[r])return s.splice(r,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(t){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const s=this._anyOutgoingListeners.slice();for(const r of s)r.apply(this,t.data)}}}function vr(e){e=e||{},this.ms=e.min||100,this.max=e.max||1e4,this.factor=e.factor||2,this.jitter=e.jitter>0&&e.jitter<=1?e.jitter:0,this.attempts=0}vr.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),s=Math.floor(t*this.jitter*e);e=Math.floor(t*10)&1?e+s:e-s}return Math.min(e,this.max)|0};vr.prototype.reset=function(){this.attempts=0};vr.prototype.setMin=function(e){this.ms=e};vr.prototype.setMax=function(e){this.max=e};vr.prototype.setJitter=function(e){this.jitter=e};class Yl extends He{constructor(t,s){var r;super(),this.nsps={},this.subs=[],t&&typeof t=="object"&&(s=t,t=void 0),s=s||{},s.path=s.path||"/socket.io",this.opts=s,lo(this,s),this.reconnection(s.reconnection!==!1),this.reconnectionAttempts(s.reconnectionAttempts||1/0),this.reconnectionDelay(s.reconnectionDelay||1e3),this.reconnectionDelayMax(s.reconnectionDelayMax||5e3),this.randomizationFactor((r=s.randomizationFactor)!==null&&r!==void 0?r:.5),this.backoff=new vr({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(s.timeout==null?2e4:s.timeout),this._readyState="closed",this.uri=t;const i=s.parser||Lj;this.encoder=new i.Encoder,this.decoder=new i.Decoder,this._autoConnect=s.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,t||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(t){return t===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var s;return t===void 0?this._reconnectionDelay:(this._reconnectionDelay=t,(s=this.backoff)===null||s===void 0||s.setMin(t),this)}randomizationFactor(t){var s;return t===void 0?this._randomizationFactor:(this._randomizationFactor=t,(s=this.backoff)===null||s===void 0||s.setJitter(t),this)}reconnectionDelayMax(t){var s;return t===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,(s=this.backoff)===null||s===void 0||s.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new kj(this.uri,this.opts);const s=this.engine,r=this;this._readyState="opening",this.skipReconnect=!1;const i=ts(s,"open",function(){r.onopen(),t&&t()}),a=l=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",l),t?t(l):this.maybeReconnectOnOpen()},o=ts(s,"error",a);if(this._timeout!==!1){const l=this._timeout,c=this.setTimeoutFn(()=>{i(),a(new Error("timeout")),s.close()},l);this.opts.autoUnref&&c.unref(),this.subs.push(()=>{this.clearTimeoutFn(c)})}return this.subs.push(i),this.subs.push(o),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(ts(t,"ping",this.onping.bind(this)),ts(t,"data",this.ondata.bind(this)),ts(t,"error",this.onerror.bind(this)),ts(t,"close",this.onclose.bind(this)),ts(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(s){this.onclose("parse error",s)}}ondecoded(t){oo(()=>{this.emitReserved("packet",t)},this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,s){let r=this.nsps[t];return r?this._autoConnect&&!r.active&&r.connect():(r=new Nm(this,t,s),this.nsps[t]=r),r}_destroy(t){const s=Object.keys(this.nsps);for(const r of s)if(this.nsps[r].active)return;this._close()}_packet(t){const s=this.encoder.encode(t);for(let r=0;r<s.length;r++)this.engine.write(s[r],t.options)}cleanup(){this.subs.forEach(t=>t()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(t,s){var r;this.cleanup(),(r=this.engine)===null||r===void 0||r.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,s),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const s=this.backoff.duration();this._reconnecting=!0;const r=this.setTimeoutFn(()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),!t.skipReconnect&&t.open(i=>{i?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",i)):t.onreconnect()}))},s);this.opts.autoUnref&&r.unref(),this.subs.push(()=>{this.clearTimeoutFn(r)})}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const _r={};function la(e,t){typeof e=="object"&&(t=e,e=void 0),t=t||{};const s=bj(e,t.path||"/socket.io"),r=s.source,i=s.id,a=s.path,o=_r[i]&&a in _r[i].nsps,l=t.forceNew||t["force new connection"]||t.multiplex===!1||o;let c;return l?c=new Yl(r,t):(_r[i]||(_r[i]=new Yl(r,t)),c=_r[i]),s.query&&!t.query&&(t.query=s.queryKey),c.socket(s.path,t)}Object.assign(la,{Manager:Yl,Socket:Nm,io:la,connect:la});const km=d.createContext(void 0);function Ij({children:e}){const[,t]=d.useState(null),[s,r]=d.useState(!1),[i,a]=d.useState({active:!1}),[o,l]=d.useState([]),[c,u]=d.useState(null),[m,f]=d.useState(null),[g,R]=d.useState([]);d.useEffect(()=>{const N=la(window.location.origin,{transports:["websocket","polling"]});return N.on("connect",()=>{r(!0),console.log("[Recorder] Connected to server")}),N.on("disconnect",()=>{r(!1),console.log("[Recorder] Disconnected from server")}),N.on("recorder:status",S=>{console.log("STATUS UPDATE:",S),a(S)}),N.on("recorder:action",S=>{console.log("ACTION RECEIVED:",S),l(P=>[...P,S.step])}),N.on("recorder:steps",S=>{l(S.steps)}),N.on("recorder:event",S=>{switch(console.log("[Recorder] Event:",S),S.type){case"session_started":k();break;case"session_stopped":k(),C();break;case"capture_started":case"capture_completed":case"capture_error":k(),C();break}}),N.on("recorder:diagnostic",S=>{const P={level:S.level,message:S.message,timestamp:new Date().toISOString()};R(b=>[...b,P].slice(-50)),S.level==="error"&&f(S.message)}),t(N),fetch("/api/recorder/status").then(S=>S.json()).then(S=>S.ok&&a(S.status)),fetch("/api/recorder/steps").then(S=>S.json()).then(S=>S.ok&&l(S.steps)),()=>{N.close()}},[]);const k=d.useCallback(async()=>{try{const N=await fetch("/api/recorder/status");if(N.ok){const S=await N.json();a(S.status||{active:!1})}}catch(N){console.error("[Recorder] Failed to refresh status:",N)}},[]),C=d.useCallback(async()=>{try{const N=await fetch("/api/recorder/steps");if(N.ok){const S=await N.json();l(S.steps||[])}}catch(N){console.error("[Recorder] Failed to refresh steps:",N)}},[]),j=d.useCallback(async N=>{l([]);try{f(null);const S=await fetch("/api/recorder/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(N)});if(!S.ok){const O=(await S.json()).error||"Failed to start recording";throw f(O),new Error(O)}a(b=>({...b,active:!0,visualKey:N.visualKey||b.visualKey}));const P=await fetch("/api/recorder/status");if(P.ok){const b=await P.json();a(b.status||{active:!1})}}catch(S){throw console.error("[Recorder] Failed to start:",S),f(S.message||"Failed to start recording"),S}},[]),p=d.useCallback(async(N=!0)=>{try{f(null);const S=await fetch("/api/recorder/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({save:N})});if(!S.ok){const D=(await S.json()).error||"Failed to stop recording";throw f(D),new Error(D)}const[P,b]=await Promise.all([fetch("/api/recorder/status"),fetch("/api/recorder/steps")]);if(P.ok){const O=await P.json();a(O.status||{active:!1})}if(b.ok){const O=await b.json();l(O.steps||[])}u(null)}catch(S){throw console.error("[Recorder] Failed to stop:",S),f(S.message||"Failed to stop recording"),S}},[]),h=d.useCallback(async(N={})=>{try{const S=await fetch("/api/recorder/capture",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(N)});if(!S.ok){const O=await S.json();throw new Error(O.error||"Failed to capture")}const[P,b]=await Promise.all([fetch("/api/recorder/status"),fetch("/api/recorder/steps")]);if(P.ok){const O=await P.json();a(O.status||{active:!1})}if(b.ok){const O=await b.json();l(O.steps||[])}}catch(S){throw console.error("[Recorder] Failed to capture:",S),S}},[]),x=d.useCallback(async N=>{try{const S=await fetch(`/api/recorder/steps/${N}`,{method:"DELETE"});if(!S.ok){const P=await S.json();throw new Error(P.error||"Failed to remove step")}l(P=>P.filter((b,O)=>O!==N))}catch(S){throw console.error("[Recorder] Failed to remove step:",S),S}},[]),w=d.useMemo(()=>({status:i,steps:o,isConnected:s,lastEvent:c,error:m,diagnostics:g,start:j,stop:p,capture:h,removeStep:x,refreshStatus:k,refreshSteps:C}),[i,o,s,c,m,g,j,p,h,x,k,C]);return n.jsx(km.Provider,{value:w,children:e})}function bm(){const e=d.useContext(km);if(e===void 0)throw new Error("useRecorder must be used within a RecorderProvider");return e}const he=d.forwardRef(({className:e,...t},s)=>n.jsx("div",{ref:s,className:Y("rounded-lg border border-border/40 bg-card/50 text-card-foreground backdrop-blur-sm",e),...t}));he.displayName="Card";const ke=d.forwardRef(({className:e,...t},s)=>n.jsx("div",{ref:s,className:Y("flex flex-col space-y-1 p-4",e),...t}));ke.displayName="CardHeader";const be=d.forwardRef(({className:e,...t},s)=>n.jsx("h3",{ref:s,className:Y("text-sm font-medium leading-none tracking-tight",e),...t}));be.displayName="CardTitle";const at=d.forwardRef(({className:e,...t},s)=>n.jsx("p",{ref:s,className:Y("text-[13px] text-muted-foreground",e),...t}));at.displayName="CardDescription";const me=d.forwardRef(({className:e,...t},s)=>n.jsx("div",{ref:s,className:Y("p-4 pt-0",e),...t}));me.displayName="CardContent";const Dj=d.forwardRef(({className:e,...t},s)=>n.jsx("div",{ref:s,className:Y("flex items-center p-4 pt-0",e),...t}));Dj.displayName="CardFooter";const mh=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,xh=nm,Sm=(e,t)=>s=>{var r;if((t==null?void 0:t.variants)==null)return xh(e,s==null?void 0:s.class,s==null?void 0:s.className);const{variants:i,defaultVariants:a}=t,o=Object.keys(i).map(u=>{const m=s==null?void 0:s[u],f=a==null?void 0:a[u];if(m===null)return null;const g=mh(m)||mh(f);return i[u][g]}),l=s&&Object.entries(s).reduce((u,m)=>{let[f,g]=m;return g===void 0||(u[f]=g),u},{}),c=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((u,m)=>{let{class:f,className:g,...R}=m;return Object.entries(R).every(k=>{let[C,j]=k;return Array.isArray(j)?j.includes({...a,...l}[C]):{...a,...l}[C]===j})?[...u,f,g]:u},[]);return xh(e,o,c,s==null?void 0:s.class,s==null?void 0:s.className)},Fj=Sm("inline-flex items-center rounded-md border px-1.5 py-0.5 text-[11px] font-medium transition-colors focus:outline-none",{variants:{variant:{default:"border-transparent bg-primary/20 text-primary",secondary:"border-transparent bg-secondary text-secondary-foreground",destructive:"border-transparent bg-destructive/20 text-destructive",success:"border-transparent bg-success/20 text-success",approved:"border-transparent bg-green-500/20 text-green-600 dark:text-green-400",pending:"border-transparent bg-amber-500/20 text-amber-600 dark:text-amber-400",warning:"border-transparent bg-warning/20 text-warning",info:"border-transparent bg-blue-500/20 text-blue-600 dark:text-blue-400",outline:"border-border/60 text-muted-foreground bg-transparent",muted:"border-transparent bg-muted text-muted-foreground"}},defaultVariants:{variant:"default"}});function ue({className:e,variant:t,...s}){return n.jsx("div",{className:Y(Fj({variant:t}),e),...s})}const $j=Sm("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-[13px] font-medium transition-all duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90 shadow-[0_1px_2px_rgba(0,0,0,0.3),inset_0_1px_0_rgba(255,255,255,0.1)]",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-border bg-transparent hover:bg-accent hover:text-accent-foreground hover:border-border/80",secondary:"bg-secondary/80 text-secondary-foreground hover:bg-secondary",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline",success:"bg-success text-success-foreground hover:bg-success/90 shadow-[0_1px_2px_rgba(0,0,0,0.3),inset_0_1px_0_rgba(255,255,255,0.1)]"},size:{default:"h-8 px-3 py-1.5",sm:"h-7 rounded-md px-2.5 text-xs",lg:"h-9 rounded-md px-4",icon:"h-8 w-8","icon-sm":"h-7 w-7"}},defaultVariants:{variant:"default",size:"default"}}),T=d.forwardRef(({className:e,variant:t,size:s,...r},i)=>n.jsx("button",{className:Y($j({variant:t,size:s,className:e})),ref:i,...r}));T.displayName="Button";const Fa=d.forwardRef(({className:e,value:t=0,...s},r)=>n.jsx("div",{ref:r,className:`relative h-2 w-full overflow-hidden rounded-full bg-gray-700 ${e||""}`,...s,children:n.jsx("div",{className:"h-full bg-blue-500 transition-all duration-300",style:{width:`${Math.min(100,Math.max(0,t))}%`}})}));Fa.displayName="Progress";const Cm=d.createContext(void 0);function st({open:e,onOpenChange:t,children:s}){return d.useEffect(()=>(e?document.body.style.overflow="hidden":document.body.style.overflow="",()=>{document.body.style.overflow=""}),[e]),e?n.jsx(Cm.Provider,{value:{open:e,onOpenChange:t},children:n.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[n.jsx("div",{className:"fixed inset-0 bg-black/50",onClick:()=>t(!1)}),n.jsx("div",{className:"relative z-50",children:s})]})}):null}function nt({className:e,children:t,...s}){if(!d.useContext(Cm))throw new Error("DialogContent must be used within Dialog");return n.jsx("div",{...s,className:Y("bg-card/95 backdrop-blur-xl border border-border/50 rounded-xl shadow-2xl p-6 w-full max-w-lg max-h-[90vh] overflow-auto",e),children:t})}function Xe({className:e,...t}){return n.jsx("div",{...t,className:Y("flex flex-col space-y-1.5 mb-4",e)})}function Ze({className:e,...t}){return n.jsx("h2",{...t,className:Y("text-[15px] font-semibold leading-none tracking-tight",e)})}function ot({className:e,...t}){return n.jsx("p",{...t,className:Y("text-[13px] text-muted-foreground mt-1",e)})}function lt({className:e,...t}){return n.jsx("div",{...t,className:Y("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2 mt-4",e)})}function gh(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Em(...e){return t=>{let s=!1;const r=e.map(i=>{const a=gh(i,t);return!s&&typeof a=="function"&&(s=!0),a});if(s)return()=>{for(let i=0;i<r.length;i++){const a=r[i];typeof a=="function"?a():gh(e[i],null)}}}}function od(...e){return d.useCallback(Em(...e),e)}function Vj(e,t=[]){let s=[];function r(a,o){const l=d.createContext(o),c=s.length;s=[...s,o];const u=f=>{var p;const{scope:g,children:R,...k}=f,C=((p=g==null?void 0:g[e])==null?void 0:p[c])||l,j=d.useMemo(()=>k,Object.values(k));return n.jsx(C.Provider,{value:j,children:R})};u.displayName=a+"Provider";function m(f,g){var C;const R=((C=g==null?void 0:g[e])==null?void 0:C[c])||l,k=d.useContext(R);if(k)return k;if(o!==void 0)return o;throw new Error(`\`${f}\` must be used within \`${a}\``)}return[u,m]}const i=()=>{const a=s.map(o=>d.createContext(o));return function(l){const c=(l==null?void 0:l[e])||a;return d.useMemo(()=>({[`__scope${e}`]:{...l,[e]:c}}),[l,c])}};return i.scopeName=e,[r,Uj(i,...t)]}function Uj(...e){const t=e[0];if(e.length===1)return t;const s=()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(a){const o=r.reduce((l,{useScope:c,scopeName:u})=>{const f=c(a)[`__scope${u}`];return{...l,...f}},{});return d.useMemo(()=>({[`__scope${t.scopeName}`]:o}),[o])}};return s.scopeName=t.scopeName,s}function vh(e,t,{checkForDefaultPrevented:s=!0}={}){return function(i){if(e==null||e(i),s===!1||!i.defaultPrevented)return t==null?void 0:t(i)}}var $a=globalThis!=null&&globalThis.document?d.useLayoutEffect:()=>{},Bj=zh[" useInsertionEffect ".trim().toString()]||$a;function Wj({prop:e,defaultProp:t,onChange:s=()=>{},caller:r}){const[i,a,o]=Kj({defaultProp:t,onChange:s}),l=e!==void 0,c=l?e:i;{const m=d.useRef(e!==void 0);d.useEffect(()=>{const f=m.current;f!==l&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${l?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),m.current=l},[l,r])}const u=d.useCallback(m=>{var f;if(l){const g=Hj(m)?m(e):m;g!==e&&((f=o.current)==null||f.call(o,g))}else a(m)},[l,e,a,o]);return[c,u]}function Kj({defaultProp:e,onChange:t}){const[s,r]=d.useState(e),i=d.useRef(s),a=d.useRef(t);return Bj(()=>{a.current=t},[t]),d.useEffect(()=>{var o;i.current!==s&&((o=a.current)==null||o.call(a,s),i.current=s)},[s,i]),[s,r,a]}function Hj(e){return typeof e=="function"}function Jj(e){const t=d.useRef({value:e,previous:e});return d.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function qj(e){const[t,s]=d.useState(void 0);return $a(()=>{if(e){s({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const a=i[0];let o,l;if("borderBoxSize"in a){const c=a.borderBoxSize,u=Array.isArray(c)?c[0]:c;o=u.inlineSize,l=u.blockSize}else o=e.offsetWidth,l=e.offsetHeight;s({width:o,height:l})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else s(void 0)},[e]),t}function Gj(e,t){return d.useReducer((s,r)=>t[s][r]??s,e)}var Rm=e=>{const{present:t,children:s}=e,r=Qj(t),i=typeof s=="function"?s({present:r.isPresent}):d.Children.only(s),a=od(r.ref,Yj(i));return typeof s=="function"||r.isPresent?d.cloneElement(i,{ref:a}):null};Rm.displayName="Presence";function Qj(e){const[t,s]=d.useState(),r=d.useRef(null),i=d.useRef(e),a=d.useRef("none"),o=e?"mounted":"unmounted",[l,c]=Gj(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return d.useEffect(()=>{const u=Bi(r.current);a.current=l==="mounted"?u:"none"},[l]),$a(()=>{const u=r.current,m=i.current;if(m!==e){const g=a.current,R=Bi(u);e?c("MOUNT"):R==="none"||(u==null?void 0:u.display)==="none"?c("UNMOUNT"):c(m&&g!==R?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,c]),$a(()=>{if(t){let u;const m=t.ownerDocument.defaultView??window,f=R=>{const C=Bi(r.current).includes(CSS.escape(R.animationName));if(R.target===t&&C&&(c("ANIMATION_END"),!i.current)){const j=t.style.animationFillMode;t.style.animationFillMode="forwards",u=m.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=j)})}},g=R=>{R.target===t&&(a.current=Bi(r.current))};return t.addEventListener("animationstart",g),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{m.clearTimeout(u),t.removeEventListener("animationstart",g),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else c("ANIMATION_END")},[t,c]),{isPresent:["mounted","unmountSuspended"].includes(l),ref:d.useCallback(u=>{r.current=u?getComputedStyle(u):null,s(u)},[])}}function Bi(e){return(e==null?void 0:e.animationName)||"none"}function Yj(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,s=t&&"isReactWarning"in t&&t.isReactWarning;return s?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,s=t&&"isReactWarning"in t&&t.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}function Xj(e){const t=Zj(e),s=d.forwardRef((r,i)=>{const{children:a,...o}=r,l=d.Children.toArray(a),c=l.find(t1);if(c){const u=c.props.children,m=l.map(f=>f===c?d.Children.count(u)>1?d.Children.only(null):d.isValidElement(u)?u.props.children:null:f);return n.jsx(t,{...o,ref:i,children:d.isValidElement(u)?d.cloneElement(u,void 0,m):null})}return n.jsx(t,{...o,ref:i,children:a})});return s.displayName=`${e}.Slot`,s}function Zj(e){const t=d.forwardRef((s,r)=>{const{children:i,...a}=s;if(d.isValidElement(i)){const o=n1(i),l=s1(a,i.props);return i.type!==d.Fragment&&(l.ref=r?Em(r,o):o),d.cloneElement(i,l)}return d.Children.count(i)>1?d.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var e1=Symbol("radix.slottable");function t1(e){return d.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===e1}function s1(e,t){const s={...t};for(const r in t){const i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?s[r]=(...l)=>{const c=a(...l);return i(...l),c}:i&&(s[r]=i):r==="style"?s[r]={...i,...a}:r==="className"&&(s[r]=[i,a].filter(Boolean).join(" "))}return{...e,...s}}function n1(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,s=t&&"isReactWarning"in t&&t.isReactWarning;return s?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,s=t&&"isReactWarning"in t&&t.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}var r1=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ld=r1.reduce((e,t)=>{const s=Xj(`Primitive.${t}`),r=d.forwardRef((i,a)=>{const{asChild:o,...l}=i,c=o?s:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),n.jsx(c,{...l,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{}),co="Checkbox",[i1]=Vj(co),[a1,cd]=i1(co);function o1(e){const{__scopeCheckbox:t,checked:s,children:r,defaultChecked:i,disabled:a,form:o,name:l,onCheckedChange:c,required:u,value:m="on",internal_do_not_use_render:f}=e,[g,R]=Wj({prop:s,defaultProp:i??!1,onChange:c,caller:co}),[k,C]=d.useState(null),[j,p]=d.useState(null),h=d.useRef(!1),x=k?!!o||!!k.closest("form"):!0,w={checked:g,disabled:a,setChecked:R,control:k,setControl:C,name:l,form:o,value:m,hasConsumerStoppedPropagationRef:h,required:u,defaultChecked:tn(i)?!1:i,isFormControl:x,bubbleInput:j,setBubbleInput:p};return n.jsx(a1,{scope:t,...w,children:l1(f)?f(w):r})}var _m="CheckboxTrigger",Pm=d.forwardRef(({__scopeCheckbox:e,onKeyDown:t,onClick:s,...r},i)=>{const{control:a,value:o,disabled:l,checked:c,required:u,setControl:m,setChecked:f,hasConsumerStoppedPropagationRef:g,isFormControl:R,bubbleInput:k}=cd(_m,e),C=od(i,m),j=d.useRef(c);return d.useEffect(()=>{const p=a==null?void 0:a.form;if(p){const h=()=>f(j.current);return p.addEventListener("reset",h),()=>p.removeEventListener("reset",h)}},[a,f]),n.jsx(ld.button,{type:"button",role:"checkbox","aria-checked":tn(c)?"mixed":c,"aria-required":u,"data-state":Lm(c),"data-disabled":l?"":void 0,disabled:l,value:o,...r,ref:C,onKeyDown:vh(t,p=>{p.key==="Enter"&&p.preventDefault()}),onClick:vh(s,p=>{f(h=>tn(h)?!0:!h),k&&R&&(g.current=p.isPropagationStopped(),g.current||p.stopPropagation())})})});Pm.displayName=_m;var dd=d.forwardRef((e,t)=>{const{__scopeCheckbox:s,name:r,checked:i,defaultChecked:a,required:o,disabled:l,value:c,onCheckedChange:u,form:m,...f}=e;return n.jsx(o1,{__scopeCheckbox:s,checked:i,defaultChecked:a,disabled:l,required:o,onCheckedChange:u,name:r,form:m,value:c,internal_do_not_use_render:({isFormControl:g})=>n.jsxs(n.Fragment,{children:[n.jsx(Pm,{...f,ref:t,__scopeCheckbox:s}),g&&n.jsx(zm,{__scopeCheckbox:s})]})})});dd.displayName=co;var Tm="CheckboxIndicator",Am=d.forwardRef((e,t)=>{const{__scopeCheckbox:s,forceMount:r,...i}=e,a=cd(Tm,s);return n.jsx(Rm,{present:r||tn(a.checked)||a.checked===!0,children:n.jsx(ld.span,{"data-state":Lm(a.checked),"data-disabled":a.disabled?"":void 0,...i,ref:t,style:{pointerEvents:"none",...e.style}})})});Am.displayName=Tm;var Om="CheckboxBubbleInput",zm=d.forwardRef(({__scopeCheckbox:e,...t},s)=>{const{control:r,hasConsumerStoppedPropagationRef:i,checked:a,defaultChecked:o,required:l,disabled:c,name:u,value:m,form:f,bubbleInput:g,setBubbleInput:R}=cd(Om,e),k=od(s,R),C=Jj(a),j=qj(r);d.useEffect(()=>{const h=g;if(!h)return;const x=window.HTMLInputElement.prototype,N=Object.getOwnPropertyDescriptor(x,"checked").set,S=!i.current;if(C!==a&&N){const P=new Event("click",{bubbles:S});h.indeterminate=tn(a),N.call(h,tn(a)?!1:a),h.dispatchEvent(P)}},[g,C,a,i]);const p=d.useRef(tn(a)?!1:a);return n.jsx(ld.input,{type:"checkbox","aria-hidden":!0,defaultChecked:o??p.current,required:l,disabled:c,name:u,value:m,form:f,...t,tabIndex:-1,ref:k,style:{...t.style,...j,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});zm.displayName=Om;function l1(e){return typeof e=="function"}function tn(e){return e==="indeterminate"}function Lm(e){return tn(e)?"indeterminate":e?"checked":"unchecked"}const ns=d.forwardRef(({className:e,indeterminate:t,...s},r)=>n.jsx(dd,{ref:r,className:Y("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",t&&"bg-primary text-primary-foreground",e),...s,children:n.jsx(Am,{className:Y("flex items-center justify-center text-current"),children:t?n.jsx(Zp,{className:"h-3 w-3"}):n.jsx(ro,{className:"h-3 w-3"})})}));ns.displayName=dd.displayName;const uo=d.forwardRef(({className:e,...t},s)=>n.jsx("textarea",{className:Y("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:s,...t}));uo.displayName="Textarea";function ho({open:e,onOpenChange:t,scenarioKeys:s,onConfirm:r}){const[i,a]=d.useState([]),[o,l]=d.useState(!0),[c,u]=d.useState(!1),[m,f]=d.useState(""),[g,R]=d.useState(new Set),[k,C]=d.useState({}),j=d.useMemo(()=>JSON.stringify(s||[]),[s]);d.useEffect(()=>{if(!e)return;(async()=>{l(!0);try{const $=(await(await fetch("/api/output?latestJobOnly=true")).json()).groups||[],A=(s?$.filter(J=>s.includes(J.scenarioKey)):$).map(J=>({scenarioKey:J.scenarioKey,variationSlug:J.variationSlug,assets:J.assets||[]}));a(A);const z={};for(const J of A){const G=`${J.scenarioKey}::${J.variationSlug}`;z[G]=!0}C(z),R(new Set);const W=[...new Set(A.map(J=>J.scenarioKey))];W.length===1?f(`Update ${W[0]} visuals`):W.length>1?f(`Update ${W.length} scenarios`):f(""),l(!1)}catch(_){console.error("Failed to load assets:",_),l(!1)}})()},[e,j]);const p=y=>y<1024?`${y} B`:y<1024*1024?`${(y/1024).toFixed(1)} KB`:`${(y/(1024*1024)).toFixed(1)} MB`,h=y=>{const _=i.filter($=>$.scenarioKey===y),F=_.every($=>k[`${$.scenarioKey}::${$.variationSlug}`]);C($=>{const E={...$};for(const A of _)E[`${A.scenarioKey}::${A.variationSlug}`]=!F;return E})},x=y=>{const _=`${y.scenarioKey}::${y.variationSlug}`;C(F=>({...F,[_]:!F[_]}))},w=()=>{C(y=>{const _={...y};for(const F of Object.keys(_))_[F]=!0;return _})},N=()=>{C(y=>{const _={...y};for(const F of Object.keys(_))_[F]=!1;return _})},S=y=>{R(_=>{const F=new Set(_);return F.has(y)?F.delete(y):F.add(y),F})},P=Object.values(k).filter(Boolean).length,b=i.length,O=d.useMemo(()=>{let y=0;for(const _ of i){const F=`${_.scenarioKey}::${_.variationSlug}`;k[F]&&(y+=_.assets.length)}return y},[i,k]),D=d.useMemo(()=>{let y=0;for(const _ of i){const F=`${_.scenarioKey}::${_.variationSlug}`;if(k[F])for(const $ of _.assets)y+=$.size}return y},[i,k]),v=async()=>{u(!0);try{const y=i.filter(_=>{const F=`${_.scenarioKey}::${_.variationSlug}`;return k[F]});await r(y,m.trim()||void 0)}finally{u(!1)}},L=y=>{const _=i.filter($=>$.scenarioKey===y),F=_.filter($=>k[`${$.scenarioKey}::${$.variationSlug}`]).length;return F===0?"none":F===_.length?"all":"some"},V=d.useMemo(()=>{const y=new Map;for(const _ of i){const F=y.get(_.scenarioKey)||[];F.push(_),y.set(_.scenarioKey,F)}return y},[i]);return n.jsx(st,{open:e,onOpenChange:t,children:n.jsxs(nt,{className:"max-w-3xl max-h-[85vh] overflow-y-auto",children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:"Publish Preview"}),n.jsx(ot,{children:"Select which scenarios to publish to the platform"})]}),o?n.jsx("div",{className:"py-8 text-center text-muted-foreground",children:"Loading assets..."}):b===0?n.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[n.jsx("p",{children:"No assets found to publish."}),n.jsx("p",{className:"text-sm mt-2",children:"Run `reshot run` to generate assets first."})]}):n.jsxs("div",{className:"space-y-4",children:[n.jsxs(he,{children:[n.jsxs(ke,{className:"pb-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Fy,{className:"h-4 w-4 text-muted-foreground"}),n.jsx(be,{className:"text-sm",children:"Commit Message"})]}),n.jsx(at,{className:"text-xs",children:"Describe what changed in this publish for version tracking."})]}),n.jsx(me,{children:n.jsxs("div",{className:"space-y-2",children:[n.jsx(uo,{placeholder:"e.g., Updated dashboard screenshots with new navigation design",value:m,onChange:y=>f(y.target.value),rows:2,className:"resize-none"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:m.length>0?`${m.length} characters`:"Optional but recommended"})]})})]}),n.jsxs(he,{children:[n.jsx(ke,{className:"pb-2",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(be,{className:"text-sm",children:"Summary"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsxs(T,{variant:"outline",size:"sm",onClick:w,className:"text-xs h-7",children:[n.jsx(Qc,{className:"h-3 w-3 mr-1"}),"Select All"]}),n.jsxs(T,{variant:"outline",size:"sm",onClick:N,className:"text-xs h-7",children:[n.jsx(ed,{className:"h-3 w-3 mr-1"}),"Select None"]})]})]})}),n.jsx(me,{children:n.jsxs("div",{className:"grid grid-cols-4 gap-4 text-sm",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-muted-foreground text-xs",children:"Scenarios"}),n.jsx("div",{className:"font-semibold text-lg",children:V.size})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-muted-foreground text-xs",children:"Variations"}),n.jsxs("div",{className:"font-semibold text-lg",children:[P," / ",b]})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-muted-foreground text-xs",children:"Assets"}),n.jsx("div",{className:"font-semibold text-lg",children:O})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-muted-foreground text-xs",children:"Size"}),n.jsx("div",{className:"font-semibold text-lg",children:p(D)})]})]})})]}),n.jsx("div",{className:"space-y-2",children:Array.from(V.entries()).map(([y,_])=>{const F=L(y),$=g.has(y),E=_.reduce((z,W)=>z+W.assets.length,0),A=_.filter(z=>k[`${z.scenarioKey}::${z.variationSlug}`]).length;return n.jsxs(he,{className:"overflow-hidden",children:[n.jsxs("div",{className:"flex items-center gap-3 p-3 hover:bg-muted/30 cursor-pointer border-b",onClick:()=>h(y),children:[n.jsx(ns,{checked:F==="all",indeterminate:F==="some",onCheckedChange:()=>h(y),onClick:z=>z.stopPropagation()}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"font-medium text-sm truncate",children:y}),n.jsxs("div",{className:"text-xs text-muted-foreground",children:[A,"/",_.length," variations · ",E," assets"]})]}),n.jsx(T,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:z=>{z.stopPropagation(),S(y)},children:$?n.jsx(zs,{className:"h-4 w-4"}):n.jsx(Ps,{className:"h-4 w-4"})})]}),$&&n.jsx("div",{className:"p-2 space-y-1 bg-muted/10",children:_.map(z=>{const W=`${z.scenarioKey}::${z.variationSlug}`,J=k[W];return n.jsxs("div",{className:`flex items-center gap-3 p-2 rounded-md cursor-pointer transition-colors ${J?"bg-primary/10 border border-primary/20":"hover:bg-muted/50"}`,onClick:()=>x(z),children:[n.jsx(ns,{checked:J,onCheckedChange:()=>x(z),onClick:G=>G.stopPropagation(),className:"ml-4"}),n.jsx("div",{className:"flex-1 min-w-0",children:n.jsx(ue,{variant:"secondary",className:"font-mono text-xs",children:z.variationSlug})}),n.jsxs("span",{className:"text-xs text-muted-foreground",children:[z.assets.length," assets"]})]},W)})})]},y)})})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>t(!1),disabled:c,children:"Cancel"}),n.jsx(T,{onClick:v,disabled:P===0||c,children:c?n.jsxs(n.Fragment,{children:[n.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[n.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),n.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Publishing..."]}):n.jsxs(n.Fragment,{children:[n.jsx(on,{className:"h-4 w-4 mr-2"}),"Publish"," ",O>0&&`${O} assets`]})})]})]})})}const Mm=/\u001b\[[0-9;]*m/g;function tr(e){for(let t=e.length-1;t>=0;t--){const s=e[t].message.replace(Mm,""),r=s.match(/\[PROGRESS\]\s*(\d+)\/(\d+)\s*\|\s*active:(\d+)\s*\|\s*last:[^\|]+\|\s*eta:([^\|]+)\|\s*rate:([^\s]+)\/min/);if(r)return{current:parseInt(r[1],10),total:parseInt(r[2],10),activeWorkers:parseInt(r[3],10),eta:r[4].trim(),throughput:r[5].trim()};const i=s.match(/\[(\d+)\/(\d+)\]/)||s.match(/Progress:\s*(\d+)\/(\d+)/);if(i)return{current:parseInt(i[1],10),total:parseInt(i[2],10)}}return null}function Im(e){return e.replace(Mm,"")}const Dm=d.createContext(null);function ji(){const e=d.useContext(Dm);if(!e)throw new Error("useJobMonitor must be used within JobMonitorProvider");return e}function c1({children:e}){const[t,s]=d.useState([]),[r,i]=d.useState(!1),[a,o]=d.useState(0),[l,c]=d.useState(".reshot/output"),[u,m]=d.useState(null);d.useEffect(()=>{fetch("/api/config").then(w=>w.json()).then(w=>{var N,S;(N=w.config)!=null&&N.assetDir&&c(w.config.assetDir),(S=w.settings)!=null&&S.platformUrl&&m(w.settings.platformUrl)}).catch(()=>{})},[]);const f=d.useRef(new Set),g=d.useRef(new Set),[R,k]=d.useState(null),C=d.useCallback(()=>{k(null)},[]),j=d.useCallback(async()=>{try{const S=(await(await fetch("/api/jobs?limit=20")).json()).jobs||[],P=Date.now(),b=S.filter(O=>{if(O.status==="running"||O.status==="pending")return!0;const D=new Date(O.updatedAt).getTime();return P-D<1e4});s(b)}catch(w){console.error("Failed to load jobs:",w)}},[]),p=t.some(w=>w.status==="running"||w.status==="pending");d.useEffect(()=>{if(j(),a===0&&!p)return;const w=setInterval(j,2e3);return()=>clearInterval(w)},[j,p,a]),d.useEffect(()=>{var w;for(const N of t)if(f.current.has(N.id)&&!g.current.has(N.id)){if(N.status==="success"){g.current.add(N.id),k(N);break}if(N.status==="failed"&&((w=N.metadata)!=null&&w.authRequired)){g.current.add(N.id),k(N);break}}},[t]);const h=d.useCallback(w=>{s(N=>[w,...N.filter(S=>S.id!==w.id)]),i(!1)},[]),x=d.useCallback((w,N)=>{f.current.add(w),i(!1),o(S=>S+1),setTimeout(()=>o(0),1e4),j()},[j]);return n.jsx(Dm.Provider,{value:{activeJobs:t,addJob:h,refreshJobs:j,trackJob:x,isMinimized:r,setIsMinimized:i,completedJobForModal:R,dismissCompletionModal:C,outputDir:l,platformUrl:u},children:e})}function d1(){var V;const e=Os(),t=On(),{toast:s}=Pt(),{activeJobs:r,isMinimized:i,setIsMinimized:a,trackJob:o,completedJobForModal:l,dismissCompletionModal:c,outputDir:u,platformUrl:m}=ji(),[f,g]=d.useState(null),[R,k]=d.useState(new Set),[C,j]=d.useState(!1),[p,h]=d.useState([]),[x,w]=d.useState(null);if(d.useEffect(()=>{const y=r.find(_=>_.status==="running"||_.status==="pending");y&&y.id!==x&&(g(y.id),w(y.id)),!y&&x&&w(null)},[r,x]),t.pathname==="/jobs")return null;const N=r.filter(y=>!R.has(y.id));if(N.length===0)return null;const S=N.filter(y=>y.status==="running"||y.status==="pending"),P=N.filter(y=>y.status==="success"||y.status==="failed"||y.status==="cancelled"),b=y=>{y.scenarioKey?e(`/scenarios/${y.scenarioKey}?tab=assets`):e("/assets"),k(_=>new Set([..._,y.id]))},O=y=>{k(_=>new Set([..._,y]))},D=(y,_)=>{if(_==="running"||_==="pending")return n.jsx(_e,{className:"h-3.5 w-3.5 animate-spin"});if(_==="success")return n.jsx(vt,{className:"h-3.5 w-3.5 text-green-500"});if(_==="failed")return n.jsx(Da,{className:"h-3.5 w-3.5 text-red-500"});switch(y){case"run":return n.jsx(Ts,{className:"h-3.5 w-3.5"});case"publish":return n.jsx(on,{className:"h-3.5 w-3.5"});default:return n.jsx(fn,{className:"h-3.5 w-3.5"})}},v=y=>{const _=y.type==="run"?"Capture":y.type==="publish"?"Publish":"Record";return y.scenarioKey?`${_}: ${y.scenarioKey}`:`${_} All`},L=y=>{switch(y.status){case"running":{const _=tr(y.logs);return n.jsx(ue,{variant:"info",className:"text-[10px] px-1.5 py-0",children:_?`${_.current}/${_.total}`:"Running"})}case"pending":return n.jsx(ue,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:"Queued"});case"success":return n.jsx(ue,{variant:"success",className:"text-[10px] px-1.5 py-0",children:"Done"});case"failed":return n.jsx(ue,{variant:"destructive",className:"text-[10px] px-1.5 py-0",children:"Failed"});case"cancelled":return n.jsx(ue,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:"Cancelled"});default:return null}};return n.jsxs("div",{className:"fixed bottom-4 right-4 z-50 flex flex-col gap-2 max-w-sm w-full",children:[i&&n.jsx(he,{className:"cursor-pointer hover:bg-accent transition-colors shadow-lg border-border",onClick:()=>a(!1),children:n.jsxs(me,{className:"p-3 flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[S.length>0&&n.jsx(_e,{className:"h-4 w-4 animate-spin text-blue-500"}),S.length===0&&P.length>0&&n.jsx(vt,{className:"h-4 w-4 text-green-500"}),n.jsx("span",{className:"text-sm font-medium",children:S.length>0?(()=>{const y=tr(S[0].logs);if(y){const _=y.eta?` — ETA ${y.eta}`:"";return`Capturing ${y.current}/${y.total}${_}`}return`${S.length} job${S.length>1?"s":""} running`})():`${P.length} completed`})]}),n.jsx(Wy,{className:"h-4 w-4 text-muted-foreground"})]})}),!i&&n.jsxs(he,{className:"shadow-lg border-border overflow-hidden",children:[n.jsxs(ke,{className:"py-2 px-3 border-b bg-muted/30 flex flex-row items-center justify-between",children:[n.jsxs(be,{className:"text-xs font-medium flex items-center gap-2",children:[S.length>0&&n.jsx(_e,{className:"h-3 w-3 animate-spin text-blue-500"}),"Active Jobs (",N.length,")"]}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx(T,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>e("/jobs"),children:n.jsx(an,{className:"h-3 w-3"})}),n.jsx(T,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>a(!0),children:n.jsx(Hy,{className:"h-3 w-3"})})]})]}),n.jsx(me,{className:"p-0 max-h-80 overflow-y-auto",children:n.jsx("div",{className:"divide-y divide-border",children:N.map(y=>{var _,F;return n.jsxs("div",{className:"p-2 hover:bg-accent/50 transition-colors",children:[n.jsxs("div",{className:"flex items-center justify-between cursor-pointer",onClick:()=>g(f===y.id?null:y.id),children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[D(y.type,y.status),n.jsx("span",{className:"text-xs font-medium truncate",children:v(y)})]}),n.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[L(y),f===y.id?n.jsx(Yc,{className:"h-3 w-3 text-muted-foreground"}):n.jsx(zs,{className:"h-3 w-3 text-muted-foreground"})]})]}),(y.status==="running"||y.status==="pending")&&(()=>{const $=tr(y.logs);if($){const E=Math.round($.current/$.total*100);return n.jsxs("div",{className:"mt-2 space-y-1",children:[n.jsx(Fa,{value:E,className:"h-1"}),n.jsxs("div",{className:"flex items-center justify-between text-[10px] text-muted-foreground",children:[n.jsxs("span",{children:[$.current,"/",$.total," completed",$.activeWorkers&&$.activeWorkers>1?` (${$.activeWorkers} parallel)`:""]}),n.jsxs("span",{children:[E,"%"]})]}),($.eta||$.throughput)&&n.jsxs("div",{className:"flex items-center justify-between text-[10px] text-muted-foreground",children:[$.eta&&n.jsxs("span",{children:["ETA: ",$.eta]}),$.throughput&&n.jsxs("span",{children:[$.throughput,"/min"]})]})]})}return y.status==="running"?n.jsxs("div",{className:"mt-2 text-[10px] text-muted-foreground flex items-center gap-1",children:[n.jsx(_e,{className:"h-3 w-3 animate-spin"}),n.jsx("span",{children:"Processing..."})]}):null})(),y.status==="failed"&&((_=y.metadata)==null?void 0:_.error)&&n.jsxs("div",{className:"mt-2 p-2 bg-red-50 dark:bg-red-950/30 rounded border border-red-200 dark:border-red-900",children:[n.jsx("p",{className:"text-[10px] text-red-600 dark:text-red-400 font-medium",children:y.metadata.error}),((F=y.metadata)==null?void 0:F.authRequired)&&n.jsxs(T,{size:"sm",variant:"outline",className:"h-6 text-xs mt-1.5",onClick:$=>{$.stopPropagation(),e("/connection")},children:[n.jsx(Ma,{className:"h-3 w-3 mr-1"}),"Reconnect"]})]}),f===y.id&&n.jsxs("div",{className:"mt-2 space-y-2",children:[n.jsx("div",{className:"bg-muted/50 rounded p-2 max-h-32 overflow-y-auto",children:n.jsxs("div",{className:"font-mono text-[10px] space-y-0.5",children:[y.logs.slice(-8).map(($,E)=>n.jsxs("div",{className:"text-muted-foreground truncate",children:[n.jsx("span",{className:"text-muted-foreground/40 text-[9px]",children:new Date($.timestamp).toLocaleTimeString()})," ",Im($.message)]},E)),y.logs.length===0&&n.jsx("div",{className:"text-muted-foreground",children:"Waiting to start..."})]})}),n.jsxs("div",{className:"flex items-center gap-2",children:[y.status==="success"&&n.jsx(T,{size:"sm",variant:"default",className:"h-6 text-xs",onClick:$=>{$.stopPropagation(),b(y)},children:"View Assets"}),n.jsx(T,{size:"sm",variant:"ghost",className:"h-6 text-xs ml-auto",onClick:$=>{$.stopPropagation(),O(y.id)},children:n.jsx(ln,{className:"h-3 w-3"})})]})]})]},y.id)})})})]}),n.jsx(st,{open:!!l,onOpenChange:y=>{y||c()},children:n.jsx(nt,{children:(l==null?void 0:l.status)==="failed"&&((V=l==null?void 0:l.metadata)!=null&&V.authRequired)?n.jsxs(n.Fragment,{children:[n.jsxs(Xe,{children:[n.jsxs(Ze,{className:"flex items-center gap-2",children:[n.jsx(Da,{className:"h-5 w-5 text-red-500"}),"Authentication Required"]}),n.jsx(ot,{children:l.metadata.error||"Your API key has expired or is invalid. Please reconnect to publish."})]}),n.jsxs(lt,{className:"gap-2 sm:gap-0",children:[n.jsx(T,{variant:"outline",onClick:c,children:"Close"}),n.jsxs(T,{onClick:()=>{c(),e("/connection")},children:[n.jsx(Ma,{className:"h-4 w-4 mr-2"}),"Reconnect"]})]})]}):(l==null?void 0:l.type)==="publish"?n.jsxs(n.Fragment,{children:[n.jsxs(Xe,{children:[n.jsxs(Ze,{className:"flex items-center gap-2",children:[n.jsx(vt,{className:"h-5 w-5 text-green-500"}),"Publish Complete"]}),n.jsx(ot,{children:l!=null&&l.scenarioKey?`Scenario "${l.scenarioKey}" published successfully.`:"Successfully published to platform."})]}),n.jsxs(lt,{className:"gap-2 sm:gap-0",children:[n.jsx(T,{variant:"outline",onClick:c,children:"Close"}),m&&n.jsxs(T,{onClick:()=>{window.open(m,"_blank"),c()},children:[n.jsx(an,{className:"h-4 w-4 mr-2"}),"View on Platform"]})]})]}):n.jsxs(n.Fragment,{children:[n.jsxs(Xe,{children:[n.jsxs(Ze,{className:"flex items-center gap-2",children:[n.jsx(vt,{className:"h-5 w-5 text-green-500"}),"Capture Complete"]}),n.jsx(ot,{children:l!=null&&l.scenarioKey?`Scenario "${l.scenarioKey}" finished successfully.`:"All scenarios finished successfully."})]}),n.jsx("div",{className:"py-2",children:n.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground bg-muted/50 rounded-md p-3",children:[n.jsx(fi,{className:"h-4 w-4 flex-shrink-0"}),n.jsxs("span",{className:"font-mono text-xs truncate",children:[u,"/"]})]})}),n.jsxs(lt,{className:"gap-2 sm:gap-0",children:[n.jsx(T,{variant:"outline",onClick:c,children:"Close"}),n.jsx(T,{variant:"secondary",onClick:()=>{l!=null&&l.scenarioKey?e(`/scenarios/${l.scenarioKey}?tab=assets`):e("/assets"),c()},children:"Review Assets"}),n.jsxs(T,{onClick:()=>{var _;const y=l!=null&&l.scenarioKey?[l.scenarioKey]:((_=l==null?void 0:l.metadata)==null?void 0:_.scenarioKeys)||[];h(y),c(),j(!0)},children:[n.jsx(on,{className:"h-4 w-4 mr-2"}),"Publish to Platform"]})]})]})})}),n.jsx(ho,{open:C,onOpenChange:j,scenarioKeys:p.length>0?p:void 0,onConfirm:async y=>{var _;try{const F=y.reduce((A,z)=>A+z.assets.length,0),$=await fetch("/api/jobs/publish",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:p,selectedGroups:y})}),E=await $.json();if($.status===401||E.authRequired){j(!1),s({title:"Authentication Required",description:E.error||"Please reconnect to publish.",variant:"destructive"}),e("/connection");return}$.ok&&E.ok?(s({title:"Job Created",description:`Publishing ${F} asset(s). Monitor progress in the panel below.`}),j(!1),(_=E.job)!=null&&_.id&&o(E.job.id)):s({title:"Error",description:E.error||"Failed to create publish job",variant:"destructive"})}catch{s({title:"Error",description:"Failed to connect to server",variant:"destructive"})}}})]})}const u1=[{value:"platform",label:"Reshot Platform",icon:Py,description:"Managed hosting"},{value:"s3",label:"Amazon S3",icon:ih,description:"Your own bucket"},{value:"r2",label:"Cloudflare R2",icon:ih,description:"Your own bucket"},{value:"local",label:"Local Storage",icon:Vy,description:"Offline only"}];function wi({open:e,onOpenChange:t,onAuthenticated:s}){const{toast:r}=Pt(),[i,a]=d.useState("idle"),[o,l]=d.useState("platform"),[c,u]=d.useState(null),[m,f]=d.useState(null),[g,R]=d.useState(null),[k,C]=d.useState(null);d.useEffect(()=>{e&&(a("idle"),u(null),f(null),R(null),C(null))},[e]),d.useEffect(()=>{if(i!=="waiting"||!m)return;const h=setInterval(async()=>{try{const w=await(await fetch(`/api/auth/status?token=${m}`)).json();w.status==="completed"?(a("completed"),C({projectId:w.projectId,projectName:w.projectName,workspaceName:w.workspaceName}),clearInterval(h),setTimeout(()=>{s(),t(!1)},1500)):(w.status==="expired"||w.status==="invalid")&&(a("error"),R(w.error||"Authentication session expired"),clearInterval(h))}catch(x){console.error("Poll error:",x)}},2e3);return()=>clearInterval(h)},[i,m,s,t]);const j=async()=>{a("starting"),R(null);try{const x=await(await fetch("/api/auth/start",{method:"POST",headers:{"Content-Type":"application/json"}})).json();if(x.ok&&x.authUrl){u(x.authUrl),f(x.authToken),a("waiting");try{await fetch("/api/auth/open-browser",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({authUrl:x.authUrl})})}catch{}}else throw new Error(x.error||"Failed to start authentication")}catch(h){a("error"),R(h.message||"Failed to start authentication")}},p=d.useCallback(async()=>{if(c)try{await navigator.clipboard.writeText(c),r({title:"Copied",description:"Authentication URL copied to clipboard",variant:"success"})}catch{r({title:"Error",description:"Failed to copy URL",variant:"destructive"})}},[c,r]);return n.jsx(st,{open:e,onOpenChange:t,children:n.jsxs(nt,{className:"max-w-md",children:[n.jsxs(Xe,{children:[n.jsxs(Ze,{className:"flex items-center gap-2",children:[n.jsx(La,{className:"h-5 w-5"}),"Connect to Reshot Platform"]}),n.jsx(ot,{children:"Choose your storage destination and authenticate to sync your assets."})]}),n.jsxs("div",{className:"py-4 space-y-4",children:[i==="idle"&&n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsx("label",{className:"text-sm font-medium",children:"Storage Destination"}),n.jsx("div",{className:"grid grid-cols-2 gap-2",children:u1.map(h=>{const x=h.icon;return n.jsxs("button",{onClick:()=>l(h.value),className:Y("flex flex-col items-start gap-1 p-3 rounded-lg border text-left transition-colors",o===h.value?"border-primary bg-primary/5":"border-border hover:border-primary/50 hover:bg-muted/50"),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(x,{className:"h-4 w-4"}),n.jsx("span",{className:"text-sm font-medium",children:h.label})]}),n.jsx("span",{className:"text-xs text-muted-foreground",children:h.description})]},h.value)})})]}),o==="platform"&&n.jsxs(T,{onClick:j,className:"w-full",children:[n.jsx(La,{className:"h-4 w-4 mr-2"}),"Authenticate with Platform"]}),o==="s3"&&n.jsxs("div",{className:"text-center space-y-2 p-4 bg-muted/50 rounded-lg",children:[n.jsx("p",{className:"text-sm text-muted-foreground",children:"S3 storage requires configuration in your project settings."}),n.jsxs("p",{className:"text-xs text-muted-foreground",children:["Run ",n.jsx("code",{className:"bg-muted px-1 rounded",children:"reshot config --storage s3"})]})]}),o==="r2"&&n.jsxs("div",{className:"text-center space-y-2 p-4 bg-muted/50 rounded-lg",children:[n.jsx("p",{className:"text-sm text-muted-foreground",children:"Cloudflare R2 storage requires configuration in your project settings."}),n.jsxs("p",{className:"text-xs text-muted-foreground",children:["Run ",n.jsx("code",{className:"bg-muted px-1 rounded",children:"reshot config --storage r2"})]})]}),o==="local"&&n.jsxs("div",{className:"text-center space-y-2 p-4 bg-muted/50 rounded-lg",children:[n.jsx("p",{className:"text-sm text-muted-foreground",children:"Local storage keeps assets only on your machine. Great for testing."}),n.jsx(T,{variant:"outline",onClick:()=>{s(),t(!1),r({title:"Local Mode",description:"Working in local-only mode",variant:"success"})},className:"w-full mt-2",children:"Use Local Storage"})]}),n.jsx("div",{className:"pt-2 border-t border-border",children:n.jsxs("a",{href:"https://docs.reshot.dev/reference/cli",target:"_blank",rel:"noopener noreferrer",className:"flex items-center justify-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors",children:[n.jsx(an,{className:"h-3 w-3"}),"View CLI Documentation"]})})]}),i==="starting"&&n.jsxs("div",{className:"text-center space-y-4 py-4",children:[n.jsx(_e,{className:"h-8 w-8 animate-spin mx-auto text-primary"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"Starting authentication..."})]}),i==="waiting"&&c&&n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"text-center space-y-2",children:[n.jsx(_e,{className:"h-8 w-8 animate-spin mx-auto text-primary"}),n.jsx("p",{className:"text-sm font-medium",children:"Complete authentication in your browser"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"A browser window should have opened. Select a project to link."})]}),n.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 space-y-2",children:[n.jsx("p",{className:"text-xs text-muted-foreground",children:"If the browser didn't open, click below or copy the URL:"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsxs(T,{variant:"outline",size:"sm",className:"flex-1",onClick:()=>window.open(c,"_blank"),children:[n.jsx(an,{className:"h-3 w-3 mr-1"}),"Open in Browser"]}),n.jsx(T,{variant:"outline",size:"sm",onClick:p,children:n.jsx(rn,{className:"h-3 w-3"})})]})]})]}),i==="completed"&&k&&n.jsxs("div",{className:"text-center space-y-4 py-4",children:[n.jsx(Ry,{className:"h-12 w-12 mx-auto text-green-500"}),n.jsxs("div",{children:[n.jsx("p",{className:"font-medium",children:"Successfully Connected!"}),n.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Linked to"," ",k.workspaceName&&`${k.workspaceName} / `,k.projectName]})]})]}),i==="error"&&n.jsxs("div",{className:"text-center space-y-4 py-4",children:[n.jsx(Jt,{className:"h-12 w-12 mx-auto text-destructive"}),n.jsxs("div",{children:[n.jsx("p",{className:"font-medium",children:"Authentication Failed"}),n.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:g||"Something went wrong"})]}),n.jsx(T,{onClick:j,variant:"outline",children:"Try Again"})]})]})]})})}function h1({status:e,className:t}){const s=()=>{switch(e){case"success":return n.jsx(vt,{className:"h-3 w-3"});case"failed":return n.jsx(Da,{className:"h-3 w-3"});case"running":return n.jsx(_e,{className:"h-3 w-3 animate-spin"});default:return n.jsx(hi,{className:"h-3 w-3"})}},r=()=>{switch(e){case"success":return"default";case"failed":return"destructive";default:return"secondary"}};return n.jsxs(ue,{variant:r(),className:Y("text-[10px] h-5 px-2 font-medium flex items-center gap-1",t),children:[s(),e]})}const ve=d.forwardRef(({className:e,type:t,...s},r)=>n.jsx("input",{type:t,className:Y("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...s}));ve.displayName="Input";function f1({open:e,onOpenChange:t,workspaceScenarios:s,allScenarios:r,onScenariosChange:i}){const{toast:a}=Pt(),[o,l]=d.useState(""),[c,u]=d.useState("name"),[m,f]=d.useState("all"),[g,R]=d.useState(new Set);d.useEffect(()=>{e&&l("")},[e]);const k=N=>s.includes(N),C=d.useMemo(()=>{let N=[...r];if(o){const S=o.toLowerCase();N=N.filter(P=>{var b;return P.name.toLowerCase().includes(S)||P.key.toLowerCase().includes(S)||((b=P.url)==null?void 0:b.toLowerCase().includes(S))})}return m==="in-workspace"?N=N.filter(S=>k(S.key)):m==="not-in-workspace"&&(N=N.filter(S=>!k(S.key))),N.sort((S,P)=>{var b,O;switch(c){case"name":return S.name.localeCompare(P.name);case"key":return S.key.localeCompare(P.key);case"steps":return(((b=P.steps)==null?void 0:b.length)||0)-(((O=S.steps)==null?void 0:O.length)||0);default:return 0}}),N},[r,o,m,c,s]),j=async N=>{const S=k(N);R(P=>new Set(P).add(N));try{if(S){const P=await fetch(`/api/workspace/scenarios/${encodeURIComponent(N)}`,{method:"DELETE"});if(!P.ok){const b=await P.json();throw new Error(b.error||"Failed to remove scenario")}a({title:"Removed",description:`${N} removed from workspace`})}else{const P=await fetch("/api/workspace/scenarios",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:[N]})});if(!P.ok){const b=await P.json();throw new Error(b.error||"Failed to add scenario")}a({title:"Added",description:`${N} added to workspace`})}i()}catch(P){const b=P instanceof Error?P.message:"Operation failed";a({title:"Error",description:b,variant:"destructive"})}finally{R(P=>{const b=new Set(P);return b.delete(N),b})}},p=async()=>{const N=C.filter(S=>!k(S.key));if(N.length!==0){R(new Set(N.map(S=>S.key)));try{const S=await fetch("/api/workspace/scenarios",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:N.map(P=>P.key)})});if(!S.ok){const P=await S.json();throw new Error(P.error||"Failed to add scenarios")}a({title:"Added",description:`Added ${N.length} scenarios to workspace`}),i()}catch(S){const P=S instanceof Error?S.message:"Operation failed";a({title:"Error",description:P,variant:"destructive"})}finally{R(new Set)}}},h=async()=>{const N=C.filter(S=>k(S.key));if(N.length!==0){R(new Set(N.map(S=>S.key)));try{for(const S of N)await fetch(`/api/workspace/scenarios/${encodeURIComponent(S.key)}`,{method:"DELETE"});a({title:"Removed",description:`Removed ${N.length} scenarios from workspace`}),i()}catch(S){const P=S instanceof Error?S.message:"Operation failed";a({title:"Error",description:P,variant:"destructive"})}finally{R(new Set)}}},x=r.filter(N=>k(N.key)).length,w=r.length-x;return n.jsx(st,{open:e,onOpenChange:t,children:n.jsxs(nt,{className:"max-w-2xl max-h-[85vh] flex flex-col",children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:"Manage Workspace Scenarios"}),n.jsxs(ot,{children:["Add or remove scenarios from your workspace. ",x," of"," ",r.length," scenarios selected."]})]}),n.jsxs("div",{className:"space-y-3 py-2",children:[n.jsxs("div",{className:"relative",children:[n.jsx(Zc,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),n.jsx(ve,{placeholder:"Search scenarios...",value:o,onChange:N=>l(N.target.value),className:"pl-9"})]}),n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsxs("div",{className:"flex items-center gap-1 text-xs",children:[n.jsx(Ly,{className:"h-3.5 w-3.5 text-muted-foreground"}),n.jsxs(T,{variant:m==="all"?"secondary":"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>f("all"),children:["All (",r.length,")"]}),n.jsxs(T,{variant:m==="in-workspace"?"secondary":"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>f("in-workspace"),children:["In Workspace (",x,")"]}),n.jsxs(T,{variant:m==="not-in-workspace"?"secondary":"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>f("not-in-workspace"),children:["Available (",w,")"]})]}),n.jsx("div",{className:"flex-1"}),n.jsxs("div",{className:"flex items-center gap-1 text-xs",children:[n.jsx(Gc,{className:"h-3.5 w-3.5 text-muted-foreground"}),n.jsx(T,{variant:c==="name"?"secondary":"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>u("name"),children:"Name"}),n.jsx(T,{variant:c==="key"?"secondary":"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>u("key"),children:"Key"}),n.jsx(T,{variant:c==="steps"?"secondary":"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>u("steps"),children:"Steps"})]})]}),C.length>0&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:p,disabled:C.every(N=>k(N.key))||g.size>0,children:[n.jsx(as,{className:"h-3 w-3 mr-1"}),"Add All Visible"]}),n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:h,disabled:!C.some(N=>k(N.key))||g.size>0,children:[n.jsx(Zp,{className:"h-3 w-3 mr-1"}),"Remove All Visible"]})]})]}),n.jsx("div",{className:"flex-1 overflow-y-auto min-h-0 -mx-6 px-6",children:C.length===0?n.jsx("div",{className:"text-center py-8 text-muted-foreground text-sm",children:o?"No scenarios match your search":"No scenarios available"}):n.jsx("div",{className:"space-y-1 pb-4",children:C.map(N=>{var b;const S=k(N.key),P=g.has(N.key);return n.jsxs("div",{className:Y("flex items-center gap-3 p-3 rounded-lg border transition-colors cursor-pointer",S?"bg-primary/5 border-primary/20 hover:bg-primary/10":"bg-card border-border hover:bg-accent/50"),onClick:()=>!P&&j(N.key),children:[n.jsx("div",{className:Y("w-5 h-5 rounded border flex items-center justify-center transition-colors",S?"bg-primary border-primary":"border-muted-foreground/30"),children:P?n.jsx(_e,{className:"h-3 w-3 animate-spin text-primary-foreground"}):S?n.jsx(ro,{className:"h-3 w-3 text-primary-foreground"}):null}),n.jsx(Rn,{className:"h-4 w-4 text-muted-foreground shrink-0"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm font-medium truncate",children:N.name}),n.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:N.key})]}),N.url&&n.jsx("p",{className:"text-xs text-muted-foreground truncate",children:N.url})]}),n.jsxs(ue,{variant:"secondary",className:"text-xs shrink-0",children:[((b=N.steps)==null?void 0:b.length)||0," steps"]})]},N.key)})})}),n.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[n.jsxs("p",{className:"text-sm text-muted-foreground",children:[x," scenario",x!==1?"s":""," in workspace"]}),n.jsx(T,{onClick:()=>t(!1),children:"Done"})]})]})})}function p1(){var V,y,_,F,$;const{toast:e}=Pt(),{trackJob:t}=ji(),[s,r]=d.useState({workspace:null,allScenarios:[],assetGroups:[],jobs:[],settings:null,loading:!0,error:null}),[i,a]=d.useState(new Set),[o,l]=d.useState(!1),[c,u]=d.useState(!1),[m,f]=d.useState(!1),[g,R]=d.useState(new Set),[k,C]=d.useState(!1),[j,p]=d.useState(0),h=d.useCallback(async(E=!1)=>{var A,z;try{E&&C(!0);const[W,J,G,fe]=await Promise.all([fetch("/api/status"),fetch("/api/workspace"),fetch("/api/output"),fetch("/api/config")]);if(!W.ok)throw new Error(`Status API failed: ${W.status}`);const[ye,ge,Re,U]=await Promise.all([W.json(),J.json(),G.json(),fe.json()]);let X=ge.workspace;if(!X){const ce=await fetch("/api/workspace",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:"Default Workspace"})});ce.ok&&(X=(await ce.json()).workspace)}const Z=((A=X==null?void 0:X.allScenarios)==null?void 0:A.length)>0?X.allScenarios:((z=U.config)==null?void 0:z.scenarios)||[];r({workspace:X,allScenarios:Z,assetGroups:Re.groups||[],jobs:ye.jobs||[],settings:ye.settings||null,loading:!1,error:null}),E&&e({title:"Refreshed",description:"Data updated successfully"})}catch(W){const J=W instanceof Error?W.message:"Failed to load data";console.error("Failed to load data:",W),r(G=>({...G,loading:!1,error:J})),E&&e({title:"Error",description:J,variant:"destructive"})}finally{C(!1)}},[e]);d.useEffect(()=>{h()},[h]),d.useEffect(()=>{if(!s.jobs.some(z=>z.status==="running"||z.status==="pending")&&j===0)return;const A=setInterval(()=>h(!1),3e3);return()=>clearInterval(A)},[s.jobs,h,j]);const x=async E=>{try{const A=await fetch("/api/workspace/scenarios",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:[E]})});if(!A.ok){const W=await A.json();throw new Error(W.error||"Failed to add scenario")}const z=await A.json();z.workspace&&(r(W=>({...W,workspace:z.workspace})),e({title:"Added",description:`Added ${E} to workspace`}))}catch(A){const z=A instanceof Error?A.message:"Failed to add scenario";console.error("Add scenario error:",A),e({title:"Error",description:z,variant:"destructive"})}},w=async E=>{try{const A=await fetch(`/api/workspace/scenarios/${encodeURIComponent(E)}`,{method:"DELETE"});if(!A.ok){const W=await A.json();throw new Error(W.error||"Failed to remove scenario")}const z=await A.json();z.workspace&&(r(W=>({...W,workspace:z.workspace})),e({title:"Removed",description:`Removed ${E} from workspace`}))}catch(A){const z=A instanceof Error?A.message:"Failed to remove scenario";console.error("Remove scenario error:",A),e({title:"Error",description:z,variant:"destructive"})}},N=async E=>{R(A=>new Set(A).add(E));try{const A=await fetch("/api/jobs/run",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:[E]})}),z=await A.json();if(!A.ok)throw new Error(z.error||`Failed to start capture (${A.status})`);if(z.ok&&z.job)t(z.job.id,E),await h(!1),p(W=>W+1),setTimeout(()=>p(0),1e4);else throw new Error(z.error||"Unknown error starting job")}catch(A){const z=A instanceof Error?A.message:"Failed to start capture";console.error("Run scenario error:",A),e({title:"Capture Failed",description:z,variant:"destructive"})}finally{R(A=>{const z=new Set(A);return z.delete(E),z})}},S=E=>{a(A=>{const z=new Set(A);return z.has(E)?z.delete(E):z.add(E),z})},P=E=>s.assetGroups.filter(A=>A.scenarioKey===E),b=((V=s.workspace)==null?void 0:V.resolvedScenarios)||[],O=s.allScenarios.filter(E=>{var A,z;return!((z=(A=s.workspace)==null?void 0:A.scenarios)!=null&&z.includes(E.key))}),D=((y=s.settings)==null?void 0:y.isAuthenticated)||!1,v=s.assetGroups.length>0,L=s.jobs.filter(E=>E.status==="running"||E.status==="pending");return s.loading?n.jsx("div",{className:"flex items-center justify-center h-full",children:n.jsxs("div",{className:"text-center",children:[n.jsx(_e,{className:"h-8 w-8 animate-spin text-muted-foreground mx-auto mb-3"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading workspace..."})]})}):s.error&&!s.workspace?n.jsx("div",{className:"flex items-center justify-center h-full p-6",children:n.jsx(he,{className:"max-w-md w-full",children:n.jsxs(me,{className:"pt-6 text-center",children:[n.jsx(Jt,{className:"h-10 w-10 text-destructive mx-auto mb-3"}),n.jsx("h2",{className:"text-lg font-semibold mb-2",children:"Failed to Load"}),n.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:s.error}),n.jsxs(T,{onClick:()=>h(!0),children:[n.jsx(_t,{className:"h-4 w-4 mr-2"}),"Retry"]})]})})}):n.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[n.jsx("div",{className:"shrink-0 px-6 py-4 border-b border-border bg-background",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("h1",{className:"text-lg font-semibold text-foreground",children:((_=s.workspace)==null?void 0:_.name)||"Workspace"}),n.jsxs("p",{className:"text-sm text-muted-foreground",children:[b.length," scenario",b.length!==1?"s":"",v&&` • ${s.assetGroups.length} captured variant${s.assetGroups.length!==1?"s":""}`]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(T,{variant:"outline",size:"icon",onClick:()=>h(!0),disabled:k,title:"Refresh",children:n.jsx(_t,{className:Y("h-4 w-4",k&&"animate-spin")})}),n.jsxs(T,{variant:"outline",size:"sm",onClick:()=>f(!0),className:"gap-1.5",children:[n.jsx(Yy,{className:"h-3.5 w-3.5"}),"Manage Scenarios"]}),D&&n.jsxs(T,{size:"sm",onClick:()=>u(!0),disabled:!v,className:"gap-1.5",children:[n.jsx(on,{className:"h-3.5 w-3.5"}),"Commit"]})]})]})}),n.jsxs("div",{className:"flex-1 overflow-auto p-6 space-y-6",children:[!D&&n.jsx(he,{className:"border-yellow-500/30 bg-yellow-50/5",children:n.jsx(me,{className:"py-4",children:n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("div",{className:"p-2 rounded-full bg-yellow-500/10",children:n.jsx(em,{className:"h-4 w-4 text-yellow-500"})}),n.jsxs("div",{className:"flex-1",children:[n.jsx("p",{className:"text-sm font-medium text-foreground",children:"Connect to Platform"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Authenticate to publish assets and sync with the platform"})]}),n.jsx(T,{size:"sm",variant:"outline",onClick:()=>l(!0),children:"Connect"})]})})}),L.length>0&&n.jsxs(he,{children:[n.jsx(ke,{className:"py-3 px-4",children:n.jsxs(be,{className:"text-sm font-medium flex items-center gap-2",children:[n.jsx(_e,{className:"h-4 w-4 animate-spin"}),"Active Jobs"]})}),n.jsx(me,{className:"px-4 pb-4",children:n.jsx("div",{className:"space-y-2",children:L.map(E=>n.jsxs("div",{className:"flex items-center justify-between p-2 rounded-md bg-muted/50",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(h1,{status:E.status}),n.jsxs("span",{className:"text-sm",children:[E.type==="run"?"Capturing":E.type,E.scenarioKey&&`: ${E.scenarioKey}`]})]}),E.progress!==void 0&&n.jsxs("span",{className:"text-xs text-muted-foreground",children:[E.progress,"%"]})]},E.id))})})]}),n.jsxs("section",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(fi,{className:"h-4 w-4 text-muted-foreground"}),n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Workspace Scenarios"})]}),n.jsxs("button",{onClick:()=>f(!0),className:"text-xs text-muted-foreground hover:text-foreground",children:["View all ",s.allScenarios.length," scenarios →"]})]}),b.length===0?n.jsx(he,{className:"border-dashed",children:n.jsxs(me,{className:"py-8 text-center",children:[n.jsx(fi,{className:"h-8 w-8 mx-auto text-muted-foreground/50 mb-3"}),n.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"No scenarios in workspace"}),n.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Add scenarios to start capturing and publishing visuals"}),n.jsxs(T,{variant:"outline",size:"sm",onClick:()=>f(!0),children:[n.jsx(as,{className:"h-3.5 w-3.5 mr-1.5"}),"Add First Scenario"]})]})}):n.jsx("div",{className:"space-y-2",children:b.map(E=>{const A=P(E.key),z=i.has(E.key),W=g.has(E.key)||L.some(J=>J.scenarioKey===E.key);return n.jsxs(he,{className:"overflow-hidden",children:[n.jsxs("div",{className:Y("flex items-center gap-3 px-4 py-3 cursor-pointer hover:bg-accent/50 transition-colors",z&&"bg-accent/30"),onClick:()=>S(E.key),children:[n.jsx("button",{className:"text-muted-foreground",children:z?n.jsx(zs,{className:"h-4 w-4"}):n.jsx(Ps,{className:"h-4 w-4"})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm font-medium text-foreground",children:E.name||E.key}),n.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:E.key})]}),E.url&&n.jsx("p",{className:"text-xs text-muted-foreground truncate",children:E.url})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[A.length>0&&n.jsxs(ue,{variant:"secondary",className:"text-xs",children:[A.reduce((J,G)=>J+G.assets.length,0)," ","assets"]}),n.jsxs("div",{className:"flex items-center gap-1",onClick:J=>J.stopPropagation(),children:[n.jsx(T,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>N(E.key),disabled:W,children:W?n.jsx(_e,{className:"h-3.5 w-3.5 animate-spin"}):n.jsx(Ts,{className:"h-3.5 w-3.5"})}),n.jsx(T,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>w(E.key),children:n.jsx(ps,{className:"h-3.5 w-3.5"})})]})]})]}),z&&n.jsxs("div",{className:"border-t border-border bg-muted/30 px-4 py-3",children:[A.length===0?n.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[n.jsx(Jt,{className:"h-3.5 w-3.5"}),"No captures yet. Click play to run this scenario."]}):n.jsx("div",{className:"space-y-3",children:A.map((J,G)=>n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[n.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:J.variationSlug==="default"?"Default":J.variationSlug}),n.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",J.assets.length," file",J.assets.length!==1?"s":"",")"]})]}),n.jsxs("div",{className:"grid grid-cols-4 sm:grid-cols-6 md:grid-cols-8 gap-2",children:[J.assets.slice(0,8).map((fe,ye)=>n.jsx(Kt,{to:`/assets/${J.scenarioKey}/${J.variationSlug}/${fe.captureKey}`,className:"aspect-video rounded-md overflow-hidden border border-border hover:border-primary/50 transition-colors",children:fe.filename.endsWith(".mp4")?n.jsx("div",{className:"w-full h-full bg-muted flex items-center justify-center",children:n.jsx(io,{className:"h-4 w-4 text-muted-foreground"})}):n.jsx("img",{src:fe.url,alt:fe.captureKey,className:"w-full h-full object-cover"})},ye)),J.assets.length>8&&n.jsx(Kt,{to:"/assets",className:"aspect-video rounded-md overflow-hidden border border-border bg-muted flex items-center justify-center hover:bg-accent transition-colors",children:n.jsxs("span",{className:"text-xs text-muted-foreground",children:["+",J.assets.length-8]})})]})]},`${J.scenarioKey}-${J.variationSlug}-${G}`))}),n.jsx("div",{className:"mt-3 pt-3 border-t border-border",children:n.jsx(Kt,{to:`/scenarios/${E.key}`,className:"text-xs text-primary hover:underline",children:"Edit scenario →"})})]})]},E.key)})})]}),O.length>0&&b.length>0&&n.jsxs("section",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(as,{className:"h-4 w-4 text-muted-foreground"}),n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Quick Add"})]}),n.jsx("button",{onClick:()=>f(!0),className:"text-xs text-muted-foreground hover:text-foreground",children:"Manage all →"})]}),n.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2",children:O.slice(0,3).map(E=>n.jsxs("button",{onClick:()=>x(E.key),className:"flex items-center gap-3 p-3 rounded-lg border border-border bg-card hover:bg-accent/50 transition-colors text-left group",children:[n.jsx("div",{className:"p-1.5 rounded bg-muted group-hover:bg-primary/10 transition-colors",children:n.jsx(as,{className:"h-3.5 w-3.5 text-muted-foreground group-hover:text-primary"})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-foreground truncate",children:E.name||E.key}),n.jsx("div",{className:"text-xs text-muted-foreground font-mono truncate",children:E.key})]})]},E.key))})]}),((F=s.workspace)==null?void 0:F.commits)&&s.workspace.commits.length>0&&n.jsxs("section",{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n.jsx(vt,{className:"h-4 w-4 text-muted-foreground"}),n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Recent Commits"})]}),n.jsx("div",{className:"space-y-2",children:s.workspace.commits.slice(-3).reverse().map(E=>n.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-border bg-card",children:[n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-foreground truncate",children:E.message}),n.jsxs("div",{className:"text-xs text-muted-foreground",children:[E.scenarioKeys.length," scenario",E.scenarioKeys.length!==1?"s":""," • ",E.assetCount," asset",E.assetCount!==1?"s":""," • ",new Date(E.createdAt).toLocaleDateString()]})]}),E.platformCommitId?n.jsx(ue,{variant:"secondary",className:"text-xs bg-green-500/10 text-green-500",children:"Synced"}):n.jsx(ue,{variant:"secondary",className:"text-xs",children:"Local"})]},E.id))})]})]}),n.jsx(wi,{open:o,onOpenChange:l,onAuthenticated:h}),n.jsx(f1,{open:m,onOpenChange:f,workspaceScenarios:(($=s.workspace)==null?void 0:$.scenarios)||[],allScenarios:s.allScenarios,onScenariosChange:h}),n.jsx(ho,{open:c,onOpenChange:u,onConfirm:async(E,A)=>{var z;try{const W=await fetch("/api/jobs/publish",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({selectedGroups:E,commitMessage:A})}),J=await W.json();if(W.status===401||J.authRequired){u(!1),e({title:"Authentication Required",description:"Your API key has expired. Please reconnect.",variant:"destructive"}),l(!0);return}W.ok&&J.ok?(u(!1),(z=J.job)!=null&&z.id&&t(J.job.id),h(),p(G=>G+1),setTimeout(()=>p(0),1e4)):e({title:"Error",description:J.error||"Failed to create publish job",variant:"destructive"})}catch{e({title:"Error",description:"Failed to connect to server",variant:"destructive"})}}})]})}const q=d.forwardRef(({className:e,...t},s)=>n.jsx("label",{ref:s,className:Y("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",e),...t}));q.displayName="Label";function Fm(e){const t=d.useRef(!1);return d.useCallback(async()=>{if(!t.current){t.current=!0;try{await e()}finally{t.current=!1}}},[e])}function yh(e){if(!e)return"Never";const t=new Date(e),r=new Date().getTime()-t.getTime(),i=Math.floor(r/(1e3*60)),a=Math.floor(r/(1e3*60*60)),o=Math.floor(r/(1e3*60*60*24));return i<1?"Just now":i<60?`${i}m ago`:a<24?`${a}h ago`:o<7?`${o}d ago`:t.toLocaleDateString()}function Pr(e){if(e.category)return e.category;const s=(e.key||"").split("-");return s.length>=2?s[0]:"other"}function m1(e){return e.split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function x1(){const e=Os(),{toast:t}=Pt(),{trackJob:s}=ji(),[r,i]=d.useState([]),[a,o]=d.useState(!0),[l,c]=d.useState(!1),[u,m]=d.useState({name:"",key:"",url:""}),[f,g]=d.useState(!1),[R,k]=d.useState(""),[C,j]=d.useState("grouped"),[p,h]=d.useState(new Set),[x,w]=d.useState(new Set),[N,S]=d.useState(!1),[P,b]=d.useState(!1),[O,D]=d.useState(null),[v,L]=d.useState({}),[V,y]=d.useState(!0),[_,F]=d.useState("step-by-step-images"),[$,E]=d.useState(null),[A,z]=d.useState(!0),[W,J]=d.useState(!1),[G,fe]=d.useState("scenarios"),[ye,ge]=d.useState(""),[Re,U]=d.useState("lastRun"),[X,Z]=d.useState(!1),ce=d.useCallback(async()=>{var B,oe,se;o(!0);try{const[re,qe]=await Promise.all([fetch("/api/scenarios/metadata"),fetch("/api/config")]),[De,At]=await Promise.all([re.json(),qe.json()]);if(i(De.scenarios||[]),D(((B=At.config)==null?void 0:B.variants)||null),z(((se=(oe=At.config)==null?void 0:oe.diffing)==null?void 0:se.enabled)!==!1),x.size===0){const I=new Set((De.scenarios||[]).map(ee=>Pr(ee)));w(I)}}catch(re){console.error("Failed to load scenarios:",re)}finally{o(!1)}},[x.size]);d.useEffect(()=>{ce()},[ce]);const ie=Fm(ce),ae=async()=>{try{const oe=await fetch(G==="scenarios"?"/api/config/scenarios":"/api/assets",{method:"DELETE"}),se=await oe.json();oe.ok?(t({title:"Success",description:G==="scenarios"?`Deleted ${se.deleted} scenario(s)`:`Deleted ${se.deleted} asset file(s)`,variant:"success"}),J(!1),G==="scenarios"&&ce()):t({title:"Error",description:se.error||"Failed to delete",variant:"destructive"})}catch(B){console.error("Failed to bulk delete:",B),t({title:"Error",description:"Failed to perform bulk delete",variant:"destructive"})}},Se=d.useMemo(()=>{let B=[...r];if(ye){const oe=ye.toLowerCase();B=B.filter(se=>se.name.toLowerCase().includes(oe)||se.key.toLowerCase().includes(oe)||se.url.toLowerCase().includes(oe)||Pr(se).toLowerCase().includes(oe))}return B.sort((oe,se)=>{var qe,De,At,I,ee,pe;let re=0;switch(Re){case"name":re=oe.name.localeCompare(se.name);break;case"key":re=oe.key.localeCompare(se.key);break;case"steps":re=(((qe=oe.steps)==null?void 0:qe.length)||0)-(((De=se.steps)==null?void 0:De.length)||0);break;case"lastRun":const Ce=((At=oe._metadata)==null?void 0:At.lastRunAt)||((I=oe._metadata)==null?void 0:I.createdAt)||"",Oe=((ee=se._metadata)==null?void 0:ee.lastRunAt)||((pe=se._metadata)==null?void 0:pe.createdAt)||"";re=Ce.localeCompare(Oe);break}return X?re:-re}),B},[r,ye,Re,X]),Ie=d.useMemo(()=>{const B={};for(const se of Se){const re=Pr(se);B[re]||(B[re]=[]),B[re].push(se)}return Object.entries(B).sort(([se],[re])=>se==="other"?1:re==="other"?-1:se.localeCompare(re)).map(([se,re])=>({key:se,name:m1(se),scenarios:re,isExpanded:x.has(se)}))},[Se,x]),mt=B=>{w(oe=>{const se=new Set(oe);return se.has(B)?se.delete(B):se.add(B),se})},Nt=B=>{h(oe=>{const se=new Set(oe);return se.has(B)?se.delete(B):se.add(B),se})},Ft=B=>{const oe=B.scenarios.map(re=>re.key),se=oe.every(re=>p.has(re));h(re=>{const qe=new Set(re);return se?oe.forEach(De=>qe.delete(De)):oe.forEach(De=>qe.add(De)),qe})},Yt=()=>{const B=Se.map(oe=>oe.key);h(new Set(B))},$t=()=>{h(new Set)},kt=async()=>{if(p.size===0){t({title:"No scenarios selected",description:"Please select at least one scenario to run",variant:"destructive"});return}b(!0);try{const oe={scenarioKeys:Array.from(p),format:_,diff:$===null?A:$};!V&&Object.keys(v).length>0&&(oe.variant=v);const se=await fetch("/api/jobs/run",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(oe)}),re=await se.json();if(!se.ok)throw new Error(re.error||"Failed to start capture job");re.job&&(s(re.job.id,`${p.size} scenarios`),S(!1),$t())}catch(B){const oe=B instanceof Error?B.message:"Failed to start capture";t({title:"Error",description:oe,variant:"destructive"})}finally{b(!1)}},Tt=B=>{Re===B?Z(!X):(U(B),Z(!0))},Vt=async()=>{var B;if(!u.name||!u.key||!u.url){t({title:"Error",description:"Please fill in all required fields",variant:"destructive"});return}if(!/^[a-z0-9-]+$/.test(u.key)){t({title:"Error",description:"Key must contain only lowercase letters, numbers, and hyphens",variant:"destructive"});return}try{const oe=await fetch("/api/config/scenarios",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...u,steps:[]})});if(oe.ok){t({title:"Success",description:"Scenario created successfully",variant:"success"}),c(!1),m({name:"",key:"",url:""});const re=await(await fetch("/api/config")).json();i(((B=re.config)==null?void 0:B.scenarios)||[]),e(`/scenarios/${u.key}`)}else{const se=await oe.json();t({title:"Error",description:se.error||"Failed to create scenario",variant:"destructive"})}}catch(oe){console.error("Failed to create scenario:",oe),t({title:"Error",description:"Failed to create scenario",variant:"destructive"})}},je=B=>B.toLowerCase().replace(/[^a-z0-9\s-]/g,"").trim().replace(/\s+/g,"-").replace(/-+/g,"-");return n.jsxs("div",{"data-testid":"studio-scenarios","data-loaded":"true",className:"p-5 space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 pb-3",children:[n.jsxs("div",{children:[n.jsx("h1",{className:"text-xl font-bold tracking-tight",children:"Scenarios"}),n.jsxs("p",{className:"text-xs text-muted-foreground mt-1 font-normal",children:[r.length," scenarios in ",Ie.length," categories"]})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx(T,{variant:"outline",size:"icon",onClick:ie,title:"Refresh",className:"shadow-sm",disabled:a,children:n.jsx(_t,{className:`h-4 w-4 ${a?"animate-spin":""}`})}),n.jsxs(T,{variant:"outline",size:"sm",onClick:()=>{fe("scenarios"),J(!0)},title:"Delete all scenarios",className:"shadow-sm text-destructive hover:text-destructive",children:[n.jsx(ps,{className:"h-3.5 w-3.5 mr-1.5"}),"Delete All"]}),n.jsxs(T,{size:"sm",onClick:()=>e("/recorder"),className:"shadow-sm",children:[n.jsx(as,{className:"h-3.5 w-3.5 mr-1.5"}),"New Scenario"]})]})]}),r.length>0&&n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[n.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-md",children:[n.jsx(Zc,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),n.jsx(ve,{placeholder:"Search scenarios or categories...",value:ye,onChange:B=>ge(B.target.value),className:"pl-9 h-9"})]}),n.jsxs("div",{className:"flex items-center gap-1 border rounded-md p-0.5",children:[n.jsxs(T,{variant:C==="grouped"?"secondary":"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>j("grouped"),children:[n.jsx(Kr,{className:"h-3 w-3 mr-1"}),"Grouped"]}),n.jsxs(T,{variant:C==="flat"?"secondary":"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>j("flat"),children:[n.jsx(Rn,{className:"h-3 w-3 mr-1"}),"Flat"]})]}),n.jsxs("div",{className:"flex items-center gap-1 text-xs",children:[n.jsx(Gc,{className:"h-3.5 w-3.5 text-muted-foreground mr-1"}),n.jsxs(T,{variant:Re==="lastRun"?"secondary":"ghost",size:"sm",className:"h-8 text-xs",onClick:()=>Tt("lastRun"),children:["Last Run ",Re==="lastRun"&&(X?"↑":"↓")]}),n.jsxs(T,{variant:Re==="name"?"secondary":"ghost",size:"sm",className:"h-8 text-xs",onClick:()=>Tt("name"),children:["Name ",Re==="name"&&(X?"↑":"↓")]})]})]}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(T,{variant:"ghost",size:"sm",className:"h-8 text-xs",onClick:p.size>0?$t:Yt,children:p.size>0?n.jsxs(n.Fragment,{children:[n.jsx(ed,{className:"h-3.5 w-3.5 mr-1"}),"Clear (",p.size,")"]}):n.jsxs(n.Fragment,{children:[n.jsx(Qc,{className:"h-3.5 w-3.5 mr-1"}),"Select All"]})}),p.size>0&&n.jsxs(ue,{variant:"secondary",className:"text-xs",children:[p.size," selected"]})]}),p.size>0&&n.jsxs(T,{size:"sm",onClick:()=>S(!0),className:"gap-1.5",children:[n.jsx(Ts,{className:"h-3.5 w-3.5"}),"Run Selected (",p.size,")"]})]})]}),a?n.jsx("div",{className:"text-muted-foreground",children:"Loading scenarios..."}):r.length===0?n.jsxs(he,{children:[n.jsxs(ke,{children:[n.jsx(be,{children:"No Scenarios"}),n.jsx(at,{children:"Create your first scenario to get started"})]}),n.jsx(me,{children:n.jsxs(T,{onClick:()=>c(!0),children:[n.jsx(as,{className:"h-4 w-4 mr-2"}),"Create Scenario"]})})]}):Se.length===0?n.jsx(he,{children:n.jsxs(me,{className:"py-8 text-center",children:[n.jsxs("p",{className:"text-muted-foreground",children:['No scenarios match "',ye,'"']}),n.jsx(T,{variant:"link",onClick:()=>ge(""),children:"Clear search"})]})}):C==="grouped"?n.jsx("div",{className:"space-y-4",children:Ie.map(B=>{const oe=B.scenarios.every(re=>p.has(re.key)),se=B.scenarios.some(re=>p.has(re.key));return n.jsxs(he,{className:"overflow-hidden",children:[n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 bg-muted/30 border-b cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>mt(B.key),children:[n.jsx(ns,{checked:oe,className:Y("data-[state=indeterminate]:bg-primary/50",se&&!oe&&"data-[state=checked]:bg-primary/50"),onClick:re=>{re.stopPropagation(),Ft(B)}}),n.jsxs("div",{className:"flex items-center gap-2 flex-1",children:[B.isExpanded?n.jsx(zs,{className:"h-4 w-4 text-muted-foreground"}):n.jsx(Ps,{className:"h-4 w-4 text-muted-foreground"}),n.jsx(fi,{className:"h-4 w-4 text-muted-foreground"}),n.jsx("span",{className:"font-medium text-sm",children:B.name}),n.jsx(ue,{variant:"secondary",className:"text-xs",children:B.scenarios.length})]})]}),B.isExpanded&&n.jsx("div",{className:"divide-y",children:B.scenarios.map(re=>{var qe,De;return n.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 hover:bg-muted/20 transition-colors",children:[n.jsx(ns,{checked:p.has(re.key),onClick:At=>{At.stopPropagation(),Nt(re.key)}}),n.jsx(Kt,{to:`/scenarios/${re.key}`,className:"flex-1 min-w-0 group",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"text-sm font-medium group-hover:text-primary transition-colors truncate",children:re.name}),n.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[n.jsx("span",{className:"font-mono",children:re.key}),n.jsx("span",{children:"•"}),n.jsxs("span",{children:[((qe=re.steps)==null?void 0:qe.length)||0," steps"]}),n.jsx("span",{children:"•"}),n.jsx(hi,{className:"h-3 w-3"}),n.jsx("span",{children:yh(((De=re._metadata)==null?void 0:De.lastRunAt)||null)})]})]}),n.jsx(Ps,{className:"h-4 w-4 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity"})]})})]},re.key)})})]},B.key)})}):n.jsx("div",{className:"grid gap-3 md:grid-cols-2 lg:grid-cols-3",children:Se.map(B=>{var oe,se;return n.jsxs("div",{className:"relative",children:[n.jsx("div",{className:"absolute top-3 left-3 z-10",children:n.jsx(ns,{checked:p.has(B.key),onClick:re=>{re.stopPropagation(),Nt(B.key)},className:"bg-background"})}),n.jsx(Kt,{to:`/scenarios/${B.key}`,children:n.jsxs(he,{className:"dagster-card cursor-pointer group",children:[n.jsxs(ke,{className:"px-4 py-3 pl-10",children:[n.jsxs("div",{className:"flex items-start justify-between",children:[n.jsx(be,{className:"text-sm font-semibold group-hover:text-primary transition-colors",children:B.name}),n.jsx(Rn,{className:"h-3.5 w-3.5 text-muted-foreground group-hover:text-primary transition-colors"})]}),n.jsx(at,{className:"font-mono text-[10px] mt-1 text-muted-foreground",children:B.key})]}),n.jsx(me,{className:"px-4 pb-3",children:n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[n.jsx(ue,{variant:"outline",className:"text-[10px]",children:Pr(B)}),n.jsx("span",{children:"•"}),n.jsx("span",{className:"font-medium",children:((oe=B.steps)==null?void 0:oe.length)||0}),n.jsx("span",{children:"steps"})]}),n.jsx("div",{className:"flex items-center gap-3 text-[10px] text-muted-foreground",children:n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx(hi,{className:"h-3 w-3"}),n.jsx("span",{children:yh(((se=B._metadata)==null?void 0:se.lastRunAt)||null)})]})}),n.jsx("div",{className:"text-[10px] text-muted-foreground truncate font-mono",children:B.url})]})})]})})]},B.key)})}),n.jsx(st,{open:l,onOpenChange:c,children:n.jsxs(nt,{children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:"Create New Scenario"}),n.jsx(ot,{children:"Create a new visual scenario. You can add steps later."})]}),n.jsxs("div",{className:"space-y-4 py-4",children:[n.jsxs("div",{children:[n.jsx(q,{htmlFor:"name",children:"Name"}),n.jsx(ve,{id:"name",value:u.name,onChange:B=>{m({...u,name:B.target.value,key:u.key||je(B.target.value)})},placeholder:"Admin Dashboard"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"key",children:"Key"}),n.jsx(ve,{id:"key",value:u.key,onChange:B=>m({...u,key:B.target.value}),placeholder:"admin-dashboard",className:"font-mono"}),n.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Lowercase letters, numbers, and hyphens only"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"url",children:"URL"}),n.jsx(ve,{id:"url",value:u.url,onChange:B=>m({...u,url:B.target.value}),placeholder:"https://example.com/dashboard"})]})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>c(!1),children:"Cancel"}),n.jsx(T,{onClick:Vt,children:"Create Scenario"})]})]})}),n.jsx(st,{open:f,onOpenChange:g,children:n.jsxs(nt,{children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:"Record New Visual"}),n.jsx(ot,{children:"Create a new visual by recording it. Enter a title and the recorder will start."})]}),n.jsxs("div",{className:"space-y-4 py-4",children:[n.jsxs("div",{children:[n.jsx(q,{htmlFor:"record-title",children:"Visual Title"}),n.jsx(ve,{id:"record-title",value:R,onChange:B=>k(B.target.value),placeholder:"Admin Dashboard"})]}),n.jsxs("div",{className:"text-sm text-muted-foreground space-y-2",children:[n.jsx("p",{children:"This will:"}),n.jsxs("ul",{className:"list-disc list-inside space-y-1 ml-2",children:[n.jsx("li",{children:"Start a recording job"}),n.jsx("li",{children:"Open Chrome with remote debugging (if not already open)"}),n.jsx("li",{children:"Allow you to capture steps using keyboard shortcuts"})]}),n.jsx("p",{className:"mt-4 font-medium",children:"Keyboard shortcuts:"}),n.jsxs("ul",{className:"list-disc list-inside space-y-1 ml-2",children:[n.jsxs("li",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded text-xs",children:"C"})," ","- Capture"]}),n.jsxs("li",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded text-xs",children:"Q"})," ","- Quit and save"]})]})]})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>g(!1),children:"Cancel"}),n.jsx(T,{onClick:async()=>{if(!R.trim()){t({title:"Error",description:"Please enter a title",variant:"destructive"});return}try{const B=await fetch("/api/jobs/record",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:R})}),oe=await B.json();B.ok?(t({title:"Success",description:"Recording job started. Check Jobs page and your terminal.",variant:"success"}),g(!1),k("")):t({title:"Error",description:oe.error||"Failed to start recording",variant:"destructive"})}catch{t({title:"Error",description:"Failed to start recording",variant:"destructive"})}},children:"Start Recording"})]})]})}),n.jsx(st,{open:N,onOpenChange:S,children:n.jsxs(nt,{className:"max-w-lg",children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:"Run Selected Scenarios"}),n.jsxs(ot,{children:["Capture assets for ",p.size," selected scenario(s)"]})]}),n.jsxs("div",{className:"space-y-5 py-4",children:[n.jsxs("div",{className:"space-y-3",children:[n.jsx(q,{className:"text-sm font-medium",children:"Output Format"}),n.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[n.jsx("button",{type:"button",onClick:()=>F("step-by-step-images"),className:`p-3 rounded-lg border-2 text-left transition-all ${_==="step-by-step-images"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(fn,{className:"h-4 w-4"}),n.jsx("span",{className:"font-medium text-sm",children:"Screenshots"})]})}),n.jsx("button",{type:"button",onClick:()=>F("summary-video"),className:`p-3 rounded-lg border-2 text-left transition-all ${_==="summary-video"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(io,{className:"h-4 w-4"}),n.jsx("span",{className:"font-medium text-sm",children:"Video"})]})})]})]}),n.jsx("div",{className:"space-y-2",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(q,{className:"text-sm font-medium",children:"Visual Diffing"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Compare against approved baselines"})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[$===null&&A&&n.jsx("span",{className:"text-xs text-muted-foreground",children:"(default: on)"}),$===null&&!A&&n.jsx("span",{className:"text-xs text-muted-foreground",children:"(default: off)"}),n.jsx("input",{type:"checkbox",checked:$===null?A:$,onChange:B=>E(B.target.checked),className:"rounded h-4 w-4"})]})]})}),n.jsx("div",{className:"space-y-2",children:n.jsx("div",{className:"flex items-center justify-between",children:n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(q,{className:"text-sm font-medium",children:"Output Crop"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Crop is configured per-scenario in Details tab"})]})})}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Selected Scenarios:"}),n.jsx("div",{className:"max-h-28 overflow-auto border rounded-md p-2 space-y-1",children:Array.from(p).map(B=>{const oe=r.find(re=>re.key===B),se=oe?Pr(oe):B.split("-")[0]||"other";return n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx(ue,{variant:"outline",className:"text-[10px]",children:se}),n.jsx("span",{className:"font-medium",children:(oe==null?void 0:oe.name)||B})]},B)})})]}),(O==null?void 0:O.dimensions)&&Object.keys(O.dimensions).length>0&&n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(ns,{id:"run-all-variants",checked:V,onCheckedChange:B=>y(!!B)}),n.jsx(q,{htmlFor:"run-all-variants",className:"text-sm",children:"Run all variant combinations"})]}),!V&&n.jsxs("div",{className:"pl-6 space-y-2",children:[n.jsx("p",{className:"text-xs text-muted-foreground",children:"Select specific variant:"}),Object.entries(O.dimensions).map(([B,oe])=>n.jsxs("div",{className:"space-y-1",children:[n.jsx(q,{className:"text-xs",children:oe.label||B}),n.jsx("div",{className:"flex flex-wrap gap-1",children:oe.options&&Object.entries(oe.options).map(([se,re])=>n.jsx(ue,{variant:v[B]===se?"default":"outline",className:"cursor-pointer text-xs",onClick:()=>L(qe=>({...qe,[B]:se})),children:(re==null?void 0:re.name)||se},se))})]},B))]})]})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>S(!1),disabled:P,children:"Cancel"}),n.jsx(T,{onClick:kt,disabled:P,children:P?n.jsxs(n.Fragment,{children:[n.jsx(_t,{className:"h-4 w-4 mr-2 animate-spin"}),"Starting..."]}):n.jsxs(n.Fragment,{children:[n.jsx(Ts,{className:"h-4 w-4 mr-2"}),"Run ",p.size," Scenario(s)"]})})]})]})}),n.jsx(st,{open:W,onOpenChange:J,children:n.jsxs(nt,{children:[n.jsxs(Xe,{children:[n.jsxs(Ze,{className:"text-destructive",children:["Delete All"," ",G==="scenarios"?"Scenarios":"Assets","?"]}),n.jsx(ot,{children:G==="scenarios"?`This will permanently remove all ${r.length} scenarios from your config. This action cannot be undone.`:"This will permanently delete all captured asset files from the output folder. This action cannot be undone."})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>J(!1),children:"Cancel"}),n.jsxs(T,{variant:"destructive",onClick:ae,children:[n.jsx(ps,{className:"h-4 w-4 mr-2"}),"Delete All"]})]})]})})]})}const ud=d.createContext(void 0),hd=d.forwardRef(({className:e,value:t,onValueChange:s,...r},i)=>n.jsx(ud.Provider,{value:{value:t,onValueChange:s},children:n.jsx("div",{ref:i,className:Y("w-full",e),...r})}));hd.displayName="Tabs";const fd=d.forwardRef(({className:e,...t},s)=>n.jsx("div",{ref:s,className:Y("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",e),...t}));fd.displayName="TabsList";const sr=d.forwardRef(({className:e,value:t,...s},r)=>{const i=d.useContext(ud);if(!i)throw new Error("TabsTrigger must be used within Tabs");const a=i.value===t;return n.jsx("button",{ref:r,className:Y("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",a&&"bg-background text-foreground shadow-sm",e),onClick:()=>i.onValueChange(t),...s})});sr.displayName="TabsTrigger";const nr=d.forwardRef(({className:e,value:t,forceMount:s,...r},i)=>{const a=d.useContext(ud);if(!a)throw new Error("TabsContent must be used within Tabs");const o=a.value===t;return!o&&!s?null:n.jsx("div",{ref:i,className:Y("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",!o&&"hidden",e),...r})});nr.displayName="TabsContent";const Ni=d.createContext({open:!1,setOpen:()=>{},containerRef:{current:null}}),$m=({value:e,onValueChange:t,children:s,disabled:r})=>{const[i,a]=d.useState(!1),o=d.useRef(null);return d.useEffect(()=>{if(!i)return;const l=u=>{const m=u.target;o.current&&!o.current.contains(m)&&a(!1)},c=u=>{u.key==="Escape"&&a(!1)};return document.addEventListener("mousedown",l),document.addEventListener("keydown",c),()=>{document.removeEventListener("mousedown",l),document.removeEventListener("keydown",c)}},[i]),n.jsx(Ni.Provider,{value:{value:e,onValueChange:t,open:i,setOpen:a,containerRef:o},children:n.jsx("div",{ref:o,className:"relative inline-block","data-disabled":r,children:s})})},pd=d.forwardRef(({className:e,children:t,...s},r)=>{const{open:i,setOpen:a}=d.useContext(Ni);return n.jsxs("button",{ref:r,type:"button",onClick:()=>a(!i),className:Y("flex h-9 w-full items-center justify-between rounded-md border border-gray-600 bg-gray-800 px-3 py-2 text-sm text-white ring-offset-background placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...s,children:[t,n.jsx(zs,{className:Y("h-4 w-4 opacity-50 transition-transform ml-2 flex-shrink-0",i&&"rotate-180")})]})});pd.displayName="SelectTrigger";const Vm=({placeholder:e})=>{const{value:t}=d.useContext(Ni);return n.jsx("span",{className:"truncate",children:t||e})},md=d.forwardRef(({className:e,children:t,...s},r)=>{const{open:i}=d.useContext(Ni);return i?n.jsx("div",{ref:r,className:Y("absolute z-[100] mt-1 max-h-60 min-w-full overflow-auto rounded-md border border-gray-600 bg-gray-800 py-1 shadow-lg",e),...s,children:t}):null});md.displayName="SelectContent";const xd=d.forwardRef(({className:e,children:t,value:s,...r},i)=>{const{value:a,onValueChange:o,setOpen:l}=d.useContext(Ni),c=a===s,u=f=>{f.stopPropagation()},m=f=>{f.preventDefault(),f.stopPropagation(),o==null||o(s),l(!1)};return n.jsxs("div",{ref:i,className:Y("relative flex w-full cursor-pointer select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm text-white outline-none hover:bg-gray-700 focus:bg-gray-700",c&&"bg-gray-700",e),onMouseDown:u,onClick:m,...r,children:[n.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c&&n.jsx(ro,{className:"h-4 w-4"})}),t]})});xd.displayName="SelectItem";function g1({url:e,filename:t,onClose:s}){const[r,i]=d.useState(1),[a,o]=d.useState({x:0,y:0}),[l,c]=d.useState(!1),[u,m]=d.useState({x:0,y:0}),[f,g]=d.useState(0),R=.5,k=5,C=()=>{i(b=>Math.min(b+.25,k))},j=()=>{i(b=>Math.max(b-.25,R))},p=()=>{i(1),o({x:0,y:0}),g(0)},h=()=>{g(b=>(b+90)%360)},x=()=>{const b=document.createElement("a");b.href=e,b.download=t,document.body.appendChild(b),b.click(),document.body.removeChild(b)},w=b=>{r>1&&(c(!0),m({x:b.clientX-a.x,y:b.clientY-a.y}))},N=b=>{l&&r>1&&o({x:b.clientX-u.x,y:b.clientY-u.y})},S=()=>{c(!1)},P=b=>{b.preventDefault();const O=b.deltaY>0?-.1:.1;i(D=>Math.max(R,Math.min(k,D+O)))};return d.useEffect(()=>{const b=O=>{O.key==="Escape"&&s()};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[s]),n.jsx(st,{open:!0,onOpenChange:s,children:n.jsx(nt,{className:"max-w-[95vw] max-h-[95vh] p-0 bg-black/95 border-none",children:n.jsxs("div",{className:"relative w-full h-full flex flex-col",children:[n.jsxs("div",{className:"absolute top-0 left-0 right-0 z-10 flex items-center justify-between p-4 bg-black/50 backdrop-blur-sm",children:[n.jsx("div",{className:"flex items-center gap-2",children:n.jsx("span",{className:"text-white text-sm font-medium",children:t})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(T,{variant:"ghost",size:"sm",onClick:j,disabled:r<=R,className:"text-white hover:bg-white/20",children:n.jsx(l0,{className:"h-4 w-4"})}),n.jsxs("span",{className:"text-white text-sm min-w-[60px] text-center",children:[Math.round(r*100),"%"]}),n.jsx(T,{variant:"ghost",size:"sm",onClick:C,disabled:r>=k,className:"text-white hover:bg-white/20",children:n.jsx(o0,{className:"h-4 w-4"})}),n.jsx(T,{variant:"ghost",size:"sm",onClick:h,className:"text-white hover:bg-white/20",children:n.jsx(Qy,{className:"h-4 w-4"})}),n.jsx(T,{variant:"ghost",size:"sm",onClick:p,className:"text-white hover:bg-white/20",children:"Reset"}),n.jsx(T,{variant:"ghost",size:"sm",onClick:x,className:"text-white hover:bg-white/20",children:n.jsx(Ay,{className:"h-4 w-4"})}),n.jsx(T,{variant:"ghost",size:"sm",onClick:s,className:"text-white hover:bg-white/20",children:n.jsx(ln,{className:"h-4 w-4"})})]})]}),n.jsx("div",{className:"flex-1 overflow-hidden flex items-center justify-center cursor-move",onMouseDown:w,onMouseMove:N,onMouseUp:S,onMouseLeave:S,onWheel:P,children:n.jsx("img",{src:e,alt:t,className:"max-w-full max-h-full object-contain select-none",style:{transform:`translate(${a.x}px, ${a.y}px) scale(${r}) rotate(${f}deg)`,transition:l?"none":"transform 0.1s"},draggable:!1})})]})})})}function v1({url:e,className:t}){const s=d.useRef(null),[r,i]=d.useState(!1),[a,o]=d.useState(!1),[l,c]=d.useState(!0),u=()=>{s.current&&(r?s.current.pause():s.current.play(),i(!r))},m=()=>{s.current&&(s.current.muted=!a,o(!a))},f=()=>{s.current&&s.current.requestFullscreen&&s.current.requestFullscreen()};return n.jsxs("div",{className:Y("relative group",t),onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[n.jsx("video",{ref:s,src:e,className:"w-full h-full object-contain",onPlay:()=>i(!0),onPause:()=>i(!1),onEnded:()=>i(!1),muted:a,playsInline:!0,preload:"metadata"}),l&&n.jsx("div",{className:"absolute inset-0 bg-black/30 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(T,{variant:"ghost",size:"sm",onClick:u,className:"text-white hover:bg-white/20",children:r?n.jsx(qy,{className:"h-6 w-6"}):n.jsx(Ts,{className:"h-6 w-6"})}),n.jsx(T,{variant:"ghost",size:"sm",onClick:m,className:"text-white hover:bg-white/20",children:a?n.jsx(i0,{className:"h-4 w-4"}):n.jsx(r0,{className:"h-4 w-4"})}),n.jsx(T,{variant:"ghost",size:"sm",onClick:f,className:"text-white hover:bg-white/20",children:n.jsx(Ky,{className:"h-4 w-4"})})]})})]})}function fo({url:e,filename:t,className:s,size:r="md",showControls:i=!0}){const[a,o]=d.useState(!1),[l,c]=d.useState(!1),[u,m]=d.useState(!0);d.useEffect(()=>{c(!1),m(!0)},[e]);const f=t.toLowerCase().split(".").pop(),g=["png","jpg","jpeg","gif","webp"].includes(f||""),R=["mp4","webm","mov"].includes(f||""),k={sm:"h-16 w-24",md:"h-32 w-48",lg:"h-64 w-96"};return g?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:Y("relative rounded-md border border-border overflow-hidden bg-muted cursor-pointer group",k[r],s),onClick:()=>o(!0),children:[l?n.jsxs("div",{className:"flex items-center justify-center h-full flex-col gap-1",children:[n.jsx(ah,{className:"h-6 w-6 text-muted-foreground"}),n.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Failed to load"})]}):n.jsxs(n.Fragment,{children:[u&&n.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-muted z-10",children:n.jsx(_e,{className:"h-5 w-5 text-muted-foreground animate-spin"})}),n.jsx("img",{src:e,alt:t,className:Y("w-full h-full object-contain transition-opacity",u?"opacity-0":"opacity-100"),loading:"lazy",onLoad:()=>m(!1),onError:()=>{c(!0),m(!1)}})]}),i&&!u&&!l&&n.jsx("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/20 transition-colors flex items-center justify-center opacity-0 group-hover:opacity-100",children:n.jsx(fn,{className:"h-6 w-6 text-white"})})]}),a&&n.jsx(g1,{url:e,filename:t,onClose:()=>o(!1)})]}):R?r==="sm"?n.jsxs("div",{className:Y("relative rounded-md border border-border overflow-hidden bg-muted group cursor-pointer",k[r],s),children:[n.jsx("video",{src:e,className:"w-full h-full object-contain",preload:"metadata",muted:!0,playsInline:!0}),n.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/20",children:n.jsx("div",{className:"rounded-full bg-black/50 p-1",children:n.jsx(Ts,{className:"h-3 w-3 text-white fill-white"})})})]}):n.jsx("div",{className:Y("rounded-md border border-border overflow-hidden bg-muted",k[r],s),children:n.jsx(v1,{url:e,filename:t})}):n.jsx("div",{className:Y("rounded-md border border-border bg-muted flex items-center justify-center",k[r],s),children:n.jsx(ah,{className:"h-8 w-8 text-muted-foreground"})})}const y1=["goto","click","type","hover","wait","waitForSelector","screenshot","clip"];function j1({open:e,onOpenChange:t,step:s,onSave:r,assetUrl:i}){const[a,o]=d.useState({action:"click",selector:"",key:"",text:"",url:"",ms:"",duration:"",clip:null,selectorPadding:null,deviceScaleFactor:null,path:"",order:0});d.useEffect(()=>{o(s?{...a,...s}:{action:"click",selector:"",key:"",text:"",url:"",ms:"",duration:"",clip:null,selectorPadding:null,deviceScaleFactor:null,path:"",order:0})},[s,e]);const l=()=>{const c={action:a.action};if(a.selector&&(c.selector=a.selector),a.key&&(c.key=a.key),a.text&&(c.text=a.text),a.url&&(c.url=a.url),a.ms&&(c.ms=parseInt(a.ms,10)),a.duration&&(c.duration=parseInt(a.duration,10)),a.path&&(c.path=a.path),a.order!==void 0&&(c.order=a.order),a.clip)try{c.clip=typeof a.clip=="string"?JSON.parse(a.clip):a.clip}catch{}a.selectorPadding!==null&&a.selectorPadding!==""&&(c.selectorPadding=parseInt(a.selectorPadding,10)),a.deviceScaleFactor!==null&&a.deviceScaleFactor!==""&&(c.deviceScaleFactor=parseFloat(a.deviceScaleFactor)),r(c)};return n.jsx(st,{open:e,onOpenChange:t,children:n.jsxs(nt,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:s?"Edit Step":"Add Step"}),n.jsx(ot,{children:"Configure the step action and parameters"})]}),n.jsxs("div",{className:"space-y-4 py-4",children:[n.jsxs("div",{children:[n.jsx(q,{htmlFor:"action",children:"Action"}),n.jsx("select",{id:"action",value:a.action,onChange:c=>o({...a,action:c.target.value}),className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:y1.map(c=>n.jsx("option",{value:c,children:c},c))})]}),(a.action==="click"||a.action==="type"||a.action==="hover"||a.action==="waitForSelector"||a.action==="screenshot")&&n.jsxs("div",{children:[n.jsx(q,{htmlFor:"selector",children:"Selector"}),n.jsx(ve,{id:"selector",value:a.selector||"",onChange:c=>o({...a,selector:c.target.value}),placeholder:"#id, .class, [data-testid]"})]}),a.action==="type"&&n.jsxs("div",{children:[n.jsx(q,{htmlFor:"text",children:"Text"}),n.jsx(ve,{id:"text",value:a.text||"",onChange:c=>o({...a,text:c.target.value}),placeholder:"Text to type"})]}),a.action==="goto"&&n.jsxs("div",{children:[n.jsx(q,{htmlFor:"url",children:"URL"}),n.jsx(ve,{id:"url",value:a.url||"",onChange:c=>o({...a,url:c.target.value}),placeholder:"https://example.com"})]}),a.action==="wait"&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{children:[n.jsx(q,{htmlFor:"ms",children:"Milliseconds"}),n.jsx(ve,{id:"ms",type:"number",value:a.ms||"",onChange:c=>o({...a,ms:c.target.value}),placeholder:"1000"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"duration",children:"Duration (alternative)"}),n.jsx(ve,{id:"duration",type:"number",value:a.duration||"",onChange:c=>o({...a,duration:c.target.value}),placeholder:"1000"})]})]}),(a.action==="screenshot"||a.action==="clip")&&n.jsxs(n.Fragment,{children:[i&&n.jsxs("div",{children:[n.jsx(q,{children:"Asset Preview"}),n.jsx("div",{className:"mt-2",children:n.jsx(fo,{url:i,filename:a.path||`${a.key||"asset"}.png`,size:"md"})})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"key",children:"Key"}),n.jsx(ve,{id:"key",value:a.key||"",onChange:c=>o({...a,key:c.target.value}),placeholder:"capture-key"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"path",children:"Path"}),n.jsx(ve,{id:"path",value:a.path||"",onChange:c=>o({...a,path:c.target.value}),placeholder:"screenshot.png"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"clip",children:"Clip (JSON)"}),n.jsx(uo,{id:"clip",value:typeof a.clip=="object"?JSON.stringify(a.clip,null,2):a.clip||"",onChange:c=>o({...a,clip:c.target.value}),placeholder:'{"x": 0, "y": 0, "width": 800, "height": 600}',className:"font-mono text-sm"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"selectorPadding",children:"Selector Padding"}),n.jsx(ve,{id:"selectorPadding",type:"number",value:a.selectorPadding||"",onChange:c=>o({...a,selectorPadding:c.target.value}),placeholder:"0"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"deviceScaleFactor",children:"Device Scale Factor"}),n.jsx(ve,{id:"deviceScaleFactor",type:"number",step:"0.1",value:a.deviceScaleFactor||"",onChange:c=>o({...a,deviceScaleFactor:c.target.value}),placeholder:"1.0"})]})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"order",children:"Order"}),n.jsx(ve,{id:"order",type:"number",value:a.order||0,onChange:c=>o({...a,order:parseInt(c.target.value,10)||0})})]})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),n.jsxs(T,{onClick:l,children:[s?"Update":"Add"," Step"]})]})]})})}const w1=({open:e,children:t})=>(d.useEffect(()=>{if(e){const s=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=s}}},[e]),e?n.jsx(n.Fragment,{children:t}):null),N1={top:"inset-x-0 top-0 border-b animate-in slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t animate-in slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r animate-in slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l animate-in slide-in-from-right sm:max-w-lg"},Um=d.forwardRef(({side:e="right",className:t,children:s,onOpenChange:r},i)=>{const a=d.useCallback(l=>{l.stopPropagation(),r==null||r(!1)},[r]),o=d.useCallback(l=>{l.stopPropagation()},[]);return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-50 bg-black/80 animate-in fade-in-0",onClick:a}),n.jsxs("div",{ref:i,className:Y("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out duration-300",N1[e],t),onClick:o,children:[s,n.jsxs("button",{onClick:()=>r==null?void 0:r(!1),className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",children:[n.jsx(ln,{className:"h-4 w-4"}),n.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Um.displayName="SheetContent";const Bm=({className:e,...t})=>n.jsx("div",{className:Y("flex flex-col space-y-2 text-center sm:text-left",e),...t});Bm.displayName="SheetHeader";const Wm=({className:e,children:t,...s})=>n.jsx("h2",{className:Y("text-lg font-semibold text-foreground",e),...s,children:t});Wm.displayName="SheetTitle";const Km=({className:e,children:t,...s})=>n.jsx("p",{className:Y("text-sm text-muted-foreground",e),...s,children:t});Km.displayName="SheetDescription";function k1({open:e,onOpenChange:t,asset:s,scenarioKey:r,variationSlug:i,allAssets:a=[],onNavigate:o}){var V;const{toast:l}=Pt(),[c,u]=d.useState(null),[m,f]=d.useState(!1),[g,R]=d.useState(!1),k=d.useRef(a),C=d.useRef(o),j=d.useRef(t);d.useEffect(()=>{k.current=a,C.current=o,j.current=t});const p=(s==null?void 0:s.captureKey)||(s==null?void 0:s.filename.replace(/\.[^/.]+$/,"")),h=a.findIndex(y=>y.filename===(s==null?void 0:s.filename)),x=h>0,w=h<a.length-1&&h>=0,N=d.useRef({currentIndex:h,hasPrev:x,hasNext:w});d.useEffect(()=>{N.current={currentIndex:h,hasPrev:x,hasNext:w}}),d.useEffect(()=>{f(!1),R(!1)},[s==null?void 0:s.url]);const S=d.useRef(null);d.useEffect(()=>{!r||!e||S.current!==r&&(S.current=r,fetch(`/api/config/scenarios/${r}`).then(y=>y.json()).then(y=>{const _=y.scenario;if(_!=null&&_.steps){const F=_.steps.findIndex($=>{var E;return $.key===p||$.captureKey===p||((E=$.path)==null?void 0:E.replace(/\.[^/.]+$/,""))===p});u(F!==-1?{step:_.steps[F],index:F}:null)}}).catch(()=>{u(null)}))},[r,e]);const P=d.useCallback(()=>{const{currentIndex:y,hasPrev:_}=N.current,F=k.current,$=C.current;_&&$&&F[y-1]&&$(F[y-1])},[]),b=d.useCallback(()=>{const{currentIndex:y,hasNext:_}=N.current,F=k.current,$=C.current;_&&$&&F[y+1]&&$(F[y+1])},[]),O=d.useCallback(()=>{var y;(y=j.current)==null||y.call(j,!1)},[]);d.useEffect(()=>{if(!e)return;const y=_=>{if(_.key==="Escape"){_.preventDefault(),_.stopPropagation(),O();return}_.key==="ArrowLeft"?(_.preventDefault(),_.stopPropagation(),P()):_.key==="ArrowRight"&&(_.preventDefault(),_.stopPropagation(),b())};return window.addEventListener("keydown",y,!0),()=>{window.removeEventListener("keydown",y,!0)}},[e,P,b,O]);const D=y=>y<1024?`${y} B`:y<1024*1024?`${(y/1024).toFixed(1)} KB`:`${(y/(1024*1024)).toFixed(1)} MB`,v=()=>{s!=null&&s.path&&(navigator.clipboard.writeText(s.path),l({title:"Copied",description:"File path copied to clipboard",variant:"success"}))},L=()=>{if(s!=null&&s.url){const y=`${window.location.origin}${s.url}`;navigator.clipboard.writeText(y),l({title:"Copied",description:"Asset URL copied to clipboard",variant:"success"})}};return s?n.jsx(w1,{open:e,onOpenChange:t,children:n.jsxs(Um,{side:"right",className:"w-full sm:max-w-2xl overflow-y-auto",onOpenChange:t,children:[n.jsxs(Bm,{children:[n.jsxs(Wm,{className:"flex items-center gap-2",children:[n.jsx("span",{className:"truncate",children:s.filename}),s.diff&&n.jsxs(n.Fragment,{children:[s.diff.status==="new"&&n.jsx(ue,{variant:"success",className:"text-xs",children:"New"}),s.diff.status==="changed"&&n.jsx(ue,{variant:"warning",className:"text-xs",children:s.diff.score!==void 0?`${(s.diff.score*100).toFixed(1)}% diff`:"Changed"}),s.diff.status==="unchanged"&&n.jsx(ue,{variant:"approved",className:"text-xs",children:"Match"})]})]}),n.jsxs(Km,{children:[r," / ",i,a.length>1&&n.jsxs("span",{className:"ml-2",children:["(",h+1," of ",a.length,")"]})]})]}),a.length>1&&o&&n.jsxs("div",{className:"flex items-center justify-between my-4",children:[n.jsxs(T,{variant:"outline",size:"sm",onClick:P,disabled:!x,children:[n.jsx(_y,{className:"h-4 w-4 mr-1"}),"Previous"]}),n.jsx("span",{className:"text-sm text-muted-foreground",children:"Use ← → arrow keys to navigate"}),n.jsxs(T,{variant:"outline",size:"sm",onClick:b,disabled:!w,children:["Next",n.jsx(Ps,{className:"h-4 w-4 ml-1"})]})]}),n.jsxs("div",{className:"mt-4 space-y-4",children:[n.jsxs("div",{className:"relative rounded-lg border bg-muted overflow-hidden",children:[!m&&!g&&n.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:n.jsx("div",{className:"animate-pulse text-muted-foreground",children:"Loading..."})}),g?n.jsx("div",{className:"flex items-center justify-center h-64 text-muted-foreground",children:"Failed to load image"}):n.jsx("img",{src:s.url,alt:s.filename,className:Y("w-full h-auto max-h-[50vh] object-contain transition-opacity",m?"opacity-100":"opacity-0"),onLoad:()=>f(!0),onError:()=>R(!0)})]}),n.jsxs("div",{className:"flex gap-2 flex-wrap",children:[n.jsxs(T,{variant:"outline",size:"sm",onClick:v,children:[n.jsx(rn,{className:"h-3.5 w-3.5 mr-1.5"}),"Copy Path"]}),n.jsxs(T,{variant:"outline",size:"sm",onClick:L,children:[n.jsx(rn,{className:"h-3.5 w-3.5 mr-1.5"}),"Copy URL"]}),n.jsxs("a",{href:s.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground",children:[n.jsx(an,{className:"h-3.5 w-3.5"}),"Open Full Size"]})]}),n.jsxs("div",{className:"space-y-3 border-t pt-4",children:[n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"File Size"}),n.jsx("div",{className:"text-sm font-medium mt-0.5",children:D(s.size)})]}),n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Modified"}),n.jsx("div",{className:"text-sm font-medium mt-0.5",children:new Date(s.mtime).toLocaleString()})]}),p&&n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Capture Key"}),n.jsx("code",{className:"block text-sm font-mono bg-muted px-2 py-1 rounded mt-0.5",children:p})]}),n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"File Path"}),n.jsx("div",{className:"text-xs font-mono bg-muted px-2 py-1 rounded mt-0.5 break-all",children:s.relativePath})]}),c&&n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Linked Step"}),n.jsx("div",{className:"mt-1",children:n.jsxs("div",{className:"inline-flex items-center gap-1.5 text-sm",children:[n.jsx(Rn,{className:"h-3.5 w-3.5 text-primary"}),"Step #",c.index+1,": ",c.step.action]})}),c.step.selector&&n.jsx("div",{className:"text-xs font-mono bg-muted px-2 py-1 rounded mt-1",children:c.step.selector})]})]}),((V=s.diff)==null?void 0:V.diffUrl)&&n.jsxs("div",{className:"space-y-2 border-t pt-4",children:[n.jsxs(q,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n.jsx(Qp,{className:"h-3.5 w-3.5 text-yellow-500"}),"Visual Diff"]}),n.jsx("div",{className:"rounded-lg border overflow-hidden",children:n.jsx("img",{src:s.diff.diffUrl,alt:"Visual diff",className:"w-full h-auto"})})]})]})]})}):null}function b1({scenarioKey:e}){const[t,s]=d.useState([]),[r,i]=d.useState([]),[a,o]=d.useState(!0),[l,c]=d.useState(null),[u,m]=d.useState(null),[f,g]=d.useState(null),[R,k]=d.useState(!1),[C,j]=d.useState(new Set);d.useEffect(()=>{if(!e){o(!1);return}fetch(`/api/output/${e}/versions`).then(v=>v.json()).then(v=>{const L=v.versions||[];i(L),L.length>0?c(L[0].timestamp):o(!1)}).catch(v=>{console.error("Failed to load versions:",v),o(!1)})},[e]),d.useEffect(()=>{!e||!l||(o(!0),fetch(`/api/output/${e}/version/${l}`).then(v=>v.json()).then(v=>{s(v.assets||[]),m(v.diffManifest||null),o(!1)}).catch(v=>{console.error("Failed to load assets:",v),o(!1)}))},[e,l]);const p=d.useMemo(()=>t.filter(v=>!v.isSentinel),[t]),{images:h,videos:x,stepsByVariant:w}=d.useMemo(()=>{var y;const v=p.filter(_=>_.filename.endsWith(".png")||_.filename.endsWith(".jpg")||_.filename.endsWith(".jpeg")||_.filename.endsWith(".webp")),L=p.filter(_=>_.filename.endsWith(".mp4")||_.filename.endsWith(".webm")),V={};for(const _ of v){const F=((y=_.assetKey)==null?void 0:y.split("/"))||[];let $="default";F.length>1&&($=F.slice(0,-1).join("/"));const E=_.filename.match(/(step-\d+)/),A=E?E[1]:"other";V[$]||(V[$]={}),V[$][A]||(V[$][A]=[]),V[$][A].push(_)}return{images:v,videos:L,stepsByVariant:V}},[p]),N=Object.keys(w).sort(),S=p.length,P=d.useCallback(v=>{j(L=>{const V=new Set(L);return V.has(v)?V.delete(v):V.add(v),V})},[]),b=d.useCallback(v=>{g(v),k(!0)},[]),O=d.useCallback(v=>{g(v)},[]),D=d.useCallback(v=>{k(v),v||g(null)},[]);return a?n.jsx("div",{className:"text-muted-foreground text-center py-4 text-sm",children:"Loading assets..."}):S===0&&r.length===0?n.jsx("div",{className:"text-center text-muted-foreground py-6 text-sm",children:n.jsx("p",{children:"No assets found. Run the scenario to generate assets."})}):n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Uy,{className:"h-4 w-4 text-muted-foreground"}),n.jsxs($m,{value:l||"",onValueChange:c,children:[n.jsx(pd,{className:"h-8 w-[200px] text-xs",children:n.jsx(Vm,{placeholder:"Select version"})}),n.jsx(md,{children:r.map(v=>n.jsxs(xd,{value:v.timestamp,className:"text-xs",children:[v.label," ",v.isLatest&&"(Latest)"," · ",v.assetCount]},v.timestamp))})]})]}),n.jsxs("div",{className:"flex gap-1.5 flex-wrap",children:[n.jsxs(ue,{variant:"secondary",className:"text-xs h-6",children:[n.jsx(fn,{className:"h-3 w-3 mr-1"}),h.length]}),x.length>0&&n.jsxs(ue,{variant:"secondary",className:"text-xs h-6",children:[n.jsx(_n,{className:"h-3 w-3 mr-1"}),x.length]}),(u==null?void 0:u.summary)&&n.jsxs(n.Fragment,{children:[u.summary.new>0&&n.jsxs(ue,{variant:"info",className:"text-xs h-6",children:["+",u.summary.new]}),u.summary.changed>0&&n.jsxs(ue,{variant:"warning",className:"text-xs h-6",children:["⚠",u.summary.changed]}),u.summary.unchanged>0&&n.jsxs(ue,{variant:"approved",className:"text-xs h-6",children:["✓",u.summary.unchanged]})]})]})]}),l&&h.length>0&&n.jsx("div",{className:"space-y-2",children:N.map(v=>{const L=w[v],V=Object.keys(L).sort((F,$)=>{var z,W;const E=parseInt(((z=F.match(/\d+/))==null?void 0:z[0])||"0"),A=parseInt(((W=$.match(/\d+/))==null?void 0:W[0])||"0");return E-A}),y=C.has(v),_=Object.values(L).flat().length;return n.jsxs("div",{className:"border rounded-lg bg-card",children:[n.jsxs("button",{onClick:()=>P(v),className:"w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-accent/50 transition-colors",children:[y?n.jsx(Ps,{className:"h-4 w-4 text-muted-foreground"}):n.jsx(zs,{className:"h-4 w-4 text-muted-foreground"}),n.jsx(Xp,{className:"h-4 w-4 text-muted-foreground"}),n.jsx("span",{className:"font-medium text-sm",children:v==="default"?"Default":v.replace(/_/g," / ").replace(/-/g,": ")}),n.jsxs(ue,{variant:"outline",className:"text-xs ml-auto",children:[_," assets"]})]}),!y&&n.jsx("div",{className:"px-3 pb-3",children:n.jsx("div",{className:"flex gap-2 overflow-x-auto pb-2",children:V.map(F=>{const $=L[F];return n.jsxs("div",{className:"flex-shrink-0 space-y-1",children:[n.jsx("div",{className:"text-xs text-muted-foreground text-center",children:F==="other"?"Other":F.replace("-"," ")}),n.jsx("div",{className:"flex gap-1",children:$.map((E,A)=>{const z=E.diff,W=E.filename.includes("after");return n.jsxs("div",{onClick:()=>b(E),className:Y("relative cursor-pointer rounded overflow-hidden border transition-all hover:ring-2 hover:ring-primary",(z==null?void 0:z.status)==="changed"&&"border-yellow-500",(z==null?void 0:z.status)==="new"&&"border-blue-500",(z==null?void 0:z.status)==="unchanged"&&"border-green-500/50"),style:{width:100,height:64},children:[n.jsx("img",{src:E.url,alt:E.filename,className:"w-full h-full object-cover",loading:"lazy"}),z&&n.jsxs("div",{className:"absolute top-0.5 right-0.5",children:[z.status==="new"&&n.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-500"}),z.status==="changed"&&n.jsx("div",{className:"w-2 h-2 rounded-full bg-yellow-500"})]}),n.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/60 text-[9px] text-center text-white py-0.5",children:W?"after":"before"})]},A)})})]},F)})})})]},v)})}),x.length>0&&n.jsxs("div",{className:"border rounded-lg bg-card p-3",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[n.jsx(_n,{className:"h-4 w-4 text-muted-foreground"}),n.jsx("span",{className:"font-medium text-sm",children:"Videos"}),n.jsx(ue,{variant:"outline",className:"text-xs",children:x.length})]}),n.jsx("div",{className:"flex gap-2 overflow-x-auto",children:x.map((v,L)=>n.jsxs("div",{onClick:()=>b(v),className:"flex-shrink-0 cursor-pointer rounded overflow-hidden border hover:ring-2 hover:ring-primary transition-all",style:{width:160},children:[n.jsx(fo,{url:v.url,filename:v.filename,size:"sm",showControls:!1}),n.jsx("div",{className:"p-1.5 text-xs truncate text-muted-foreground",children:v.filename})]},L))})]}),l&&p.length===0&&n.jsx("div",{className:"text-center text-muted-foreground py-4 text-sm",children:"No assets for this version."}),n.jsx(k1,{open:R,onOpenChange:D,asset:f,scenarioKey:e,variationSlug:l||"default",allAssets:h,onNavigate:O})]})}const S1=d.memo(b1);function C1({stepCount:e,assetCount:t=0,hasAssets:s=!1,lastPublishAt:r}){const i=e>0,a=s,o=!!r;return n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsxs("div",{className:Y("flex items-center gap-1 px-2 py-1 rounded-full border",i?"bg-green-500/10 border-green-500/30 text-green-500":"bg-muted/50 border-border text-muted-foreground"),children:[i?n.jsx(vt,{className:"h-3 w-3"}):n.jsx(na,{className:"h-3 w-3"}),n.jsx(Rn,{className:"h-3 w-3"}),n.jsxs("span",{children:[e," steps"]})]}),n.jsx("span",{className:"text-muted-foreground",children:"→"}),n.jsxs("div",{className:Y("flex items-center gap-1 px-2 py-1 rounded-full border",a?"bg-green-500/10 border-green-500/30 text-green-500":"bg-muted/50 border-border text-muted-foreground"),children:[a?n.jsx(vt,{className:"h-3 w-3"}):n.jsx(na,{className:"h-3 w-3"}),n.jsx(fn,{className:"h-3 w-3"}),n.jsxs("span",{children:[t," assets"]})]}),n.jsx("span",{className:"text-muted-foreground",children:"→"}),n.jsxs("div",{className:Y("flex items-center gap-1 px-2 py-1 rounded-full border",o?"bg-green-500/10 border-green-500/30 text-green-500":"bg-muted/50 border-border text-muted-foreground"),children:[o?n.jsx(vt,{className:"h-3 w-3"}):n.jsx(na,{className:"h-3 w-3"}),n.jsx(on,{className:"h-3 w-3"}),n.jsx("span",{children:o?"Published":"Not published"})]})]})}const E1={locale:n.jsx(ur,{className:"h-4 w-4"}),role:n.jsx(xr,{className:"h-4 w-4"}),theme:n.jsx(Xc,{className:"h-4 w-4"})};function R1({variantsConfig:e,value:t,preset:s,onChange:r}){var x;const[i,a]=d.useState(s?"preset":"custom"),[o,l]=d.useState(!1),c=(e==null?void 0:e.dimensions)||{},u=(e==null?void 0:e.presets)||{},m=Object.keys(c),f=Object.keys(u),g=i==="preset"&&s&&((x=u[s])!=null&&x.values)?u[s].values:t||{},R=()=>{var N,S;const w=[];if(!g||typeof g!="object")return w;for(const[P,b]of Object.entries(g)){const O=(S=(N=c[P])==null?void 0:N.options)==null?void 0:S[b];if(O!=null&&O.inject)for(const D of O.inject)switch(D.method){case"localStorage":w.push({method:"localStorage",details:`${D.key} = "${D.value}"`});break;case"sessionStorage":w.push({method:"sessionStorage",details:`${D.key} = "${D.value}"`});break;case"cookie":w.push({method:"cookie",details:`${D.name} = "${D.value}"`});break;case"urlParam":w.push({method:"URL param",details:`?${D.param}=${D.value}`});break;case"browser":D.locale&&w.push({method:"browser",details:`locale: ${D.locale}`}),D.timezone&&w.push({method:"browser",details:`timezone: ${D.timezone}`});break;case"header":w.push({method:"HTTP header",details:`${D.header}: ${D.value}`});break;case"script":w.push({method:"script",details:"Custom JS"});break}}return w},k=(w,N)=>{const S={...t,[w]:N};a("custom"),r(S,void 0)},C=w=>{a("preset"),r({},w)},j=()=>{a("custom"),r({},void 0)},p=Object.keys(g).length>0||s,h=R();return m.length===0&&f.length===0?n.jsx(he,{className:"bg-gray-800/50 border-gray-700",children:n.jsxs(me,{className:"py-6 text-center text-gray-400",children:[n.jsx(Kr,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),n.jsx("p",{className:"text-sm",children:"No variant dimensions configured."}),n.jsx("p",{className:"text-xs mt-1",children:"Add dimensions in reshot.config.json under variants.dimensions"})]})}):n.jsxs("div",{className:"space-y-4",children:[f.length>0&&n.jsxs(hd,{value:i,onValueChange:w=>a(w),children:[n.jsxs(fd,{className:"grid w-full grid-cols-2",children:[n.jsxs(sr,{value:"preset",children:[n.jsx(a0,{className:"h-3 w-3 mr-1"}),"Preset"]}),n.jsxs(sr,{value:"custom",children:[n.jsx(Kr,{className:"h-3 w-3 mr-1"}),"Custom"]})]}),n.jsx(nr,{value:"preset",className:"mt-4",children:n.jsx("div",{className:"grid gap-2",children:f.map(w=>{const N=u[w];if(!N)return null;const S=s===w,P=N.values||{};return n.jsxs("button",{onClick:()=>C(w),className:`w-full text-left p-3 rounded-lg border transition-colors ${S?"bg-blue-500/20 border-blue-500":"bg-gray-800 border-gray-700 hover:border-gray-600"}`,children:[n.jsx("div",{className:"font-medium text-sm",children:N.name||w}),N.description&&n.jsx("div",{className:"text-xs text-gray-400 mt-1",children:N.description}),n.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:Object.entries(P).map(([b,O])=>{var D,v,L,V;return n.jsxs(ue,{variant:"secondary",className:"text-xs",children:[((D=c[b])==null?void 0:D.label)||b,":"," ",((V=(L=(v=c[b])==null?void 0:v.options)==null?void 0:L[O])==null?void 0:V.name)||O]},b)})})]},w)})})}),n.jsx(nr,{value:"custom",className:"mt-4",children:n.jsx(jh,{dimensions:c,values:t,onChange:k})})]}),f.length===0&&n.jsx(jh,{dimensions:c,values:t,onChange:k}),p&&n.jsxs(he,{className:"bg-gray-800/50 border-gray-700",children:[n.jsx(ke,{className:"py-3 px-4",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs(be,{className:"text-sm font-medium flex items-center gap-2",children:[n.jsx(Kr,{className:"h-4 w-4"}),"Active Variant"]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs(T,{variant:"ghost",size:"sm",onClick:()=>l(!o),className:"h-7 px-2",children:[o?n.jsx(Yc,{className:"h-3 w-3"}):n.jsx(zs,{className:"h-3 w-3"}),o?"Hide":"Show"," Details"]}),n.jsx(T,{variant:"ghost",size:"sm",onClick:j,className:"h-7 px-2 text-gray-400 hover:text-white",children:"Clear"})]})]})}),o&&h.length>0&&n.jsxs(me,{className:"py-3 px-4 border-t border-gray-700",children:[n.jsx("div",{className:"text-xs text-gray-400 mb-2",children:"Injections that will be applied:"}),n.jsx("div",{className:"space-y-1",children:h.map((w,N)=>n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx(ue,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:w.method}),n.jsx("code",{className:"text-gray-300",children:w.details})]},N))})]})]})]})}function jh({dimensions:e,values:t,onChange:s}){return!e||typeof e!="object"?null:n.jsx("div",{className:"space-y-4",children:Object.entries(e).map(([r,i])=>!(i!=null&&i.options)||typeof i.options!="object"?null:n.jsxs("div",{children:[n.jsxs(q,{className:"flex items-center gap-2 mb-2",children:[E1[r]||n.jsx(Kr,{className:"h-4 w-4"}),i.label]}),i.description&&n.jsx("p",{className:"text-xs text-gray-400 mb-2",children:i.description}),n.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[n.jsx("button",{onClick:()=>{({...t},s(r,""))},className:`p-2 rounded-md border text-sm transition-colors ${t[r]?"bg-gray-800 border-gray-700 hover:border-gray-600":"bg-gray-700 border-gray-500"}`,children:"Default"}),Object.entries(i.options).map(([a,o])=>n.jsx("button",{onClick:()=>s(r,a),className:`p-2 rounded-md border text-sm transition-colors ${t[r]===a?"bg-blue-500/20 border-blue-500":"bg-gray-800 border-gray-700 hover:border-gray-600"}`,children:(o==null?void 0:o.name)||a},a))]})]},r))})}function _1({scenarioKey:e,className:t,showActions:s=!0,onStatusChange:r}){const[i,a]=d.useState(null),[o,l]=d.useState(!1),c=d.useCallback(async()=>{var m,f;try{const k=((f=(m=(await(await fetch("/api/workspace")).json()).workspace)==null?void 0:m.scenarios)==null?void 0:f.includes(e))||!1;a(k)}catch{a(!1)}},[e]);d.useEffect(()=>{c()},[c]);const u=async()=>{l(!0);try{i?(await fetch(`/api/workspace/scenarios/${encodeURIComponent(e)}`,{method:"DELETE"}),a(!1),r==null||r(!1)):(await fetch("/api/workspace/scenarios",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:[e]})}),a(!0),r==null||r(!0))}catch{c()}finally{l(!1)}};return i===null?null:n.jsxs("div",{className:Y("flex items-center gap-1.5",t),children:[n.jsx(ue,{variant:i?"default":"secondary",className:Y("text-[10px] h-5 px-2 font-medium",i&&"bg-primary/90"),children:i?"In Workspace":"Not in Workspace"}),s&&n.jsx(T,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:u,disabled:o,title:i?"Remove from workspace":"Add to workspace",children:o?n.jsx(_e,{className:"h-3.5 w-3.5 animate-spin"}):i?n.jsx(Iy,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-destructive"}):n.jsx(Dy,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-primary"})})]})}function P1({open:e,onOpenChange:t,imageUrl:s,currentCrop:r,onSave:i,scenarioName:a}){const o=d.useRef(null),l=d.useRef(null),[c,u]=d.useState(!1),[m,f]=d.useState(!1),[g,R]=d.useState(null),[k,C]=d.useState({x:0,y:0}),[j,p]=d.useState(null),[h,x]=d.useState((r==null?void 0:r.region)||null),[w,N]=d.useState(!1),[S,P]=d.useState(!1);d.useEffect(()=>{e&&(N(!1),P(!1),p(null),x((r==null?void 0:r.region)||null))},[e,r]);const b=d.useCallback((_,F)=>{if(!l.current||!o.current)return{x:0,y:0};const $=l.current.getBoundingClientRect(),E=o.current.getBoundingClientRect(),A=l.current.naturalWidth/$.width,z=l.current.naturalHeight/$.height,W=_-($.left-E.left),J=F-($.top-E.top);return{x:Math.round(W*A),y:Math.round(J*z)}},[]);d.useEffect(()=>{if(w&&(r!=null&&r.region)&&l.current&&o.current){const _=l.current.getBoundingClientRect(),F=o.current.getBoundingClientRect(),$=_.width/l.current.naturalWidth,E=_.height/l.current.naturalHeight,A=_.left-F.left,z=_.top-F.top;p({left:A+r.region.x*$,top:z+r.region.y*E,width:r.region.width*$,height:r.region.height*E}),x(r.region)}},[w,r]);const O=_=>{if(!o.current)return;const F=_.target,$=o.current.getBoundingClientRect(),E=_.clientX-$.left,A=_.clientY-$.top;if(F.dataset.handle){f(!0),R(F.dataset.handle),C({x:_.clientX,y:_.clientY});return}u(!0),C({x:E,y:A}),p({left:E,top:A,width:0,height:0})},D=_=>{if(!o.current)return;const F=o.current.getBoundingClientRect();if(c){const $=_.clientX-F.left,E=_.clientY-F.top,A=$-k.x,z=E-k.y;p({left:A<0?$:k.x,top:z<0?E:k.y,width:Math.abs(A),height:Math.abs(z)})}else if(m&&j&&g){const $=_.clientX-k.x,E=_.clientY-k.y;let A={...j};g.includes("e")&&(A.width=Math.max(10,j.width+$)),g.includes("w")&&(A.left=j.left+$,A.width=Math.max(10,j.width-$)),g.includes("s")&&(A.height=Math.max(10,j.height+E)),g.includes("n")&&(A.top=j.top+E,A.height=Math.max(10,j.height-E)),p(A),C({x:_.clientX,y:_.clientY})}},v=()=>{if((c||m)&&j&&j.width>5&&j.height>5){const _=b(j.left,j.top),F=b(j.left+j.width,j.top+j.height);x({x:Math.max(0,_.x),y:Math.max(0,_.y),width:Math.max(1,F.x-_.x),height:Math.max(1,F.y-_.y)})}u(!1),f(!1),R(null)},L=()=>{p(null),x(null)},V=()=>{h&&h.width>0&&h.height>0?i({enabled:!0,region:h}):i(null),t(!1)},y=()=>{i(null),t(!1)};return n.jsx(st,{open:e,onOpenChange:t,children:n.jsxs(nt,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[n.jsxs(Xe,{children:[n.jsxs(Ze,{className:"flex items-center gap-2",children:[n.jsx(ra,{className:"h-5 w-5"}),"Configure Crop Region"]}),n.jsx(ot,{children:a?`Drag to select the crop region for "${a}". This will apply to all captures.`:"Drag to select the crop region. This will apply to all captures."})]}),n.jsxs("div",{className:"flex-1 min-h-0 py-4",children:[s?S?n.jsx("div",{className:"flex items-center justify-center h-64 bg-muted rounded-lg",children:n.jsxs("div",{className:"text-center text-muted-foreground",children:[n.jsx(Jt,{className:"h-8 w-8 mx-auto mb-2"}),n.jsx("p",{className:"text-sm",children:"Failed to load image."})]})}):n.jsxs("div",{ref:o,className:"relative mx-auto select-none overflow-auto max-h-[50vh] border rounded-lg bg-zinc-900",style:{cursor:c?"crosshair":"default"},onMouseDown:O,onMouseMove:D,onMouseUp:v,onMouseLeave:v,children:[n.jsx("img",{ref:l,src:s,alt:"Reference screenshot",className:"block max-w-full",style:{maxHeight:"50vh"},onLoad:()=>N(!0),onError:()=>P(!0),draggable:!1}),j&&j.width>0&&j.height>0&&n.jsxs("div",{className:"absolute border-2 border-green-500 bg-green-500/10 pointer-events-none",style:{left:j.left,top:j.top,width:j.width,height:j.height,boxShadow:"0 0 0 9999px rgba(0, 0, 0, 0.5)"},children:[n.jsx("div",{"data-handle":"nw",className:"absolute -left-1.5 -top-1.5 w-3 h-3 bg-green-500 border border-white cursor-nw-resize pointer-events-auto"}),n.jsx("div",{"data-handle":"ne",className:"absolute -right-1.5 -top-1.5 w-3 h-3 bg-green-500 border border-white cursor-ne-resize pointer-events-auto"}),n.jsx("div",{"data-handle":"sw",className:"absolute -left-1.5 -bottom-1.5 w-3 h-3 bg-green-500 border border-white cursor-sw-resize pointer-events-auto"}),n.jsx("div",{"data-handle":"se",className:"absolute -right-1.5 -bottom-1.5 w-3 h-3 bg-green-500 border border-white cursor-se-resize pointer-events-auto"}),n.jsx("div",{"data-handle":"n",className:"absolute left-1/2 -translate-x-1/2 -top-1.5 w-3 h-3 bg-green-500 border border-white cursor-n-resize pointer-events-auto"}),n.jsx("div",{"data-handle":"s",className:"absolute left-1/2 -translate-x-1/2 -bottom-1.5 w-3 h-3 bg-green-500 border border-white cursor-s-resize pointer-events-auto"}),n.jsx("div",{"data-handle":"w",className:"absolute -left-1.5 top-1/2 -translate-y-1/2 w-3 h-3 bg-green-500 border border-white cursor-w-resize pointer-events-auto"}),n.jsx("div",{"data-handle":"e",className:"absolute -right-1.5 top-1/2 -translate-y-1/2 w-3 h-3 bg-green-500 border border-white cursor-e-resize pointer-events-auto"})]})]}):n.jsx("div",{className:"flex items-center justify-center h-64 bg-muted rounded-lg",children:n.jsxs("div",{className:"text-center text-muted-foreground",children:[n.jsx(Jt,{className:"h-8 w-8 mx-auto mb-2"}),n.jsx("p",{className:"text-sm",children:"No reference image available."}),n.jsx("p",{className:"text-xs mt-1",children:"Run the scenario first to capture an image."})]})}),h&&n.jsxs("div",{className:"mt-3 p-2 bg-muted rounded text-xs font-mono text-center",children:["Crop: x=",h.x,", y=",h.y,", ",h.width,"×",h.height,"px"]})]}),n.jsxs(lt,{className:"flex-shrink-0 gap-2",children:[(r==null?void 0:r.enabled)&&n.jsxs(T,{variant:"outline",onClick:y,className:"mr-auto",children:[n.jsx(ln,{className:"h-4 w-4 mr-2"}),"Disable Crop"]}),n.jsxs(T,{variant:"outline",onClick:L,disabled:!j,children:[n.jsx(Wl,{className:"h-4 w-4 mr-2"}),"Reset"]}),n.jsx(T,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),n.jsxs(T,{onClick:V,disabled:!s||!h&&!(r!=null&&r.enabled),children:[n.jsx(ro,{className:"h-4 w-4 mr-2"}),"Save Crop"]})]})]})})}const wh="reshot-scenario-tab";function T1(){var mn,gd,vd,yd,jd,wd,Nd,kd,bd,Sd,Cd,Ed,Rd,_d,Pd,Td,Ad,Od,zd,Ld,Md,Id,Dd,Fd,$d;const{key:e}=Kp(),t=Os(),[s]=ky(),{trackJob:r}=ji(),[i,a]=d.useState(null),[o,l]=d.useState({}),[c,u]=d.useState(!0),[m,f]=d.useState(!1),g=e??"",R=()=>{const M=s.get("tab");if(M&&["details","steps","assets"].includes(M))return M;const Q=localStorage.getItem(wh);return Q&&["details","steps","assets"].includes(Q)?Q:"details"},[k,C]=d.useState(R),[j,p]=d.useState(null),[h,x]=d.useState(!1),[w,N]=d.useState(!1),[S,P]=d.useState(!1),[b,O]=d.useState(!1),[D,v]=d.useState("step-by-step-images"),[L,V]=d.useState({}),[y,_]=d.useState(!1),[F,$]=d.useState(null),[E,A]=d.useState(!0),[z,W]=d.useState(null),[J,G]=d.useState(null),[fe,ye]=d.useState(!1),[ge,Re]=d.useState(!1),[U,X]=d.useState({}),[Z,ce]=d.useState([]),[ie,ae]=d.useState(0),[Se,Ie]=d.useState(!1),[mt,Nt]=d.useState(!1),[Ft,Yt]=d.useState(null),[$t,kt]=d.useState(!1),[Tt,Vt]=d.useState(0),{toast:je}=Pt();d.useEffect(()=>{fetch("/api/settings").then(M=>M.json()).then(M=>{var Q;Yt(((Q=M.settings)==null?void 0:Q.isAuthenticated)||!1)}).catch(()=>Yt(!1)),fetch("/api/config").then(M=>M.json()).then(M=>{var Q,le;A(((le=(Q=M.config)==null?void 0:Q.diffing)==null?void 0:le.enabled)!==!1)}).catch(()=>{}),fetch("/api/privacy").then(M=>M.json()).then(M=>{var Q;return ye(M.enabled&&((Q=M.selectors)==null?void 0:Q.length)>0)}).catch(()=>{}),fetch("/api/style").then(M=>M.json()).then(M=>Re(M.enabled!==!1)).catch(()=>{})},[]);const B=d.useCallback(M=>{C(M),localStorage.setItem(wh,M)},[]);d.useEffect(()=>{const M=s.get("tab");M&&["details","steps","assets"].includes(M)&&C(M)},[]);const oe=d.useCallback(()=>{Ft===!1?Nt(!0):Ie(!0)},[Ft]),se=d.useCallback(()=>{Yt(!0),je({title:"Connected",description:"Successfully connected to Reshot platform. You can now publish.",variant:"success"}),setTimeout(()=>Ie(!0),300)},[je]),re=d.useCallback(()=>{e&&(u(!0),fetch(`/api/config/scenarios/${e}`).then(M=>M.json()).then(M=>{a(M.scenario),u(!1)}).catch(M=>{console.error("Failed to load scenario:",M),u(!1)}),fetch("/api/config").then(M=>M.json()).then(M=>{var ne;const Q=((ne=M.config)==null?void 0:ne.variants)||{};l(Q);const le=(Q==null?void 0:Q.dimensions)||{};Object.keys(le).length>0&&_(!0)}).catch(M=>{console.error("Failed to load config:",M)}))},[e]);d.useEffect(()=>{re()},[re]),d.useEffect(()=>{e&&fetch("/api/output").then(M=>M.json()).then(M=>{const le=(M.groups||[]).filter(Te=>Te.scenarioKey===e),ne={};let de=0;le.forEach(Te=>{fetch(`/api/output/${Te.scenarioKey}/${Te.variationSlug}`).then(cs=>cs.json()).then(cs=>{var et;(et=cs.assets)==null||et.forEach(xt=>{const zn=xt.filename.replace(/\.[^/.]+$/,"");ne[zn]||(ne[zn]=xt.url,de++)}),X({...ne}),ae(de)}).catch(()=>{})})}).catch(()=>{})},[e]);const[qe,De]=d.useState(0),At=d.useRef(new Set);d.useEffect(()=>{const M=()=>{fetch("/api/jobs?limit=10").then(le=>le.json()).then(le=>{const ne=le.jobs||[],de=ne.filter(et=>et.scenarioKey===e&&(et.status==="running"||et.status==="pending")),Te=new Set(de.map(et=>et.id)),cs=At.current;for(const et of cs)if(!Te.has(et)){const xt=ne.find(zn=>zn.id===et);if(xt&&(xt.type==="run"||xt.type==="capture")){Vt(zn=>zn+1);break}}At.current=Te,ce(de)}).catch(()=>{})};if(M(),qe===0&&Z.length===0)return;const Q=setInterval(M,2e3);return()=>clearInterval(Q)},[e,Z.length,qe]);const I=Fm(re),ee=async()=>{if(!(!i||!e)){f(!0);try{const M=await fetch(`/api/config/scenarios/${e}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(M.ok)je({title:"Success",description:"Scenario saved successfully",variant:"success"});else{const Q=await M.json();je({title:"Error",description:Q.error||"Failed to save scenario",variant:"destructive"})}}catch(M){console.error("Failed to save scenario:",M),je({title:"Error",description:"Failed to save scenario",variant:"destructive"})}finally{f(!1)}}},pe=async()=>{if(e)try{const M=await fetch(`/api/config/scenarios/${e}`,{method:"DELETE"});if(M.ok)je({title:"Success",description:"Scenario deleted successfully",variant:"success"}),t("/scenarios");else{const Q=await M.json();je({title:"Error",description:Q.error||"Failed to delete scenario",variant:"destructive"})}}catch(M){console.error("Failed to delete scenario:",M),je({title:"Error",description:"Failed to delete scenario",variant:"destructive"})}},Ce=()=>{p(null),x(!0)},Oe=M=>{p(M),x(!0)},Ge=async M=>{if(!(!e||!i||!i.steps))try{const Q=await fetch(`/api/config/scenarios/${e}/steps/${M}`,{method:"DELETE"});if(Q.ok){const le=i.steps.filter((ne,de)=>de!==M);a({...i,steps:le}),je({title:"Success",description:"Step deleted successfully",variant:"success"})}else{const le=await Q.json();je({title:"Error",description:le.error||"Failed to delete step",variant:"destructive"})}}catch(Q){console.error("Failed to delete step:",Q),je({title:"Error",description:"Failed to delete step",variant:"destructive"})}},ls=async M=>{if(!e||!i||!i.steps)return;const Q=i.steps[M];if(!Q)return;const le={...Q};try{const ne=await fetch(`/api/config/scenarios/${e}/steps`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(le)});if(ne.ok){const de=[...i.steps];de.splice(M+1,0,le),a({...i,steps:de}),je({title:"Success",description:"Step duplicated successfully",variant:"success"})}else{const de=await ne.json();je({title:"Error",description:de.error||"Failed to duplicate step",variant:"destructive"})}}catch(ne){console.error("Failed to duplicate step:",ne),je({title:"Error",description:"Failed to duplicate step",variant:"destructive"})}},pn=async(M,Q)=>{if(!e||!i||!i.steps)return;const le=Q==="up"?M-1:M+1;if(le<0||le>=i.steps.length)return;const ne=[...i.steps];[ne[M],ne[le]]=[ne[le],ne[M]],ne.forEach((de,Te)=>{de.order!==void 0&&(de.order=Te)});try{const de=await fetch(`/api/config/scenarios/${e}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({steps:ne})});if(de.ok)a({...i,steps:ne}),je({title:"Success",description:"Step reordered successfully",variant:"success"});else{const Te=await de.json();je({title:"Error",description:Te.error||"Failed to reorder step",variant:"destructive"})}}catch(de){console.error("Failed to reorder step:",de),je({title:"Error",description:"Failed to reorder step",variant:"destructive"})}},ki=async M=>{if(!e||!i)return;const Q=i.steps||[];try{if(j!==null){const le=await fetch(`/api/config/scenarios/${e}/steps/${j}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(M)});if(le.ok){const ne=[...Q];ne[j]=M,a({...i,steps:ne}),je({title:"Success",description:"Step updated successfully",variant:"success"}),x(!1)}else{const ne=await le.json();je({title:"Error",description:ne.error||"Failed to update step",variant:"destructive"})}}else{const le=await fetch(`/api/config/scenarios/${e}/steps`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(M)});if(le.ok){const ne=[...Q,M];a({...i,steps:ne}),je({title:"Success",description:"Step added successfully",variant:"success"}),x(!1)}else{const ne=await le.json();je({title:"Error",description:ne.error||"Failed to add step",variant:"destructive"})}}}catch(le){console.error("Failed to save step:",le),je({title:"Error",description:"Failed to save step",variant:"destructive"})}};return c?n.jsx("div",{className:"p-8",children:n.jsx("div",{className:"text-muted-foreground",children:"Loading scenario..."})}):i?n.jsxs("div",{"data-testid":"studio-scenario-detail","data-loaded":"true",className:"p-4 space-y-3",children:[n.jsxs("div",{className:"flex items-center justify-between gap-4",children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx(T,{variant:"ghost",size:"icon",onClick:()=>t("/scenarios"),className:"h-7 w-7 flex-shrink-0",children:n.jsx(Bl,{className:"h-4 w-4"})}),n.jsxs("div",{className:"min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("h1",{className:"text-lg font-semibold truncate",children:i.name}),e&&n.jsx(_1,{scenarioKey:e})]}),n.jsx("p",{className:"text-[10px] text-muted-foreground font-mono truncate",children:i.key})]})]}),n.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[n.jsx(T,{variant:"ghost",size:"icon",onClick:I,disabled:c,className:"h-7 w-7",children:n.jsx(_t,{className:`h-3.5 w-3.5 ${c?"animate-spin":""}`})}),n.jsxs(T,{size:"sm",className:"h-7 text-xs",onClick:()=>{V((i==null?void 0:i.variant)||{}),_(!1),O(!0)},children:[n.jsx(Ts,{className:"h-3 w-3 mr-1"}),"Run"]}),n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:oe,children:[n.jsx(on,{className:"h-3 w-3 mr-1"}),"Publish"]}),n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>t(`/recorder?scenario=${e}`),children:[n.jsx(_n,{className:"h-3 w-3 mr-1"}),"Record"]}),n.jsx(T,{variant:"ghost",size:"icon",onClick:ee,disabled:m,className:"h-7 w-7",children:n.jsx(Hr,{className:"h-3.5 w-3.5"})}),n.jsx(T,{variant:"ghost",size:"icon",onClick:()=>N(!0),className:"h-7 w-7 text-destructive hover:text-destructive",children:n.jsx(ps,{className:"h-3.5 w-3.5"})})]})]}),n.jsx("div",{className:"flex items-center gap-4 flex-wrap",children:n.jsx(C1,{scenarioKey:g,scenarioName:i.name,stepCount:((mn=i.steps)==null?void 0:mn.length)||0,assetCount:ie,hasAssets:ie>0})}),n.jsxs(hd,{value:k,onValueChange:B,children:[n.jsxs(fd,{className:"h-8",children:[n.jsx(sr,{value:"details",className:"text-xs h-7",children:"Details"}),n.jsxs(sr,{value:"steps",className:"text-xs h-7",children:["Steps (",((gd=i.steps)==null?void 0:gd.length)||0,")"]}),n.jsx(sr,{value:"assets",className:"text-xs h-7",children:"Assets"})]}),n.jsx(nr,{value:"details",className:"mt-3",children:n.jsxs("div",{className:"border rounded-lg bg-card p-4 space-y-4",children:[n.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[n.jsxs("div",{children:[n.jsx(q,{htmlFor:"scenario-name",className:"text-xs",children:"Name"}),n.jsx(ve,{id:"scenario-name",value:i.name,onChange:M=>a({...i,name:M.target.value}),className:"h-8 text-sm"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"scenario-key",className:"text-xs",children:"Key"}),n.jsx(ve,{id:"scenario-key",value:i.key,disabled:!0,className:"h-8 text-sm font-mono bg-muted"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"scenario-url",className:"text-xs",children:"URL"}),n.jsx(ve,{id:"scenario-url",value:i.url,onChange:M=>a({...i,url:M.target.value}),className:"h-8 text-sm"})]})]}),n.jsxs("details",{className:"group",children:[n.jsxs("summary",{className:"text-xs font-medium cursor-pointer hover:text-primary",children:["Capture Variants"," ",n.jsxs("span",{className:"text-muted-foreground",children:["(",Object.keys(i.variant||{}).length," configured)"]})]}),n.jsx("div",{className:"mt-2 pl-2 border-l-2 border-border",children:n.jsx(R1,{variantsConfig:o,value:i.variant||{},preset:i.variantPreset,onChange:(M,Q)=>{a({...i,variant:Object.keys(M).length>0?M:void 0,variantPreset:Q,locale:void 0,role:void 0})}})})]}),n.jsxs("details",{className:"group",children:[n.jsxs("summary",{className:"text-xs font-medium cursor-pointer hover:text-primary flex items-center gap-1",children:[n.jsx(ra,{className:"h-3 w-3"}),"Output Crop"," ",n.jsxs("span",{className:"text-muted-foreground",children:["(",(yd=(vd=i.output)==null?void 0:vd.crop)!=null&&yd.enabled?"enabled":"disabled",")"]})]}),n.jsxs("div",{className:"mt-2 pl-2 border-l-2 border-border space-y-2",children:[n.jsx("p",{className:"text-xs text-muted-foreground",children:"Crop all captures to focus on a specific region of the screen."}),((wd=(jd=i.output)==null?void 0:jd.crop)==null?void 0:wd.enabled)&&((kd=(Nd=i.output)==null?void 0:Nd.crop)==null?void 0:kd.region)&&n.jsxs("div",{className:"text-xs font-mono bg-muted px-2 py-1 rounded",children:["Region: ",i.output.crop.region.x,","," ",i.output.crop.region.y," →"," ",i.output.crop.region.width,"×",i.output.crop.region.height,"px"]}),n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>kt(!0),children:[n.jsx(ra,{className:"h-3 w-3 mr-1"}),(Sd=(bd=i.output)==null?void 0:bd.crop)!=null&&Sd.enabled?"Edit Crop Region":"Configure Crop"]}),((Ed=(Cd=i.output)==null?void 0:Cd.crop)==null?void 0:Ed.enabled)&&n.jsx(T,{variant:"ghost",size:"sm",className:"h-7 text-xs text-muted-foreground",onClick:()=>{a({...i,output:{...i.output,crop:void 0}})},children:"Disable Crop"})]})]}),n.jsxs("details",{className:"group",children:[n.jsxs("summary",{className:"text-xs font-medium cursor-pointer hover:text-primary flex items-center gap-1",children:[n.jsx(xr,{className:"h-3 w-3"}),"Privacy Override"," ",n.jsxs("span",{className:"text-muted-foreground",children:["(",i.privacy?"overridden":"inheriting global",")"]})]}),n.jsxs("div",{className:"mt-2 pl-2 border-l-2 border-border space-y-2",children:[n.jsxs("label",{className:"flex items-center gap-2 text-xs",children:[n.jsx("input",{type:"checkbox",checked:!!i.privacy,onChange:M=>{if(M.target.checked)a({...i,privacy:{enabled:!0,method:"redact",selectors:[]}});else{const{privacy:Q,...le}=i;a(le)}},className:"rounded h-3.5 w-3.5"}),"Override global privacy config for this scenario"]}),i.privacy&&n.jsxs("div",{className:"space-y-2 pt-1",children:[n.jsx("div",{className:"flex gap-1",children:["redact","blur","hide","remove"].map(M=>{var Q;return n.jsx(T,{variant:((Q=i.privacy)==null?void 0:Q.method)===M?"default":"outline",size:"sm",className:"h-6 text-[10px] flex-1 capitalize",onClick:()=>a({...i,privacy:{...i.privacy,method:M}}),children:M},M)})}),n.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Additional selectors for this scenario (additive with global)"})]})]})]}),n.jsxs("details",{className:"group",children:[n.jsxs("summary",{className:"text-xs font-medium cursor-pointer hover:text-primary flex items-center gap-1",children:[n.jsx(ao,{className:"h-3 w-3"}),"Style Override"," ",n.jsxs("span",{className:"text-muted-foreground",children:["(",i.style?"overridden":"inheriting global",")"]})]}),n.jsxs("div",{className:"mt-2 pl-2 border-l-2 border-border space-y-2",children:[n.jsxs("label",{className:"flex items-center gap-2 text-xs",children:[n.jsx("input",{type:"checkbox",checked:!!i.style,onChange:M=>{if(M.target.checked)a({...i,style:{frame:"none",shadow:"medium",padding:40}});else{const{style:Q,...le}=i;a(le)}},className:"rounded h-3.5 w-3.5"}),"Override global style config for this scenario"]}),i.style&&n.jsxs("div",{className:"space-y-2 pt-1",children:[n.jsxs("div",{className:"space-y-1",children:[n.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Frame"}),n.jsx("div",{className:"flex gap-1",children:["none","macos","windows"].map(M=>{var Q;return n.jsx(T,{variant:((Q=i.style)==null?void 0:Q.frame)===M?"default":"outline",size:"sm",className:"h-6 text-[10px] flex-1 capitalize",onClick:()=>a({...i,style:{...i.style,frame:M}}),children:M==="none"?"None":M==="macos"?"macOS":"Windows"},M)})})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Shadow"}),n.jsx("div",{className:"flex gap-1",children:["none","small","medium","large"].map(M=>{var Q;return n.jsx(T,{variant:((Q=i.style)==null?void 0:Q.shadow)===M?"default":"outline",size:"sm",className:"h-6 text-[10px] flex-1 capitalize",onClick:()=>a({...i,style:{...i.style,shadow:M}}),children:M},M)})})]})]})]})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[n.jsxs("div",{children:[n.jsx(q,{htmlFor:"scenario-description",className:"text-xs",children:"Description"}),n.jsx(uo,{id:"scenario-description",value:((Rd=i._local)==null?void 0:Rd.description)||"",onChange:M=>a({...i,_local:{...i._local||{},description:M.target.value}}),placeholder:"Optional description",rows:2,className:"text-sm"})]}),n.jsxs("div",{children:[n.jsx(q,{htmlFor:"scenario-tags",className:"text-xs",children:"Tags"}),n.jsx(ve,{id:"scenario-tags",value:((Pd=(_d=i._local)==null?void 0:_d.tags)==null?void 0:Pd.join(", "))||"",onChange:M=>{const Q=M.target.value.split(",").map(le=>le.trim()).filter(Boolean);a({...i,_local:{...i._local||{},tags:Q}})},placeholder:"tag1, tag2",className:"h-8 text-sm"}),((Td=i._local)==null?void 0:Td.tags)&&i._local.tags.length>0&&n.jsx("div",{className:"flex gap-1 flex-wrap mt-1",children:i._local.tags.map(M=>n.jsx(ue,{variant:"secondary",className:"text-[10px] h-5",children:M},M))})]})]})]})}),n.jsxs(nr,{value:"steps",className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center justify-between py-1",children:[n.jsxs("span",{className:"text-xs text-muted-foreground",children:[((Ad=i.steps)==null?void 0:Ad.length)||0," steps"]}),n.jsxs(T,{onClick:Ce,size:"sm",className:"h-7 text-xs",children:[n.jsx(as,{className:"h-3 w-3 mr-1"}),"Add"]})]}),n.jsxs("div",{className:"border rounded-md divide-y",children:[(Od=i.steps)==null?void 0:Od.map((M,Q)=>{var Te;const le=M.key||M.captureKey,ne=le?U[le]:null,de=M.action==="screenshot"||M.action==="clip";return n.jsxs("div",{className:"flex items-center gap-2 p-2 hover:bg-accent/30 group",children:[n.jsxs("span",{className:"text-[10px] text-muted-foreground w-4 shrink-0",children:["#",Q+1]}),de&&ne?n.jsx("div",{className:"w-12 h-8 shrink-0 rounded overflow-hidden bg-muted cursor-pointer",onClick:()=>t(`/assets/${e}/default/${le}`),children:n.jsx("img",{src:ne,alt:"",className:"w-full h-full object-cover"})}):n.jsx("div",{className:"w-12 h-8 shrink-0 rounded bg-muted/50 flex items-center justify-center",children:n.jsx("span",{className:"text-[8px] text-muted-foreground",children:"—"})}),n.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[n.jsx(ue,{variant:"outline",className:"text-[10px] h-5 shrink-0",children:M.action}),M.key&&n.jsx(ue,{variant:"secondary",className:"text-[10px] h-5 shrink-0",children:M.key}),M.selector&&n.jsx("code",{className:"text-[10px] text-muted-foreground truncate font-mono",children:M.selector}),M.url&&n.jsx("span",{className:"text-[10px] text-muted-foreground truncate",children:M.url}),M.text&&n.jsxs("span",{className:"text-[10px] text-muted-foreground truncate italic",children:['"',M.text,'"']}),de&&!ne&&n.jsx("span",{className:"text-[10px] text-muted-foreground italic",children:"not generated"})]}),n.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[n.jsx(T,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>pn(Q,"up"),disabled:Q===0,title:"Move up",children:n.jsx(Yc,{className:"h-3 w-3"})}),n.jsx(T,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>pn(Q,"down"),disabled:Q===(((Te=i.steps)==null?void 0:Te.length)||0)-1,title:"Move down",children:n.jsx(zs,{className:"h-3 w-3"})}),n.jsx(T,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>Oe(Q),title:"Edit",children:n.jsx(Gy,{className:"h-3 w-3"})}),n.jsx(T,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>ls(Q),title:"Duplicate",children:n.jsx(rn,{className:"h-3 w-3"})}),n.jsx(T,{variant:"ghost",size:"icon",className:"h-6 w-6 text-destructive hover:text-destructive",onClick:()=>Ge(Q),title:"Delete",children:n.jsx(ln,{className:"h-3 w-3"})})]})]},Q)}),(!i.steps||i.steps.length===0)&&n.jsxs("div",{className:"text-center text-muted-foreground py-6",children:[n.jsx("p",{className:"text-sm",children:"No steps yet."}),n.jsxs(T,{onClick:Ce,variant:"outline",size:"sm",className:"mt-2 h-7 text-xs",children:[n.jsx(as,{className:"h-3 w-3 mr-1"}),"Add First Step"]})]})]}),n.jsx(j1,{open:h,onOpenChange:x,step:j!==null?i.steps[j]:null,onSave:ki,assetUrl:j!==null&&i.steps[j]?U[i.steps[j].key||i.steps[j].captureKey||""]:void 0}),n.jsx(st,{open:w,onOpenChange:N,children:n.jsxs(nt,{children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:"Delete Scenario"}),n.jsx(ot,{children:"Are you sure you want to delete this scenario? This action cannot be undone."})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>N(!1),children:"Cancel"}),n.jsx(T,{variant:"destructive",onClick:()=>{N(!1),pe()},children:"Delete"})]})]})})]}),n.jsx(nr,{value:"assets",className:"space-y-4",forceMount:!0,children:n.jsx(S1,{scenarioKey:g},`assets-${Tt}`)})]}),n.jsx(ho,{open:Se,onOpenChange:Ie,scenarioKeys:e?[e]:[],onConfirm:async M=>{var Q;try{const le=M.reduce((Te,cs)=>Te+cs.assets.length,0),ne=await fetch("/api/jobs/publish",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:e?[e]:[],selectedGroups:M})}),de=await ne.json();if(ne.status===401||de.authRequired){Ie(!1),je({title:"Authentication Required",description:de.error||"Please reconnect to publish.",variant:"destructive"}),Nt(!0);return}ne.ok&&de.ok?(je({title:"Job Created",description:`Publishing ${le} asset(s). Monitor progress in the panel below.`}),Ie(!1),(Q=de.job)!=null&&Q.id&&r(de.job.id,e||void 0),De(Te=>Te+1),setTimeout(()=>De(0),1e4)):je({title:"Error",description:de.error||"Failed to create publish job",variant:"destructive"})}catch{je({title:"Error",description:"Failed to connect to server",variant:"destructive"})}}}),n.jsx(wi,{open:mt,onOpenChange:Nt,onAuthenticated:se}),n.jsx(st,{open:b,onOpenChange:O,children:n.jsxs(nt,{className:"max-w-lg",children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:"Run Scenario"}),n.jsx(ot,{children:"Choose output format and variant options"})]}),n.jsxs("div",{className:"py-4 space-y-5",children:[n.jsxs("div",{className:"space-y-3",children:[n.jsx(q,{className:"text-sm font-medium",children:"Output Format"}),n.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[n.jsx("button",{type:"button",onClick:()=>v("step-by-step-images"),className:`p-3 rounded-lg border-2 text-left transition-all ${D==="step-by-step-images"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(fn,{className:"h-4 w-4"}),n.jsx("span",{className:"font-medium text-sm",children:"Screenshots"})]})}),n.jsx("button",{type:"button",onClick:()=>v("summary-video"),className:`p-3 rounded-lg border-2 text-left transition-all ${D==="summary-video"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(io,{className:"h-4 w-4"}),n.jsx("span",{className:"font-medium text-sm",children:"Video"})]})})]})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(q,{className:"text-sm font-medium",children:"Visual Diffing"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Compare against approved baselines"})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[F===null&&E&&n.jsx("span",{className:"text-xs text-muted-foreground",children:"(config default: on)"}),F===null&&!E&&n.jsx("span",{className:"text-xs text-muted-foreground",children:"(config default: off)"}),n.jsx("input",{type:"checkbox",checked:F===null?E:F,onChange:M=>$(M.target.checked),className:"rounded h-4 w-4"})]})]}),(F===!0||F===null&&E)&&n.jsx("div",{className:"text-xs text-amber-600 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 rounded-md p-2",children:"Diff results will appear in the job log after completion"})]}),n.jsx("div",{className:"space-y-2",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(q,{className:"text-sm font-medium",children:"Privacy Masking"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Hide sensitive elements during capture"})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[z===null&&n.jsxs("span",{className:"text-xs text-muted-foreground",children:["(config default: ",fe?"on":"off",")"]}),n.jsx("input",{type:"checkbox",checked:z===null?fe:!z,onChange:M=>W(M.target.checked?null:!0),className:"rounded h-4 w-4"})]})]})}),n.jsx("div",{className:"space-y-2",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(q,{className:"text-sm font-medium",children:"Style Processing"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Apply frames, shadows, and backgrounds"})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[J===null&&n.jsxs("span",{className:"text-xs text-muted-foreground",children:["(config default: ",ge?"on":"off",")"]}),n.jsx("input",{type:"checkbox",checked:J===null?ge:!J,onChange:M=>G(M.target.checked?null:!0),className:"rounded h-4 w-4"})]})]})}),n.jsx("div",{className:"space-y-2",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(q,{className:"text-sm font-medium",children:"Output Crop"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:(Ld=(zd=i.output)==null?void 0:zd.crop)!=null&&Ld.enabled?`Cropping to ${(Md=i.output.crop.region)==null?void 0:Md.width}×${(Id=i.output.crop.region)==null?void 0:Id.height}px`:"No crop configured"})]}),n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{O(!1),kt(!0)},children:[n.jsx(ra,{className:"h-3 w-3 mr-1"}),(Fd=(Dd=i.output)==null?void 0:Dd.crop)!=null&&Fd.enabled?"Edit":"Configure"]})]})}),(()=>{const M=(o==null?void 0:o.dimensions)||{},Q=Object.keys(M);if(Q.length===0)return n.jsx("div",{className:"text-sm text-muted-foreground bg-muted/50 rounded-md p-3",children:n.jsx("p",{children:"No variants configured. Will run with default settings."})});let le=1;return Q.forEach(ne=>{var Te;const de=Object.keys(((Te=M[ne])==null?void 0:Te.options)||{});le*=de.length||1}),n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"border rounded-lg overflow-hidden",children:n.jsxs("div",{className:"flex",children:[n.jsx("button",{type:"button",onClick:()=>_(!0),className:`flex-1 py-3 px-4 text-sm font-medium transition-all ${y?"bg-primary text-primary-foreground":"bg-muted/30 hover:bg-muted/50"}`,children:n.jsxs("div",{className:"flex flex-col items-center gap-1",children:[n.jsx("span",{className:"text-lg",children:"🎯"}),n.jsxs("span",{children:["All ",le," Variants"]}),n.jsx("span",{className:`text-xs ${y?"text-primary-foreground/70":"text-muted-foreground"}`,children:Q.map(ne=>{var de;return((de=M[ne])==null?void 0:de.label)||ne}).join(" × ")})]})}),n.jsx("button",{type:"button",onClick:()=>_(!1),className:`flex-1 py-3 px-4 text-sm font-medium transition-all border-l ${y?"bg-muted/30 hover:bg-muted/50":"bg-primary text-primary-foreground"}`,children:n.jsxs("div",{className:"flex flex-col items-center gap-1",children:[n.jsx("span",{className:"text-lg",children:"☝️"}),n.jsx("span",{children:"Single Variant"}),n.jsx("span",{className:`text-xs ${y?"text-muted-foreground":"text-primary-foreground/70"}`,children:"Choose specific options"})]})})]})}),!y&&n.jsx("div",{className:"space-y-3 p-3 bg-muted/30 rounded-lg",children:Q.map(ne=>{const de=M[ne],Te=(de==null?void 0:de.options)||{},cs=Object.keys(Te);return n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-sm font-medium",children:(de==null?void 0:de.label)||ne}),n.jsxs($m,{value:L[ne]||cs[0]||"",onValueChange:et=>{V(xt=>({...xt,[ne]:et}))},children:[n.jsx(pd,{className:"w-full",children:n.jsx(Vm,{placeholder:`Select ${(de==null?void 0:de.label)||ne}`})}),n.jsx(md,{children:cs.map(et=>{const xt=Te[et];return n.jsx(xd,{value:et,children:(xt==null?void 0:xt.name)||(xt==null?void 0:xt.label)||et},et)})})]})]},ne)})}),y&&n.jsxs("div",{className:"text-sm bg-green-500/10 dark:bg-green-500/20 border border-green-500/30 rounded-md p-3",children:[n.jsxs("p",{className:"font-medium text-green-700 dark:text-green-400 mb-2",children:["✓ Will capture ",le," variant",le>1?"s":"",":"]}),n.jsx("div",{className:"space-y-1 text-xs text-muted-foreground",children:Q.map(ne=>{var Te;const de=Object.keys(((Te=M[ne])==null?void 0:Te.options)||{});return n.jsxs("div",{children:[n.jsx("span",{className:"font-mono",children:ne}),":"," ",de.join(", ")]},ne)})})]})]})})()]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>O(!1),children:"Cancel"}),n.jsxs(T,{onClick:async()=>{const M=(o==null?void 0:o.dimensions)||{},Q=Object.keys(M);if(y&&Q.length>0){const le=await fetch("/api/jobs/run-all-variations",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKey:e,dimensions:Q,format:D})});if(le.ok){const ne=await le.json();for(const de of ne.jobs)r(de.id,e);O(!1),De(de=>de+1),setTimeout(()=>De(0),1e4)}else{const ne=await le.json();je({title:"Error",description:ne.error||"Failed to start jobs",variant:"destructive"})}}else{const le=await fetch("/api/jobs/run",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:[e],format:D,variant:Object.keys(L).length>0?L:void 0,diff:F,noPrivacy:z===!0?!0:void 0,noStyle:J===!0?!0:void 0})});if(le.ok){const ne=await le.json();r(ne.job.id,e),O(!1),De(de=>de+1),setTimeout(()=>De(0),1e4)}else je({title:"Error",description:"Failed to start job",variant:"destructive"})}},children:[n.jsx(Ts,{className:"h-4 w-4 mr-2"}),y?"Run All Variations":"Run"]})]})]})}),n.jsx(st,{open:S,onOpenChange:P,children:n.jsxs(nt,{children:[n.jsxs(Xe,{children:[n.jsx(Ze,{children:"Record Visual"}),n.jsx(ot,{children:"Start a recording session for this scenario. The recorder will open in your terminal."})]}),n.jsx("div",{className:"py-4",children:n.jsxs("div",{className:"text-sm text-muted-foreground space-y-2",children:[n.jsx("p",{children:"This will start a recording job that:"}),n.jsxs("ul",{className:"list-disc list-inside space-y-1 ml-2",children:[n.jsx("li",{children:"Opens Chrome with remote debugging"}),n.jsx("li",{children:"Connects to the active browser session"}),n.jsx("li",{children:"Allows you to capture steps using keyboard shortcuts"})]}),n.jsx("p",{className:"mt-4 font-medium",children:"Keyboard shortcuts:"}),n.jsxs("ul",{className:"list-disc list-inside space-y-1 ml-2",children:[n.jsxs("li",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded text-xs",children:"C"})," ","- Capture screenshot/clip"]}),n.jsxs("li",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded text-xs",children:"Q"})," ","- Quit and save"]})]})]})}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>P(!1),children:"Cancel"}),n.jsx(T,{onClick:async()=>{try{const M=await fetch("/api/jobs/record",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:i==null?void 0:i.name,scenarioKey:e})}),Q=await M.json();M.ok?(je({title:"Success",description:"Recording job started. Check Jobs page and your terminal.",variant:"success"}),P(!1),De(le=>le+1),setTimeout(()=>De(0),1e4)):je({title:"Error",description:Q.error||"Failed to start recording",variant:"destructive"})}catch{je({title:"Error",description:"Failed to start recording",variant:"destructive"})}},children:"Start Recording"})]})]})}),n.jsx(P1,{open:$t,onOpenChange:kt,imageUrl:Object.values(U)[0]||null,currentCrop:($d=i.output)==null?void 0:$d.crop,scenarioName:i.name,onSave:M=>{a({...i,output:{...i.output,crop:M||void 0}})}})]}):n.jsx("div",{className:"p-8",children:n.jsx(he,{children:n.jsx(ke,{children:n.jsx(be,{children:"Scenario Not Found"})})})})}function Nh(e){const t=e.split("-");return t.length>=2?t[0]:"other"}function A1(e){return e==="other"?"Other":e.split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function O1(){const e=Os(),{toast:t}=Pt(),[,s]=d.useState([]),[r,i]=d.useState(!0),[a,o]=d.useState({}),[l,c]=d.useState(new Set),[u,m]=d.useState(!1),[f,g]=d.useState(new Set),[R,k]=d.useState(!1),[C,j]=d.useState(!1),[p,h]=d.useState(!1),{trackJob:x}=ji(),w=U=>{g(X=>{const Z=new Set(X);return Z.has(U)?Z.delete(U):Z.add(U),Z})},N=U=>{const X=U.every(Z=>f.has(Z));g(Z=>{const ce=new Set(Z);return X?U.forEach(ie=>ce.delete(ie)):U.forEach(ie=>ce.add(ie)),ce})},S=()=>{const U=Object.keys(a);g(new Set(U))},P=()=>{g(new Set)},b=async()=>{if(f.size!==0)try{const U=await fetch("/api/assets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:Array.from(f)})}),X=await U.json();U.ok?(t({title:"Success",description:`Deleted assets for ${X.deletedScenarios||f.size} scenario(s)`,variant:"success"}),k(!1),P(),D()):t({title:"Error",description:X.error||"Failed to delete selected assets",variant:"destructive"})}catch(U){console.error("Failed to delete selected assets:",U),t({title:"Error",description:"Failed to delete selected assets",variant:"destructive"})}},O=async()=>{try{const U=await fetch("/api/assets",{method:"DELETE"}),X=await U.json();U.ok?(t({title:"Success",description:`Deleted ${X.deleted} asset file(s)`,variant:"success"}),m(!1),D()):t({title:"Error",description:X.error||"Failed to delete assets",variant:"destructive"})}catch(U){console.error("Failed to delete assets:",U),t({title:"Error",description:"Failed to delete assets",variant:"destructive"})}},D=async()=>{i(!0);try{const Z=(await(await fetch("/api/output")).json()).groups||[];s(Z);const ce=[...new Set(Z.map(ae=>ae.scenarioKey))],ie={};if(await Promise.all(ce.map(async ae=>{try{const mt=(await(await fetch(`/api/output/${ae}/versions`)).json()).versions||[];mt.length===0&&mt.push({timestamp:"default",label:"Default",date:new Date().toISOString(),assetCount:0,isLatest:!0});const Nt=mt[0].timestamp,Yt=mt[0].variants||[],$t=Yt.length>0?Yt[0].name:null;let kt=[];try{const Tt=$t?`/api/output/${ae}/version/${Nt}/variant/${$t}`:`/api/output/${ae}/version/${Nt}`;kt=((await(await fetch(Tt)).json()).assets||[]).filter(B=>!B.isSentinel)}catch{const Tt=Z.find(Vt=>Vt.scenarioKey===ae);kt=(Tt==null?void 0:Tt.assets)||[]}ie[ae]={scenarioKey:ae,versions:mt,selectedVersion:Nt,selectedVariant:$t,assets:kt,availableVariants:Yt}}catch(Se){console.error(`Failed to fetch versions for ${ae}:`,Se)}})),o(ie),l.size===0){const ae=new Set;Object.values(ie).forEach(Se=>ae.add(Nh(Se.scenarioKey))),c(ae)}i(!1)}catch(U){console.error("Failed to load assets:",U),i(!1)}};d.useEffect(()=>{D()},[]);const v=async(U,X)=>{o(Se=>({...Se,[U]:{...Se[U],selectedVersion:X}}));const Z=a[U],ce=Z==null?void 0:Z.versions.find(Se=>Se.timestamp===X),ie=(ce==null?void 0:ce.variants)||[],ae=ie.length>0?ie[0].name:null;try{const Se=ae?`/api/output/${U}/version/${X}/variant/${ae}`:`/api/output/${U}/version/${X}`,Nt=((await(await fetch(Se)).json()).assets||[]).filter(Ft=>!Ft.isSentinel);o(Ft=>({...Ft,[U]:{...Ft[U],selectedVersion:X,selectedVariant:ae,availableVariants:ie,assets:Nt}}))}catch(Se){console.error(`Failed to fetch assets for ${U}/${X}:`,Se)}},L=async(U,X)=>{const Z=a[U];if(Z){o(ce=>({...ce,[U]:{...ce[U],selectedVariant:X}}));try{const ce=`/api/output/${U}/version/${Z.selectedVersion}/variant/${X}`,Se=((await(await fetch(ce)).json()).assets||[]).filter(Ie=>!Ie.isSentinel);o(Ie=>({...Ie,[U]:{...Ie[U],selectedVariant:X,assets:Se}}))}catch(ce){console.error(`Failed to fetch assets for ${U}/${Z.selectedVersion}/${X}:`,ce)}}},V=U=>U<1024?`${U} B`:U<1024*1024?`${(U/1024).toFixed(1)} KB`:`${(U/(1024*1024)).toFixed(1)} MB`,y=U=>{if(U==="latest"||U==="default")return U;const X=U.match(/(\d{4})-(\d{2})-(\d{2})_(\d{2})-(\d{2})-(\d{2})/);return X?new Date(parseInt(X[1]),parseInt(X[2])-1,parseInt(X[3]),parseInt(X[4]),parseInt(X[5]),parseInt(X[6])).toLocaleString():U},_=U=>U.endsWith(".mp4")?n.jsx(io,{className:"h-4 w-4"}):n.jsx(fn,{className:"h-4 w-4"}),F=Object.values(a),[$,E]=d.useState(""),[A,z]=d.useState("name"),[W,J]=d.useState(!0),G=d.useMemo(()=>{let U=[...F];if($){const X=$.toLowerCase();U=U.filter(Z=>Z.scenarioKey.toLowerCase().includes(X)||Z.assets.some(ce=>ce.captureKey.toLowerCase().includes(X)))}return U.sort((X,Z)=>{let ce=0;switch(A){case"name":ce=X.scenarioKey.localeCompare(Z.scenarioKey);break;case"assets":ce=X.assets.length-Z.assets.length;break;case"versions":ce=X.versions.length-Z.versions.length;break}return W?ce:-ce}),U},[F,$,A,W]),fe=d.useMemo(()=>{const U={};for(const Z of G){const ce=Nh(Z.scenarioKey);U[ce]||(U[ce]=[]),U[ce].push(Z)}return Object.entries(U).sort(([Z],[ce])=>Z==="other"?1:ce==="other"?-1:Z.localeCompare(ce)).map(([Z,ce])=>({key:Z,name:A1(Z),scenarios:ce,totalAssets:ce.reduce((ie,ae)=>ie+ae.assets.length,0),isExpanded:l.has(Z)}))},[G,l]),ye=U=>{c(X=>{const Z=new Set(X);return Z.has(U)?Z.delete(U):Z.add(U),Z})},ge=U=>{A===U?J(!W):(z(U),J(!0))},Re=F.reduce((U,X)=>U+X.assets.length,0);return n.jsxs("div",{"data-testid":"studio-assets","data-loaded":"true",className:"p-5 space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 pb-3",children:[n.jsxs("div",{children:[n.jsx("h1",{className:"text-xl font-bold tracking-tight",children:"Assets"}),n.jsxs("p",{className:"text-xs text-muted-foreground mt-1 font-normal",children:[F.length," scenario(s) · ",Re," asset(s)"]})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx(T,{variant:"outline",size:"icon",onClick:D,disabled:r,title:"Refresh",children:n.jsx(_t,{className:`h-4 w-4 ${r?"animate-spin":""}`})}),f.size>0?n.jsxs(n.Fragment,{children:[n.jsxs(T,{variant:"default",size:"sm",onClick:()=>j(!0),children:[n.jsx(on,{className:"h-3.5 w-3.5 mr-1.5"}),"Publish Selected (",f.size,")"]}),n.jsxs(T,{variant:"outline",size:"sm",onClick:()=>k(!0),className:"text-destructive hover:text-destructive",children:[n.jsx(ps,{className:"h-3.5 w-3.5 mr-1.5"}),"Delete Selected (",f.size,")"]})]}):n.jsxs(T,{variant:"outline",size:"sm",onClick:()=>m(!0),title:"Delete all assets",className:"text-destructive hover:text-destructive",children:[n.jsx(ps,{className:"h-3.5 w-3.5 mr-1.5"}),"Delete All"]})]})]}),F.length>0&&n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[n.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-md",children:[n.jsx(Zc,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),n.jsx(ve,{placeholder:"Search assets...",value:$,onChange:U=>E(U.target.value),className:"pl-9 h-9"})]}),n.jsxs("div",{className:"flex items-center gap-1 text-xs",children:[n.jsx(Gc,{className:"h-3.5 w-3.5 text-muted-foreground mr-1"}),n.jsxs(T,{variant:A==="name"?"secondary":"ghost",size:"sm",className:"h-8 text-xs",onClick:()=>ge("name"),children:["Name ",A==="name"&&(W?"↑":"↓")]}),n.jsxs(T,{variant:A==="assets"?"secondary":"ghost",size:"sm",className:"h-8 text-xs",onClick:()=>ge("assets"),children:["Assets ",A==="assets"&&(W?"↑":"↓")]}),n.jsxs(T,{variant:A==="versions"?"secondary":"ghost",size:"sm",className:"h-8 text-xs",onClick:()=>ge("versions"),children:["Versions ",A==="versions"&&(W?"↑":"↓")]})]}),$&&n.jsxs("span",{className:"text-xs text-muted-foreground",children:[G.length," of ",F.length," scenarios"]})]}),n.jsx("div",{className:"flex items-center gap-3 text-xs",children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(T,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:f.size===F.length?P:S,children:f.size===F.length?n.jsxs(n.Fragment,{children:[n.jsx(Qc,{className:"h-3 w-3 mr-1"}),"Deselect All"]}):n.jsxs(n.Fragment,{children:[n.jsx(ed,{className:"h-3 w-3 mr-1"}),"Select All"]})}),f.size>0&&n.jsxs("span",{className:"text-muted-foreground",children:[f.size," selected"]})]})})]}),r?n.jsx("div",{className:"text-muted-foreground",children:"Loading assets..."}):F.length===0?n.jsx(he,{children:n.jsxs(ke,{children:[n.jsx(be,{children:"No Assets"}),n.jsx(at,{children:"Run a scenario to generate assets"})]})}):G.length===0?n.jsx(he,{children:n.jsxs(me,{className:"py-8 text-center",children:[n.jsxs("p",{className:"text-muted-foreground",children:['No assets match "',$,'"']}),n.jsx(T,{variant:"link",onClick:()=>E(""),children:"Clear search"})]})}):n.jsx("div",{className:"space-y-3",children:fe.map(U=>{const X=U.scenarios.map(ie=>ie.scenarioKey),Z=X.every(ie=>f.has(ie)),ce=X.some(ie=>f.has(ie));return n.jsxs(he,{className:"overflow-hidden",children:[n.jsxs("div",{className:"flex items-center gap-2 p-4 border-b border-border/50",children:[n.jsx(ns,{checked:Z,indeterminate:ce&&!Z,onCheckedChange:()=>N(X),onClick:ie=>ie.stopPropagation(),className:"h-4 w-4"}),n.jsxs("button",{onClick:()=>ye(U.key),className:"flex-1 flex items-center gap-3 text-left hover:bg-accent/50 transition-colors rounded-md px-2 py-1 -my-1",children:[U.isExpanded?n.jsx(zs,{className:"h-4 w-4 text-muted-foreground"}):n.jsx(Ps,{className:"h-4 w-4 text-muted-foreground"}),U.isExpanded?n.jsx(fi,{className:"h-5 w-5 text-primary"}):n.jsx(Xp,{className:"h-5 w-5 text-muted-foreground"}),n.jsxs("div",{className:"flex-1",children:[n.jsx("span",{className:"font-medium",children:U.name}),n.jsxs("span",{className:"text-xs text-muted-foreground ml-2",children:[U.scenarios.length," scenario(s) ·"," ",U.totalAssets," asset(s)"]})]})]})]}),U.isExpanded&&n.jsx("div",{className:"divide-y divide-border/50",children:U.scenarios.map(ie=>n.jsxs("div",{className:"p-4",children:[n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(ns,{checked:f.has(ie.scenarioKey),onCheckedChange:()=>w(ie.scenarioKey),className:"h-4 w-4"}),n.jsx("span",{className:"font-medium text-sm",children:ie.scenarioKey.includes("/")?ie.scenarioKey.split("/").slice(1).join("/"):ie.scenarioKey}),n.jsxs(ue,{variant:"outline",className:"text-[10px]",children:[ie.assets.length," asset(s)"]}),(()=>{var Se,Ie;const ae=ie.versions.find(mt=>mt.timestamp===ie.selectedVersion);return n.jsxs(n.Fragment,{children:[((Se=ae==null?void 0:ae.privacy)==null?void 0:Se.enabled)&&n.jsxs(ue,{variant:"secondary",className:"text-[10px] gap-0.5",children:[n.jsx(xr,{className:"h-2.5 w-2.5"}),ae.privacy.method||"privacy"]}),((Ie=ae==null?void 0:ae.style)==null?void 0:Ie.enabled)&&n.jsxs(ue,{variant:"secondary",className:"text-[10px] gap-0.5",children:[n.jsx(ao,{className:"h-2.5 w-2.5"}),ae.style.frame!=="none"?ae.style.frame:"styled"]})]})})()]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(hi,{className:"h-3.5 w-3.5 text-muted-foreground"}),n.jsx("select",{value:ie.selectedVersion,onChange:ae=>v(ie.scenarioKey,ae.target.value),className:"h-7 px-2 text-xs rounded-md border border-gray-600 bg-gray-800 text-white focus:outline-none focus:ring-2 focus:ring-blue-500",children:ie.versions.map(ae=>n.jsx("option",{value:ae.timestamp,children:ae.timestamp==="latest"?"Latest":ae.timestamp==="default"?"Default":y(ae.timestamp)},ae.timestamp))}),ie.availableVariants.length>0&&ie.selectedVariant&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-muted-foreground text-xs",children:"/"}),n.jsx("select",{value:ie.selectedVariant,onChange:ae=>L(ie.scenarioKey,ae.target.value),className:"h-7 px-2 text-xs rounded-md border border-gray-600 bg-gray-800 text-white focus:outline-none focus:ring-2 focus:ring-blue-500 capitalize",children:ie.availableVariants.map(ae=>n.jsxs("option",{value:ae.name,children:[ae.name," (",ae.assetCount,")"]},ae.name))})]})]})]}),ie.assets.length===0?n.jsx("p",{className:"text-sm text-muted-foreground text-center py-3",children:"No assets in this version"}):n.jsx("div",{className:"grid gap-3 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4",children:ie.assets.map(ae=>n.jsxs("div",{className:"border rounded-md p-2.5 space-y-1.5 cursor-pointer hover:border-primary transition-colors group",onClick:()=>e(`/assets/${ie.scenarioKey}/${ie.selectedVersion}/${ae.captureKey}`),children:[n.jsx(fo,{url:ae.url,filename:ae.filename,size:"sm",showControls:!1}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[_(ae.filename),n.jsx("span",{className:"font-medium text-xs truncate",children:ae.captureKey})]}),n.jsx(ue,{variant:"outline",className:"text-[9px]",children:V(ae.size)})]})]},ae.captureKey))})]},ie.scenarioKey))})]},U.key)})}),n.jsx(st,{open:R,onOpenChange:k,children:n.jsxs(nt,{children:[n.jsxs(Xe,{children:[n.jsx(Ze,{className:"text-destructive",children:"Delete Selected Assets?"}),n.jsxs(ot,{children:["This will permanently delete all assets for"," ",f.size," selected scenario(s). This action cannot be undone."]})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>k(!1),children:"Cancel"}),n.jsxs(T,{variant:"destructive",onClick:b,children:[n.jsx(ps,{className:"h-4 w-4 mr-2"}),"Delete Selected"]})]})]})}),n.jsx(st,{open:u,onOpenChange:m,children:n.jsxs(nt,{children:[n.jsxs(Xe,{children:[n.jsx(Ze,{className:"text-destructive",children:"Delete All Assets?"}),n.jsxs(ot,{children:["This will permanently delete all ",Re," captured asset files from the output folder. This action cannot be undone."]})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"outline",onClick:()=>m(!1),children:"Cancel"}),n.jsxs(T,{variant:"destructive",onClick:O,children:[n.jsx(ps,{className:"h-4 w-4 mr-2"}),"Delete All"]})]})]})}),n.jsx(ho,{open:C,onOpenChange:j,scenarioKeys:Array.from(f),onConfirm:async U=>{var X;try{const Z=U.reduce((ae,Se)=>ae+Se.assets.length,0),ce=await fetch("/api/jobs/publish",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioKeys:Array.from(f),selectedGroups:U})}),ie=await ce.json();if(ce.status===401||ie.authRequired){j(!1),t({title:"Authentication Required",description:ie.error||"Please reconnect to publish.",variant:"destructive"}),h(!0);return}ce.ok&&ie.ok?(t({title:"Job Created",description:`Publishing ${Z} asset(s). Monitor progress in the panel below.`}),j(!1),(X=ie.job)!=null&&X.id&&x(ie.job.id)):t({title:"Error",description:ie.error||"Failed to create publish job",variant:"destructive"})}catch{t({title:"Error",description:"Failed to connect to server",variant:"destructive"})}}}),n.jsx(wi,{open:p,onOpenChange:h,onAuthenticated:()=>{t({title:"Connected",description:"Successfully connected. You can now publish.",variant:"success"}),D()}})]})}function z1(){const{toast:e}=Pt(),t=d.useRef(!0),[s,r]=d.useState(null),[i,a]=d.useState(!0),[o,l]=d.useState(!1),[c,u]=d.useState(!1),[m,f]=d.useState(null),[g,R]=d.useState(!1),[k,C]=d.useState(!1);d.useEffect(()=>()=>{t.current=!1},[]);const j=d.useCallback(async(P=!0)=>{try{P&&a(!0);const b=await fetch("/api/settings");if(!b.ok)throw new Error("Failed to fetch settings");const D=(await b.json()).settings||{};if(!t.current)return;r({isAuthenticated:D.isAuthenticated||!1,projectId:D.projectId||null,projectName:D.projectName||null,workspaceName:D.workspaceName||null,platformUrl:D.platformUrl||null,user:D.user||null,linkedAt:D.linkedAt||null,apiKeyValid:!!D.isAuthenticated,apiKeyWarning:void 0})}catch(b){console.error("Failed to load status:",b),t.current&&e({title:"Error",description:"Failed to load connection status",variant:"destructive"})}finally{t.current&&a(!1)}},[e]);d.useEffect(()=>{j()},[j]);const p=async()=>{l(!0);try{const P=await fetch("/api/auth/refresh",{method:"POST"}),b=await P.json();if(!t.current)return;if(P.status===401||b.authRequired){r(O=>O?{...O,apiKeyValid:!1,apiKeyWarning:b.error||"Please re-authenticate"}:null),e({title:"Authentication Required",description:b.error||"Please re-link to platform",variant:"destructive"});return}b.ok?(r(O=>O?{...O,projectId:b.projectId||O.projectId,projectName:b.projectName||O.projectName,workspaceName:b.workspaceName||O.workspaceName,user:b.user||O.user,linkedAt:b.linkedAt||O.linkedAt,apiKeyValid:!0,apiKeyWarning:void 0}:null),e({title:"Refreshed",description:"Connection info updated from platform",variant:"success"})):b.warning&&(r(O=>O?{...O,apiKeyValid:"unknown",apiKeyWarning:b.warning}:null),e({title:"Warning",description:b.warning}))}catch(P){console.error("Refresh failed:",P),e({title:"Refresh Failed",description:"Could not refresh connection info",variant:"destructive"})}finally{t.current&&l(!1)}},h=async()=>{u(!0);try{const P=await fetch("/api/auth/verify"),b=await P.json();if(!t.current)return;P.status===401?(r(O=>O?{...O,apiKeyValid:!1,apiKeyWarning:b.error||"API key is invalid or expired"}:null),e({title:"Connection Invalid",description:b.error||"Please re-authenticate",variant:"destructive"})):b.valid==="unknown"?(r(O=>O?{...O,apiKeyValid:"unknown",apiKeyWarning:b.warning}:null),e({title:"Status Unknown",description:b.warning||"Could not verify - platform may be unreachable"})):(r(O=>O?{...O,projectId:b.projectId||O.projectId,projectName:b.projectName||O.projectName,workspaceName:b.workspaceName||O.workspaceName,user:b.user||O.user,apiKeyValid:!0,apiKeyWarning:void 0}:null),e({title:"Connection Verified",description:"Your connection is active",variant:"success"}))}catch(P){console.error("Verification failed:",P),e({title:"Verification Failed",description:"Could not verify connection",variant:"destructive"})}finally{t.current&&u(!1)}},x=async()=>{C(!0),f(null);try{const P=await fetch("/api/auth/start",{method:"POST"}),b=await P.json();if(!P.ok||!b.ok)throw new Error(b.error||"Failed to start authentication");if(!t.current)return;const O={authUrl:b.authUrl,authToken:b.authToken,expiresAt:b.expiresAt};f(O);try{await fetch("/api/auth/open-browser",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({authUrl:b.authUrl})}),e({title:"Browser Opened",description:"Complete the sign-in in your browser"})}catch{e({title:"Browser Error",description:"Copy the URL below and paste in your browser"})}R(!0)}catch(P){console.error("Auth start failed:",P),e({title:"Error",description:P instanceof Error?P.message:"Failed to start authentication",variant:"destructive"}),C(!1)}};d.useEffect(()=>{if(!g||!m)return;let P=0;const b=150,O=setInterval(async()=>{if(P++,P>b){R(!1),f(null),C(!1),e({title:"Authentication Timeout",description:"Please try again",variant:"destructive"});return}try{const v=await(await fetch(`/api/auth/status?token=${encodeURIComponent(m.authToken)}`)).json();if(!t.current)return;v.status==="completed"?(clearInterval(O),R(!1),f(null),C(!1),await j(!1),e({title:"Connected!",description:`Successfully linked to ${v.projectName||"project"}`,variant:"success"})):(v.status==="expired"||v.status==="invalid")&&(clearInterval(O),R(!1),f(null),C(!1),e({title:"Authentication Failed",description:v.error||"Session expired. Please try again.",variant:"destructive"}))}catch(D){console.error("Polling error:",D)}},2e3);return()=>{clearInterval(O)}},[g,m,j,e]);const w=()=>{R(!1),f(null),C(!1)},N=async()=>{if(m!=null&&m.authUrl)try{await navigator.clipboard.writeText(m.authUrl),e({title:"Copied",description:"Auth URL copied to clipboard"})}catch{e({title:"Error",description:"Failed to copy",variant:"destructive"})}},S=P=>{if(!P)return"Never";try{return new Date(P).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return"Invalid date"}};return i?n.jsx("div",{className:"flex items-center justify-center h-full",children:n.jsxs("div",{className:"text-center",children:[n.jsx(_e,{className:"h-8 w-8 animate-spin text-muted-foreground mx-auto mb-3"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading connection status..."})]})}):n.jsxs("div",{"data-testid":"studio-connection","data-loaded":"true",className:"p-6 max-w-3xl mx-auto space-y-6",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Platform Connection"}),n.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Manage your connection to the Reshot platform"})]}),n.jsx(T,{variant:"outline",size:"icon",onClick:()=>j(!1),disabled:i,title:"Refresh",children:n.jsx(_t,{className:Y("h-4 w-4",i&&"animate-spin")})})]}),n.jsxs(he,{children:[n.jsx(ke,{className:"pb-3",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(be,{className:"text-base font-medium",children:"Connection Status"}),n.jsx(ue,{variant:s!=null&&s.isAuthenticated?"default":"secondary",className:Y((s==null?void 0:s.isAuthenticated)&&(s==null?void 0:s.apiKeyValid)===!0&&"bg-green-600",(s==null?void 0:s.isAuthenticated)&&(s==null?void 0:s.apiKeyValid)===!1&&"bg-red-600",(s==null?void 0:s.isAuthenticated)&&(s==null?void 0:s.apiKeyValid)==="unknown"&&"bg-yellow-600"),children:s!=null&&s.isAuthenticated?(s==null?void 0:s.apiKeyValid)===!0?n.jsxs(n.Fragment,{children:[n.jsx(vt,{className:"h-3 w-3 mr-1"}),"Connected"]}):(s==null?void 0:s.apiKeyValid)===!1?n.jsxs(n.Fragment,{children:[n.jsx(Jt,{className:"h-3 w-3 mr-1"}),"Invalid"]}):n.jsxs(n.Fragment,{children:[n.jsx(Jt,{className:"h-3 w-3 mr-1"}),"Unverified"]}):n.jsxs(n.Fragment,{children:[n.jsx(s0,{className:"h-3 w-3 mr-1"}),"Not Connected"]})})]})}),n.jsx(me,{className:"space-y-4",children:s!=null&&s.isAuthenticated?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[n.jsxs("div",{className:"space-y-1",children:[n.jsxs(q,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n.jsx(Cy,{className:"h-3 w-3"}),"Project"]}),n.jsx("p",{className:"text-sm font-medium",children:s.projectName||"Unknown Project"}),s.projectId&&n.jsx("p",{className:"text-xs text-muted-foreground font-mono truncate",children:s.projectId})]}),s.workspaceName&&n.jsxs("div",{className:"space-y-1",children:[n.jsxs(q,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n.jsx(ur,{className:"h-3 w-3"}),"Workspace"]}),n.jsx("p",{className:"text-sm font-medium",children:s.workspaceName})]}),s.user&&n.jsxs("div",{className:"space-y-1",children:[n.jsxs(q,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n.jsx(n0,{className:"h-3 w-3"}),"Linked User"]}),n.jsx("p",{className:"text-sm font-medium",children:s.user.fullName||s.user.email||"Unknown"}),s.user.fullName&&s.user.email&&n.jsx("p",{className:"text-xs text-muted-foreground",children:s.user.email})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs(q,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n.jsx(Ey,{className:"h-3 w-3"}),"Linked On"]}),n.jsx("p",{className:"text-sm",children:S(s.linkedAt)})]})]}),s.apiKeyWarning&&n.jsx("div",{className:"p-3 rounded-md bg-yellow-500/10 border border-yellow-500/30",children:n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(Jt,{className:"h-4 w-4 text-yellow-500 mt-0.5 shrink-0"}),n.jsxs("div",{children:[n.jsx("p",{className:"text-sm font-medium text-yellow-600",children:"Connection Issue"}),n.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:s.apiKeyWarning})]})]})}),n.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-2",children:[n.jsxs(T,{variant:"outline",size:"sm",onClick:h,disabled:c,children:[c?n.jsx(_e,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):n.jsx(xr,{className:"h-3.5 w-3.5 mr-1.5"}),"Verify"]}),n.jsxs(T,{variant:"outline",size:"sm",onClick:p,disabled:o,children:[o?n.jsx(_e,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):n.jsx(_t,{className:"h-3.5 w-3.5 mr-1.5"}),"Sync Info"]}),n.jsxs(T,{variant:"outline",size:"sm",onClick:x,disabled:k,children:[n.jsx(Ma,{className:"h-3.5 w-3.5 mr-1.5"}),"Re-link"]}),s.platformUrl&&n.jsxs(T,{variant:"ghost",size:"sm",onClick:()=>window.open(s.platformUrl,"_blank"),children:[n.jsx(an,{className:"h-3.5 w-3.5 mr-1.5"}),"Platform"]})]})]}):n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-sm text-muted-foreground",children:"Connect to the Reshot platform to publish your captured visuals and sync with your team."}),n.jsxs(T,{onClick:x,disabled:k,children:[k?n.jsx(_e,{className:"h-4 w-4 mr-2 animate-spin"}):n.jsx(Ma,{className:"h-4 w-4 mr-2"}),"Connect to Platform"]})]})})]}),m&&n.jsxs(he,{className:"border-primary/50 bg-primary/5",children:[n.jsxs(ke,{className:"pb-3",children:[n.jsxs(be,{className:"text-base font-medium flex items-center gap-2",children:[n.jsx(_e,{className:"h-4 w-4 animate-spin text-primary"}),"Waiting for Authentication"]}),n.jsx(at,{children:"Complete the sign-in process in your browser window"})]}),n.jsxs(me,{className:"space-y-4",children:[n.jsxs("div",{className:"p-3 rounded-md bg-background border",children:[n.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"If the browser didn't open, copy this URL and paste it in your browser:"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(ve,{value:m.authUrl,readOnly:!0,className:"text-xs font-mono bg-muted"}),n.jsx(T,{variant:"outline",size:"icon",onClick:N,children:n.jsx(rn,{className:"h-4 w-4"})})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(T,{variant:"outline",size:"sm",onClick:w,children:"Cancel"}),n.jsxs(T,{variant:"outline",size:"sm",onClick:()=>window.open(m.authUrl,"_blank"),children:[n.jsx(an,{className:"h-3.5 w-3.5 mr-1.5"}),"Open Browser"]})]})]})]}),n.jsxs(he,{className:"bg-muted/30",children:[n.jsx(ke,{className:"pb-2",children:n.jsx(be,{className:"text-sm font-medium",children:"How It Works"})}),n.jsxs(me,{className:"text-sm text-muted-foreground space-y-2",children:[n.jsxs("p",{children:[n.jsx("strong",{children:"1. Connect:"})," Link this CLI to your Reshot platform project"]}),n.jsxs("p",{children:[n.jsx("strong",{children:"2. Capture:"})," Record and capture visuals locally in your workspace"]}),n.jsxs("p",{children:[n.jsx("strong",{children:"3. Commit:"})," Bundle scenarios and publish to the platform"]}),n.jsx("p",{className:"pt-2 text-xs",children:"Your captured assets remain local until you publish them. Re-link anytime to switch projects."})]})]})]})}function L1(){const{toast:e}=Pt(),[t,s]=d.useState([]),[r,i]=d.useState(!0),[a,o]=d.useState(null),[l,c]=d.useState("all"),u=d.useRef(null),[m,f]=d.useState(!0),g=d.useRef(0),[R,k]=d.useState(!1),[,C]=d.useState(null);d.useEffect(()=>{fetch("/api/settings").then(v=>v.json()).then(v=>{var L;C(((L=v.settings)==null?void 0:L.isAuthenticated)||!1)}).catch(()=>C(!1))},[]),d.useEffect(()=>{if(a&&u.current&&m){const v=a.logs.length;v>g.current&&(u.current.scrollTop=u.current.scrollHeight),g.current=v}},[a==null?void 0:a.logs,m]);const j=d.useCallback(()=>{if(u.current){const{scrollTop:v,scrollHeight:L,clientHeight:V}=u.current,y=L-v-V<50;f(y)}},[]),p=d.useCallback(async()=>{i(!0);try{const L=await(await fetch("/api/jobs?limit=50")).json();if(s(L.jobs||[]),i(!1),a){const V=L.jobs.find(y=>y.id===a.id);V&&o(V)}}catch(v){console.error("Failed to load jobs:",v),i(!1)}},[a==null?void 0:a.id]);d.useEffect(()=>{if(p(),!t.some(V=>V.status==="running"||V.status==="pending"))return;const L=setInterval(p,2e3);return()=>clearInterval(L)},[p,t.some(v=>v.status==="running")]);const h=d.useCallback(v=>{o(v),g.current=0,f(!0),fetch(`/api/jobs/${v.id}`).then(L=>L.json()).then(L=>{L.job&&o(L.job)}).catch(()=>{})},[]),x=d.useCallback(()=>{C(!0),e({title:"Connected",description:"Successfully connected to Reshot platform. You can now publish.",variant:"success"})},[e]),w=async(v,L)=>{L&&L.stopPropagation();try{const V=await fetch(`/api/jobs/${v}/cancel`,{method:"POST",headers:{"Content-Type":"application/json"}}),y=await V.json();V.ok?(e({title:"Success",description:"Job cancelled",variant:"success"}),p()):e({title:"Error",description:y.error||"Failed to cancel job",variant:"destructive"})}catch{e({title:"Error",description:"Failed to cancel job",variant:"destructive"})}},N=async(v,L)=>{var V;L&&L.stopPropagation();try{const y=v.metadata||{};let _,F;switch(v.type){case"run":_="/api/jobs/run",F={scenarioKeys:y.scenarioKeys,variant:y.variant,format:y.format,diff:y.diff};break;case"publish":_="/api/jobs/publish",F={scenarioKeys:y.scenarioKeys,selectedGroups:y.selectedGroups,commitMessage:y.commitMessage};break;case"record":_="/api/jobs/record",F={...y};break;default:e({title:"Error",description:`Unknown job type: ${v.type}`,variant:"destructive"});return}const $=await fetch(_,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F)}),E=await $.json();if($.ok)if(e({title:"Retried",description:`New ${v.type} job created`,variant:"success"}),E.jobId||(V=E.job)!=null&&V.id){const A=E.jobId||E.job.id;await p(),s(z=>{const W=z.find(J=>J.id===A);return W&&o(W),z})}else await p();else e({title:"Error",description:E.error||"Failed to retry job",variant:"destructive"})}catch{e({title:"Error",description:"Failed to retry job",variant:"destructive"})}},S=v=>{switch(v){case"running":return n.jsx(_e,{className:"h-3 w-3 animate-spin"});case"success":return n.jsx(vt,{className:"h-3 w-3 text-green-500"});case"failed":return n.jsx(Da,{className:"h-3 w-3 text-destructive"});case"cancelled":return n.jsx(Vo,{className:"h-3 w-3 text-orange-500"});default:return n.jsx(hi,{className:"h-3 w-3 text-muted-foreground"})}},P=v=>{const L={pending:"secondary",running:"default",cancelled:"secondary",success:"default",failed:"destructive"};let V=v.status;if(v.status==="running"){const y=tr(v.logs);y&&(V=`${y.current}/${y.total}`)}return n.jsx(ue,{variant:L[v.status]||"secondary",className:"text-[10px] h-4 px-1.5",children:V})},b=v=>{switch(v){case"run":return n.jsx(Ts,{className:"h-3 w-3"});case"publish":return n.jsx(on,{className:"h-3 w-3"});case"record":return n.jsx(_n,{className:"h-3 w-3"});default:return null}},O=(v,L)=>{if(!L)return"Running...";const V=new Date(L).getTime()-new Date(v).getTime(),y=Math.floor(V/1e3);return y<60?`${y}s`:`${Math.floor(y/60)}m ${y%60}s`},D=l==="all"?t:t.filter(v=>v.type===l);return r&&t.length===0?n.jsx("div",{className:"p-8",children:n.jsx("div",{className:"text-muted-foreground",children:"Loading jobs..."})}):n.jsxs("div",{"data-testid":"studio-jobs","data-loaded":"true",className:"p-5 space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 pb-3",children:[n.jsxs("div",{children:[n.jsx("h1",{className:"text-xl font-bold tracking-tight",children:"Jobs"}),n.jsx("p",{className:"text-xs text-muted-foreground mt-1 font-normal",children:"Execution history and status"})]}),n.jsx(T,{variant:"outline",size:"icon",onClick:p,className:"shadow-sm",title:"Refresh",disabled:r,children:n.jsx(_t,{className:`h-4 w-4 ${r?"animate-spin":""}`})})]}),n.jsx("div",{className:"flex gap-2",children:["all","run","publish","record"].map(v=>n.jsx(T,{variant:l===v?"default":"outline",size:"sm",onClick:()=>c(v),children:v.charAt(0).toUpperCase()+v.slice(1)},v))}),n.jsxs("div",{className:"grid gap-3 lg:grid-cols-3",children:[n.jsx("div",{className:"lg:col-span-2 space-y-2",children:D.length===0?n.jsx(he,{className:"dagster-card",children:n.jsx(me,{className:"py-12 text-center",children:n.jsx("p",{className:"text-muted-foreground",children:"No jobs found"})})}):D.map(v=>n.jsxs(he,{className:Y("dagster-card cursor-pointer group transition-all",(a==null?void 0:a.id)===v.id&&"ring-2 ring-primary bg-primary/5"),onClick:()=>h(v),children:[n.jsx(ke,{className:"pb-2.5 px-4 pt-3",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.jsx("div",{className:Y("p-1.5 rounded-md",v.type==="run"&&"bg-blue-500/10",v.type==="publish"&&"bg-green-500/10",v.type==="record"&&"bg-purple-500/10"),children:b(v.type)}),n.jsxs("div",{children:[n.jsx(be,{className:"text-xs font-semibold",children:v.type.charAt(0).toUpperCase()+v.type.slice(1)}),v.scenarioKey&&n.jsx(at,{className:"text-[10px] font-mono mt-0.5 text-muted-foreground",children:v.scenarioKey})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[v.status==="running"&&n.jsxs(T,{variant:"ghost",size:"sm",className:"h-6 px-2 text-[10px] text-orange-500 hover:text-orange-600 hover:bg-orange-500/10",onClick:L=>w(v.id,L),children:[n.jsx(Vo,{className:"h-3 w-3 mr-1"}),"Cancel"]}),(v.status==="failed"||v.status==="cancelled")&&n.jsxs(T,{variant:"ghost",size:"sm",className:"h-6 px-2 text-[10px] text-blue-500 hover:text-blue-600 hover:bg-blue-500/10",onClick:L=>N(v,L),children:[n.jsx(Wl,{className:"h-3 w-3 mr-1"}),"Retry"]}),S(v.status),P(v)]})]})}),n.jsxs(me,{className:"px-4 pb-3",children:[n.jsxs("div",{className:"flex items-center justify-between text-[10px] text-muted-foreground",children:[n.jsx("span",{className:"font-mono",children:new Date(v.createdAt).toLocaleString()}),n.jsx("span",{className:"font-medium",children:O(v.createdAt,v.status==="running"?new Date().toISOString():v.updatedAt)})]}),(v.status==="running"||v.status==="pending")&&(()=>{const L=tr(v.logs);if(!L)return null;const V=Math.round(L.current/L.total*100);return n.jsxs("div",{className:"mt-2 space-y-1",children:[n.jsx(Fa,{value:V,className:"h-1.5"}),n.jsxs("div",{className:"flex items-center justify-between text-[10px] text-muted-foreground",children:[n.jsxs("span",{children:[L.current,"/",L.total," completed"]}),n.jsxs("span",{children:[V,"%"]})]})]})})()]})]},v.id))}),a&&n.jsxs("div",{className:"space-y-2",children:[n.jsxs(he,{className:"dagster-card",children:[n.jsxs(ke,{className:"px-4 py-3 border-b border-border/50 flex flex-row items-center justify-between",children:[n.jsx(be,{className:"text-xs font-semibold",children:"Job Details"}),n.jsxs("div",{className:"flex items-center gap-2",children:[a.status==="running"&&n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-[10px] text-orange-500 border-orange-500/30 hover:bg-orange-500/10",onClick:()=>w(a.id),children:[n.jsx(Vo,{className:"h-3 w-3 mr-1"}),"Cancel Job"]}),(a.status==="failed"||a.status==="cancelled")&&n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-[10px] text-blue-500 border-blue-500/30 hover:bg-blue-500/10",onClick:()=>N(a),children:[n.jsx(Wl,{className:"h-3 w-3 mr-1"}),"Retry Job"]})]})]}),n.jsxs(me,{className:"space-y-3 px-4 py-3",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-[10px] font-medium text-muted-foreground uppercase tracking-wide mb-1",children:"Type"}),n.jsx("div",{className:"text-xs font-semibold",children:a.type})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-[10px] font-medium text-muted-foreground uppercase tracking-wide mb-1",children:"Status"}),n.jsx("div",{className:"mt-1",children:P(a)})]}),(a.status==="running"||a.status==="pending")&&(()=>{const v=tr(a.logs);if(!v)return null;const L=Math.round(v.current/v.total*100);return n.jsxs("div",{children:[n.jsx("div",{className:"text-[10px] font-medium text-muted-foreground uppercase tracking-wide mb-1",children:"Progress"}),n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(Fa,{value:L,className:"h-2"}),n.jsxs("div",{className:"flex items-center justify-between text-xs",children:[n.jsxs("span",{className:"text-muted-foreground",children:[v.current,"/",v.total," completed"]}),n.jsxs("span",{className:"font-semibold",children:[L,"%"]})]})]})]})})(),a.scenarioKey&&n.jsxs("div",{children:[n.jsx("div",{className:"text-[10px] font-medium text-muted-foreground uppercase tracking-wide mb-1",children:"Scenario"}),n.jsx(Kt,{to:`/scenarios/${a.scenarioKey}`,className:"text-xs font-mono text-primary hover:underline font-medium",children:a.scenarioKey})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-[10px] font-medium text-muted-foreground uppercase tracking-wide mb-1",children:"Started"}),n.jsx("div",{className:"text-xs font-mono",children:new Date(a.createdAt).toLocaleString()})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-[10px] font-medium text-muted-foreground uppercase tracking-wide mb-1",children:"Duration"}),n.jsx("div",{className:"text-xs font-semibold",children:O(a.createdAt,a.status==="running"?new Date().toISOString():a.updatedAt)})]})]})]}),n.jsxs(he,{className:"dagster-card",children:[n.jsxs(ke,{className:"px-4 py-3 border-b border-border/50 flex flex-row items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(be,{className:"text-xs font-semibold",children:"Logs"}),a.status==="running"&&n.jsxs(ue,{variant:"outline",className:"text-[9px] h-4 animate-pulse",children:[n.jsx(_e,{className:"h-2 w-2 mr-1 animate-spin"}),"Live"]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[!m&&n.jsx(T,{variant:"ghost",size:"sm",className:"h-6 text-[10px]",onClick:()=>{f(!0),u.current&&(u.current.scrollTop=u.current.scrollHeight)},children:"Jump to bottom"}),n.jsx(T,{variant:"ghost",size:"sm",className:"h-6 px-2",onClick:()=>{fetch(`/api/jobs/${a.id}`).then(v=>v.json()).then(v=>{v.job&&o(v.job)})},children:n.jsx(_t,{className:"h-3 w-3"})})]})]}),n.jsx(me,{className:"px-4 py-3",children:n.jsx("div",{ref:u,onScroll:j,className:"bg-background/50 rounded-md p-3 font-mono text-[10px] max-h-80 overflow-y-auto border border-border/30",children:a.logs.length===0?n.jsx("div",{className:"text-muted-foreground text-center py-4",children:a.status==="running"?"Waiting for logs...":"No logs available"}):n.jsx("div",{className:"space-y-0.5",children:a.logs.map((v,L)=>{const V=Im(v.message),y=V.includes("⚠ Diff Detected")||V.includes("% changed"),_=V.includes("✔ No changes"),F=V.includes("Diff Summary:"),$=V.includes("📥 Fetching baselines")||V.includes("baseline"),E=V.includes("🔍 Computing visual diffs");let A="";return V.includes("[error]")?A="text-destructive":V.includes("[stderr]")?A="text-orange-500":y?A="text-amber-500 font-medium":_?A="text-green-500":F||E||$?A="text-cyan-500":V.includes("✔")&&(A="text-green-500"),n.jsxs("div",{className:"text-muted-foreground leading-relaxed",children:[n.jsx("span",{className:"text-muted-foreground/40 text-[9px]",children:new Date(v.timestamp).toLocaleTimeString()})," ",n.jsx("span",{className:A,children:V})]},L)})})})})]})]})]}),n.jsx(wi,{open:R,onOpenChange:k,onAuthenticated:x})]})}function M1(){var b,O,D;const{scenarioKey:e,variationSlug:t,captureKey:s}=Kp(),r=Os(),{toast:i}=Pt(),[a,o]=d.useState(null),[l,c]=d.useState(!0),[u,m]=d.useState(null),[f,g]=d.useState(!1),[R,k]=d.useState(""),[C,j]=d.useState({}),[p,h]=d.useState([]),[x,w]=d.useState(null);d.useEffect(()=>{if(!e||!t||!s){c(!1);return}fetch(`/api/output/${e}/${t}`).then(v=>v.json()).then(v=>{var V;const L=(V=v.assets)==null?void 0:V.find(y=>y.filename.replace(/\.[^/.]+$/,"")===s||y.captureKey===s);L&&(o(L),k(L.captureKey||s)),c(!1)}).catch(v=>{console.error("Failed to load asset:",v),c(!1)})},[e,t,s]),d.useEffect(()=>{!e||!s||fetch(`/api/config/scenarios/${e}`).then(v=>v.json()).then(v=>{const L=v.scenario;if(L!=null&&L.steps){const V=L.steps.findIndex(y=>{var _;return y.key===s||y.captureKey===s||((_=y.path)==null?void 0:_.replace(/\.[^/.]+$/,""))===s});V!==-1&&m({step:L.steps[V],index:V})}}).catch(v=>{console.error("Failed to load scenario:",v)})},[e,s]),d.useEffect(()=>{!e||!t||fetch(`/api/output/${e}/${t}/sentinels`).then(v=>v.json()).then(v=>{if(v.files&&v.files.length>0){const L=v.files.map((V,y)=>{var F,$;const _=($=(F=v.sentinelsManifest)==null?void 0:F.sentinels)==null?void 0:$.find(E=>E.filename===V);return{filename:V,label:(_==null?void 0:_.label)||`Step ${y}`,stepIndex:(_==null?void 0:_.stepIndex)??y,url:`${v.basePath}/${V}`,hasDiff:!1,diffPercent:void 0}});h(L)}}).catch(v=>{console.error("Failed to load sentinels:",v)})},[e,t]),d.useEffect(()=>{e&&fetch(`/api/output/${e}/versions`).then(v=>v.json()).then(v=>{const L=v.versions||[],V=L.find(y=>y.timestamp===t)||L[0];if(V){const y={};V.privacy&&(y.privacy=V.privacy),V.style&&(y.style=V.style),j(y)}}).catch(()=>{})},[e,t]),d.useEffect(()=>{!e||!t||p.length===0||fetch(`/api/output/${e}/versions`).then(v=>v.json()).then(v=>{const L=v.versions||[];if(L.length>0){const V=L[0].timestamp;return fetch(`/api/output/${e}/version/${V}/diff-manifest`)}return null}).then(v=>v==null?void 0:v.json()).then(v=>{var L;(L=v==null?void 0:v.manifest)!=null&&L.assets&&h(V=>V.map(y=>{const _=`${t}/sentinels/${y.filename.replace(".png","")}`,F=v.manifest.assets[_];return{...y,hasDiff:F&&!F.match,diffPercent:F==null?void 0:F.diffPercent}}))}).catch(v=>{console.error("Failed to load diff manifest:",v)})},[e,t,p.length]);const N=v=>v<1024?`${v} B`:v<1024*1024?`${(v/1024).toFixed(1)} KB`:`${(v/(1024*1024)).toFixed(1)} MB`,S=()=>{a!=null&&a.path&&(navigator.clipboard.writeText(a.path),i({title:"Copied",description:"File path copied to clipboard",variant:"success"}))},P=async()=>{i({title:"Info",description:"Capture key editing will be available in a future release",variant:"default"}),g(!1)};return l?n.jsx("div",{className:"p-8",children:n.jsx("div",{className:"text-muted-foreground",children:"Loading asset..."})}):a?n.jsxs("div",{"data-testid":"studio-asset-detail","data-loaded":"true",className:"p-5 space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 pb-3",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsxs(T,{variant:"ghost",size:"sm",onClick:()=>r("/assets"),className:"shadow-sm",children:[n.jsx(Bl,{className:"h-3.5 w-3.5 mr-1.5"}),"Back"]}),n.jsxs("div",{children:[n.jsx("h1",{className:"text-xl font-bold tracking-tight",children:a.filename}),n.jsxs("p",{className:"text-xs text-muted-foreground mt-1 font-mono",children:[e," / ",t]})]})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsxs(T,{variant:"outline",size:"sm",onClick:S,className:"shadow-sm",children:[n.jsx(rn,{className:"h-3.5 w-3.5 mr-1.5"}),"Copy Path"]}),n.jsxs("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground shadow-sm",children:[n.jsx(an,{className:"h-3.5 w-3.5"}),"Open"]})]})]}),n.jsxs("div",{className:"grid gap-4 lg:grid-cols-3",children:[n.jsxs("div",{className:"lg:col-span-2 space-y-4",children:[n.jsxs(he,{children:[n.jsx(ke,{children:n.jsx(be,{children:"Preview"})}),n.jsx(me,{children:n.jsx("div",{className:"flex items-center justify-center min-h-[400px] bg-muted rounded-md",children:n.jsx(fo,{url:a.url,filename:a.filename,size:"lg"})})})]}),p.length>0&&n.jsxs(he,{children:[n.jsxs(ke,{children:[n.jsxs(be,{className:"text-sm flex items-center gap-2",children:["Sentinel Frames",p.some(v=>v.hasDiff)&&n.jsxs(ue,{variant:"destructive",className:"text-xs",children:[n.jsx(Qp,{className:"h-3 w-3 mr-1"}),"Changes Detected"]})]}),n.jsx(at,{children:"Captured at each step during recording for visual comparison"})]}),n.jsxs(me,{children:[n.jsx("div",{className:"flex gap-2 overflow-x-auto pb-2",children:p.map(v=>{var L;return n.jsxs("button",{onClick:()=>w((x==null?void 0:x.filename)===v.filename?null:v),className:Y("flex-shrink-0 w-24 h-16 rounded border-2 overflow-hidden relative group",v.hasDiff?"border-red-500":"border-transparent",(x==null?void 0:x.filename)===v.filename&&"ring-2 ring-primary"),title:v.label,children:[n.jsx("img",{src:v.url,alt:v.label,className:"w-full h-full object-cover"}),v.hasDiff&&n.jsxs("div",{className:"absolute top-0 right-0 bg-red-500 text-white text-[10px] px-1 rounded-bl",children:[(L=v.diffPercent)==null?void 0:L.toFixed(1),"%"]}),n.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/60 text-white text-[10px] px-1 py-0.5 opacity-0 group-hover:opacity-100 transition-opacity truncate",children:v.label})]},v.filename)})}),x&&n.jsxs("div",{className:"mt-4 border rounded-lg p-4 bg-muted/50",children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("div",{className:"text-sm font-medium",children:x.label}),x.hasDiff&&n.jsxs(ue,{variant:"destructive",children:[(b=x.diffPercent)==null?void 0:b.toFixed(2),"% different"]})]}),n.jsx("img",{src:x.url,alt:x.label,className:"w-full rounded border"})]})]})]})]}),n.jsxs("div",{className:"space-y-4",children:[n.jsxs(he,{children:[n.jsx(ke,{children:n.jsx(be,{children:"Metadata"})}),n.jsxs(me,{className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Capture Key"}),f?n.jsxs("div",{className:"flex gap-2 mt-1",children:[n.jsx(ve,{value:R,onChange:v=>k(v.target.value),className:"font-mono text-sm"}),n.jsx(T,{size:"sm",onClick:P,children:"Save"}),n.jsx(T,{size:"sm",variant:"outline",onClick:()=>{g(!1),k(a.captureKey||s||"")},children:"Cancel"})]}):n.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[n.jsx("code",{className:"text-sm font-mono bg-muted px-2 py-1 rounded flex-1",children:a.captureKey||s}),n.jsx(T,{variant:"ghost",size:"sm",onClick:()=>g(!0),children:"Edit"})]})]}),n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"File Size"}),n.jsx("div",{className:"text-sm font-medium mt-1",children:N(a.size)})]}),n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Modified"}),n.jsx("div",{className:"text-sm font-medium mt-1",children:new Date(a.mtime).toLocaleString()})]}),n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"File Path"}),n.jsx("div",{className:"text-xs font-mono bg-muted px-2 py-1 rounded mt-1 break-all",children:a.relativePath})]}),u&&n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Linked Step"}),n.jsx("div",{className:"mt-1",children:n.jsxs(Kt,{to:`/scenarios/${e}?step=${u.index}`,className:"inline-flex items-center gap-1.5 text-sm text-primary hover:underline",children:[n.jsx(Rn,{className:"h-3.5 w-3.5"}),"Step #",u.index+1,": ",u.step.action]})}),u.step.selector&&n.jsx("div",{className:"text-xs font-mono bg-muted px-2 py-1 rounded mt-1",children:u.step.selector}),u.step.clip&&n.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Clip: ",JSON.stringify(u.step.clip)]})]}),n.jsxs("div",{children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Variation Context"}),n.jsx("div",{className:"mt-1",children:n.jsx(ue,{variant:"secondary",children:t})})]}),((O=C.privacy)==null?void 0:O.enabled)&&n.jsxs("div",{children:[n.jsxs(q,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n.jsx(xr,{className:"h-3 w-3"}),"Privacy Masking"]}),n.jsxs("div",{className:"text-sm font-medium mt-1 capitalize",children:[C.privacy.method||"redact",C.privacy.selectorCount!=null&&n.jsxs("span",{className:"text-muted-foreground font-normal",children:[" ","(",C.privacy.selectorCount," selector",C.privacy.selectorCount!==1?"s":"",")"]})]})]}),((D=C.style)==null?void 0:D.enabled)&&n.jsxs("div",{children:[n.jsxs(q,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n.jsx(ao,{className:"h-3 w-3"}),"Style Processing"]}),n.jsxs("div",{className:"text-sm font-medium mt-1",children:[C.style.frame!=="none"&&n.jsxs("span",{className:"capitalize",children:[C.style.frame," frame"]}),C.style.shadow!=="none"&&n.jsxs("span",{children:[C.style.frame!=="none"?", ":"",C.style.shadow," shadow"]}),(!C.style.frame||C.style.frame==="none")&&(!C.style.shadow||C.style.shadow==="none")&&n.jsx("span",{children:"Custom style applied"})]})]})]})]}),u&&n.jsxs(he,{children:[n.jsx(ke,{children:n.jsx(be,{children:"Step Details"})}),n.jsxs(me,{className:"space-y-2 text-sm",children:[n.jsxs("div",{children:[n.jsx("span",{className:"text-muted-foreground",children:"Action:"})," ",n.jsx(ue,{variant:"outline",children:u.step.action})]}),u.step.selectorPadding!==void 0&&n.jsxs("div",{children:[n.jsx("span",{className:"text-muted-foreground",children:"Selector Padding:"})," ",u.step.selectorPadding,"px"]}),u.step.deviceScaleFactor!==void 0&&n.jsxs("div",{children:[n.jsx("span",{className:"text-muted-foreground",children:"Device Scale Factor:"})," ",u.step.deviceScaleFactor]})]})]})]})]})]}):n.jsx("div",{className:"p-8",children:n.jsxs(he,{children:[n.jsxs(ke,{children:[n.jsx(be,{children:"Asset Not Found"}),n.jsx(at,{children:"The requested asset could not be found."})]}),n.jsx(me,{children:n.jsxs(T,{onClick:()=>r("/assets"),variant:"outline",children:[n.jsx(Bl,{className:"h-4 w-4 mr-2"}),"Back to Assets"]})})]})})}function I1({visualKey:e,visualTitle:t,targetUrl:s,targetId:r,scenarioUrl:i,onRecordingComplete:a}){const{status:o,steps:l,isConnected:c,start:u,stop:m,capture:f,removeStep:g}=bm(),{toast:R}=Pt(),[k,C]=d.useState(!1),[j,p]=d.useState(!1),[h,x]=d.useState(!1),[w,N]=d.useState(null),S=d.useRef(null);d.useEffect(()=>{S.current&&(S.current.scrollTop=S.current.scrollHeight)},[l]);const P=async()=>{C(!0);try{await u({visualKey:e,title:t||"Untitled Visual",targetUrl:s,targetId:r,scenarioUrl:i})}catch(v){R({title:"Error",description:v.message,variant:"destructive"})}finally{C(!1)}},b=async v=>{v?p(!0):x(!0);try{await m(v),R({title:v?"Recording Saved":"Recording Cancelled",description:v?"Your scenario has been saved.":"Recording was discarded.",variant:v?"success":"default"}),v&&a?a(o.visualKey):a&&a()}catch(L){R({title:"Error",description:L.message,variant:"destructive"})}finally{p(!1),x(!1)}},O=async()=>{try{await f({outputFilename:`${o.visualKey}-${Date.now()}.png`}),R({title:"Screenshot Captured",variant:"success"})}catch(v){R({title:"Error",description:v.message,variant:"destructive"})}},D=async v=>{N(v);try{await g(v),R({title:"Step Removed",variant:"success"})}catch(L){R({title:"Error",description:L.message,variant:"destructive"})}finally{N(null)}};return n.jsxs("div",{className:"space-y-4",children:[n.jsxs(he,{className:o.active?"border-green-500/50":"",children:[n.jsx(ke,{className:"pb-3",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(be,{className:"text-sm font-medium",children:o.active?"Recording Active":"Ready to Record"}),o.active&&n.jsx(ue,{variant:"default",className:"animate-pulse bg-red-500",children:"LIVE"})]}),c?n.jsx(ue,{variant:"outline",className:"text-green-500 border-green-500/30",children:"System Connected"}):n.jsx(ue,{variant:"destructive",children:"System Disconnected"})]})}),n.jsx(me,{children:o.active?n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"flex gap-2",children:n.jsxs(T,{onClick:O,variant:"secondary",className:"flex-1",children:[n.jsx(na,{className:"mr-2 h-4 w-4 fill-current"}),"Capture Screen"]})}),n.jsxs("div",{className:"flex gap-2",children:[n.jsxs(T,{onClick:()=>b(!1),variant:"outline",disabled:h||j,className:"flex-1",children:[h?n.jsx(_e,{className:"mr-2 h-4 w-4 animate-spin"}):n.jsx(ln,{className:"mr-2 h-4 w-4"}),"Cancel"]}),n.jsxs(T,{onClick:()=>b(!0),variant:"default",disabled:j||h,className:"flex-1 bg-green-600 hover:bg-green-700",children:[j?n.jsx(_e,{className:"mr-2 h-4 w-4 animate-spin"}):n.jsx(Hr,{className:"mr-2 h-4 w-4"}),"Stop & Save"]})]}),n.jsxs("p",{className:"text-xs text-muted-foreground text-center",children:[l.length," step",l.length!==1?"s":""," recorded"]})]}):n.jsxs(T,{onClick:P,disabled:k||!c,className:"w-full",children:[k?n.jsx(_e,{className:"mr-2 h-4 w-4 animate-spin"}):n.jsx(_n,{className:"mr-2 h-4 w-4"}),"Start Recording"]})})]}),o.active&&n.jsxs(he,{className:"h-64 flex flex-col",children:[n.jsx(ke,{className:"py-3 border-b bg-muted/30",children:n.jsx(be,{className:"text-xs font-mono uppercase text-muted-foreground",children:"Live Action Log"})}),n.jsxs("div",{ref:S,className:"flex-1 overflow-y-auto p-4 space-y-2 font-mono text-xs",children:[l.length===0&&n.jsx("div",{className:"text-center text-muted-foreground py-8",children:"Interact with the browser window to see actions here..."}),l.map((v,L)=>n.jsxs("div",{className:"group flex items-start gap-2 p-2 rounded bg-muted/50 border border-transparent hover:border-border transition-colors",children:[n.jsxs("div",{className:"mt-0.5 text-muted-foreground",children:[v.action==="click"&&n.jsx(Jy,{className:"h-3 w-3"}),v.action==="type"&&n.jsx(t0,{className:"h-3 w-3"}),v.action==="screenshot"&&n.jsx(Oy,{className:"h-3 w-3"})]}),n.jsxs("div",{className:"flex-1 break-all",children:[n.jsx("span",{className:"font-bold text-primary",children:v.action.toUpperCase()}),n.jsx("span",{className:"mx-2 text-muted-foreground",children:"→"}),n.jsx("span",{className:"bg-background px-1 rounded border",children:v.selector||"page"}),v.text&&n.jsxs("div",{className:"mt-1 text-muted-foreground",children:['Value: "',v.text,'"']})]}),n.jsx("button",{onClick:()=>D(L),disabled:w!==null,className:"opacity-0 group-hover:opacity-100 transition-opacity p-1 hover:bg-red-100 hover:text-red-600 rounded",title:"Remove this step",children:w===L?n.jsx(_e,{className:"h-3 w-3 animate-spin"}):n.jsx(ps,{className:"h-3 w-3"})})]},L))]})]})]})}function D1(){const e=Os(),{status:t,isConnected:s,error:r,diagnostics:i}=bm(),{toast:a}=Pt(),[o,l]=d.useState([]),[c,u]=d.useState(""),[m,f]=d.useState(""),[g,R]=d.useState(""),[k,C]=d.useState("new"),[j,p]=d.useState(null),[h,x]=d.useState(!1),[w,N]=d.useState([]),[S,P]=d.useState(""),[b,O]=d.useState(!1),[D,v]=d.useState(null),[L,V]=d.useState(!1),y=d.useCallback(async()=>{x(!0);try{const fe=await(await fetch("/api/recorder/check-chrome")).json();p(fe)}catch{p({ok:!1,chromeAvailable:!1,error:"Failed to check Chrome status"})}finally{x(!1)}},[]),_=d.useCallback(async()=>{O(!0);try{const fe=await(await fetch("/api/recorder/tabs")).json();if(fe.ok&&fe.tabs){const ye=fe.tabs.filter(ge=>!ge.isOurUI&&!ge.isChrome);N(ye),P(ge=>!ge&&ye.length>0?ye[0].id:ge&&ye.some(Re=>Re.id===ge)?ge:ye.length>0?ye[0].id:"")}}catch(G){console.error("Failed to load tabs:",G)}finally{O(!1)}},[]),F=d.useCallback(async()=>{try{const fe=await(await fetch("/api/recorder/session-status")).json();fe.ok&&v(fe)}catch(G){console.error("Failed to check session status:",G)}},[]),$=d.useCallback(async()=>{V(!0);try{const fe=await(await fetch("/api/recorder/save-session",{method:"POST"})).json();fe.ok?(a({title:"Session Saved",description:"Your authenticated session has been saved. Future captures will use your login state."}),F()):a({title:"Save Failed",description:fe.error||"Could not save session. Make sure Chrome is running with your app logged in.",variant:"destructive"})}catch{a({title:"Error",description:"Failed to connect to server",variant:"destructive"})}finally{V(!1)}},[a,F]),E=d.useCallback(async()=>{var G;try{const ye=await(await fetch("/api/config")).json();(G=ye.config)!=null&&G.scenarios&&l(ye.config.scenarios)}catch(fe){console.error("Failed to load scenarios:",fe)}},[]);d.useEffect(()=>{E(),y(),F()},[y,F]),d.useEffect(()=>{j!=null&&j.chromeAvailable&&_()},[j==null?void 0:j.chromeAvailable,_]);const A=()=>{if(k==="existing"&&c){const G=o.find(fe=>fe.key===c);return{visualKey:c,title:(G==null?void 0:G.name)||c}}return k==="new"&&m.trim()?{visualKey:m.toLowerCase().replace(/[^a-z0-9\s-]/g,"").trim().replace(/\s+/g,"-").replace(/-+/g,"-"),title:m.trim()}:{visualKey:void 0,title:void 0}},{visualKey:z,title:W}=A(),J=w.find(G=>G.id===S);return n.jsxs("div",{"data-testid":"studio-recorder","data-loaded":"true",className:"p-8 space-y-6 max-w-4xl mx-auto",children:[n.jsxs("div",{children:[n.jsx("h1",{className:"text-3xl font-bold",children:"Recording Studio"}),n.jsx("p",{className:"text-muted-foreground mt-2",children:"Capture screenshots and user interactions from your application"})]}),n.jsxs(he,{className:j!=null&&j.hasValidTab?"border-green-500/50 bg-green-500/5":j!=null&&j.chromeAvailable?"border-yellow-500/50 bg-yellow-500/5":"border-red-500/50 bg-red-500/5",children:[n.jsx(ke,{className:"pb-3",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs(be,{className:"text-sm font-medium flex items-center gap-2",children:[n.jsx(Yp,{className:"h-4 w-4"}),"Chrome Browser Status"]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(T,{variant:"ghost",size:"icon",onClick:y,disabled:h,title:"Refresh",children:n.jsx(_t,{className:`h-4 w-4 ${h?"animate-spin":""}`})}),j&&n.jsx(ue,{variant:j.hasValidTab?"default":j.chromeAvailable?"secondary":"destructive",children:j.hasValidTab?n.jsxs(n.Fragment,{children:[n.jsx(vt,{className:"h-3 w-3 mr-1"}),"Ready"]}):j.chromeAvailable?n.jsxs(n.Fragment,{children:[n.jsx(Jt,{className:"h-3 w-3 mr-1"}),"Needs Tab"]}):n.jsxs(n.Fragment,{children:[n.jsx(Jt,{className:"h-3 w-3 mr-1"}),"Not Running"]})})]})]})}),n.jsxs(me,{className:"space-y-3",children:[!(j!=null&&j.chromeAvailable)&&n.jsxs("div",{className:"space-y-3",children:[n.jsx("div",{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground",children:n.jsx(ue,{variant:"secondary",children:"Not Connected"})}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"To enable recording, launch a dedicated Chrome instance:"}),n.jsxs("div",{className:"bg-background rounded-md p-3 border space-y-2",children:[n.jsx("p",{className:"text-xs font-medium text-foreground",children:"Run this command in your Terminal:"}),n.jsxs("div",{className:"relative",children:[n.jsx("code",{className:"block bg-muted px-3 py-2 pr-10 rounded text-xs font-mono break-all select-all",children:'/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --remote-debugging-port=9222 --user-data-dir="$HOME/.reshot/chrome-debug"'}),n.jsx(T,{variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 -translate-y-1/2 h-7 w-7",onClick:()=>{navigator.clipboard.writeText('/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --remote-debugging-port=9222 --user-data-dir="$HOME/.reshot/chrome-debug"'),a({title:"Copied",description:"Command copied to clipboard"})},title:"Copy command",children:n.jsx(rn,{className:"h-3.5 w-3.5"})})]}),n.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Note: This launches a separate Chrome profile. You do not need to close your main browser."})]})]}),(j==null?void 0:j.chromeAvailable)&&!j.hasValidTab&&n.jsxs("div",{className:"space-y-2",children:[n.jsx("p",{className:"text-sm text-yellow-600 font-medium",children:"Chrome is running, but no valid tabs found."}),n.jsx("p",{className:"text-xs text-muted-foreground",children:'Please open a tab and navigate to your application, then click "Refresh" above.'})]}),(j==null?void 0:j.hasValidTab)&&n.jsxs("div",{className:"space-y-3",children:[n.jsx("p",{className:"text-sm text-green-600 font-medium",children:"✓ Chrome is ready for recording!"}),w.length>0&&n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs font-medium",children:"Select Tab to Record:"}),n.jsx("div",{className:"space-y-1.5",children:w.map(G=>n.jsxs("div",{onClick:()=>P(G.id),className:`flex items-center gap-2 text-xs px-3 py-2 rounded cursor-pointer transition-colors ${S===G.id?"bg-primary text-primary-foreground":"bg-muted/50 hover:bg-muted"}`,children:[n.jsx(ur,{className:"h-3 w-3 flex-shrink-0"}),n.jsxs("div",{className:"truncate flex-1",children:[n.jsx("div",{className:"font-medium truncate",children:G.title||"Untitled"}),n.jsx("div",{className:`text-[10px] truncate ${S===G.id?"text-primary-foreground/70":"text-muted-foreground"}`,children:G.url})]}),S===G.id&&n.jsx(vt,{className:"h-3 w-3 flex-shrink-0"})]},G.id))}),n.jsxs(T,{variant:"ghost",size:"sm",onClick:_,disabled:b,className:"text-xs",children:[n.jsx(_t,{className:`h-3 w-3 mr-1 ${b?"animate-spin":""}`}),"Refresh Tabs"]})]}),w.length===0&&n.jsx("p",{className:"text-xs text-muted-foreground",children:"No recordable tabs found. Open your application in Chrome."})]})]})]}),(j==null?void 0:j.chromeAvailable)&&n.jsxs(he,{className:D!=null&&D.hasSession?"border-blue-500/30":"border-muted",children:[n.jsxs(ke,{className:"pb-3",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs(be,{className:"text-sm font-medium flex items-center gap-2",children:[n.jsx(La,{className:"h-4 w-4"}),"Authentication Session"]}),(D==null?void 0:D.hasSession)&&n.jsx(ue,{variant:D.isStale?"secondary":"default",children:D.isStale?"Stale":"Active"})]}),n.jsx(at,{className:"text-xs",children:"Save your logged-in session so captures can access authenticated pages"})]}),n.jsxs(me,{className:"space-y-3",children:[D!=null&&D.hasSession?n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center gap-2 text-sm text-green-600",children:[n.jsx(vt,{className:"h-4 w-4"}),n.jsx("span",{children:"Session saved"})]}),n.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[n.jsxs("p",{children:[D.cookieCount," cookies stored"]}),n.jsxs("p",{children:["Saved"," ",D.ageHours?`${D.ageHours}h ago`:"recently"]}),D.isStale&&n.jsx("p",{className:"text-yellow-600",children:"Session may be expired - consider saving a fresh one"})]})]}):n.jsx("div",{className:"text-xs text-muted-foreground",children:n.jsx("p",{children:"No saved session. Log into your app in Chrome, then save your session."})}),n.jsx(T,{variant:D!=null&&D.hasSession?"outline":"default",size:"sm",onClick:$,disabled:L||!(j!=null&&j.chromeAvailable),className:"w-full",children:L?n.jsxs(n.Fragment,{children:[n.jsx(_t,{className:"h-3 w-3 mr-2 animate-spin"}),"Saving..."]}):n.jsxs(n.Fragment,{children:[n.jsx(La,{className:"h-3 w-3 mr-2"}),D!=null&&D.hasSession?"Update Session":"Save Session"]})})]})]}),n.jsxs(he,{className:s?"border-green-500/30":"border-red-500/30",children:[n.jsx(ke,{className:"pb-3",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs(be,{className:"text-sm font-medium flex items-center gap-2",children:[n.jsx(Ia,{className:"h-4 w-4"}),"Server Connection"]}),n.jsx(ue,{variant:s?"default":"destructive",children:s?n.jsxs(n.Fragment,{children:[n.jsx(vt,{className:"h-3 w-3 mr-1"}),"Connected"]}):n.jsxs(n.Fragment,{children:[n.jsx(Jt,{className:"h-3 w-3 mr-1"}),"Disconnected"]})})]})}),n.jsx(me,{children:n.jsx("p",{className:"text-xs text-muted-foreground",children:s?"Real-time events will be captured and displayed.":"Connection lost. Please refresh the page."})})]}),r&&n.jsx(he,{className:"border-red-500/50 bg-red-50/10",children:n.jsx(me,{className:"pt-4",children:n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(Jt,{className:"h-5 w-5 text-red-500 mt-0.5"}),n.jsxs("div",{children:[n.jsx("p",{className:"font-medium text-red-600",children:"Recording Error"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:r})]})]})})}),!t.active&&n.jsxs(he,{children:[n.jsxs(ke,{children:[n.jsxs(be,{className:"text-sm font-medium flex items-center gap-2",children:[n.jsx(_n,{className:"h-4 w-4"}),"Configure Recording Session"]}),n.jsx(at,{children:"Choose to record a new visual or edit an existing scenario"})]}),n.jsxs(me,{className:"space-y-4",children:[n.jsxs("div",{className:"flex gap-2",children:[n.jsx(T,{variant:k==="new"?"default":"outline",size:"sm",onClick:()=>C("new"),children:"New Visual"}),n.jsxs(T,{variant:k==="existing"?"default":"outline",size:"sm",onClick:()=>C("existing"),disabled:o.length===0,children:["Edit Existing (",o.length,")"]})]}),k==="new"&&n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{htmlFor:"visual-title",children:"Visual Title"}),n.jsx(ve,{id:"visual-title",placeholder:"e.g., Admin Dashboard View",value:m,onChange:G=>f(G.target.value)}),m&&n.jsxs("p",{className:"text-xs text-muted-foreground",children:["Key:"," ",n.jsx("code",{className:"bg-muted px-1 rounded",children:z})]})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsxs(q,{htmlFor:"visual-url",children:["Scenario URL"," ",n.jsx("span",{className:"text-muted-foreground text-xs",children:"(optional)"})]}),n.jsx(ve,{id:"visual-url",placeholder:"https://your-app.com/page (uses tab URL if blank)",value:g,onChange:G=>R(G.target.value)}),n.jsx("p",{className:"text-xs text-muted-foreground",children:g?"This URL will be saved with the scenario.":"Leave blank to use the URL from the selected Chrome tab."})]})]}),k==="existing"&&o.length>0&&n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{children:"Select Scenario"}),n.jsx("div",{className:"grid gap-2",children:o.map(G=>{var fe;return n.jsxs("div",{onClick:()=>u(G.key),className:`p-3 rounded-md border cursor-pointer transition-colors ${c===G.key?"border-primary bg-primary/5":"border-border hover:border-primary/50"}`,children:[n.jsx("p",{className:"font-medium text-sm",children:G.name}),n.jsxs("p",{className:"text-xs text-muted-foreground",children:[G.key," • ",((fe=G.steps)==null?void 0:fe.length)||0," steps"]})]},G.key)})})]})]})]}),n.jsx(I1,{visualKey:z,visualTitle:W,targetUrl:J==null?void 0:J.url,targetId:S,scenarioUrl:k==="new"&&g.trim()?g.trim():void 0,onRecordingComplete:G=>{a({title:"Recording Complete",description:"Scenario has been saved.",variant:"success"});const fe=G||z;fe?setTimeout(()=>{e(`/scenarios/${fe}`)},500):fetch("/api/config").then(ye=>ye.json()).then(ye=>{var ge;if((ge=ye.config)!=null&&ge.scenarios){l(ye.config.scenarios);const Re=ye.config.scenarios[ye.config.scenarios.length-1];Re!=null&&Re.key?e(`/scenarios/${Re.key}`):e("/scenarios")}}).catch(()=>{e("/scenarios")})}}),i.length>0&&n.jsxs(he,{children:[n.jsx(ke,{className:"py-3 border-b",children:n.jsxs(be,{className:"text-xs font-mono uppercase text-muted-foreground flex items-center gap-2",children:[n.jsx(e0,{className:"h-3 w-3"}),"Diagnostic Log (",i.length,")"]})}),n.jsx(me,{className:"p-0 max-h-48 overflow-y-auto",children:n.jsx("div",{className:"font-mono text-xs divide-y divide-border",children:i.slice(-20).map((G,fe)=>n.jsxs("div",{className:`px-4 py-2 ${G.level==="error"?"bg-red-50/10 text-red-600":G.level==="warn"?"bg-yellow-50/10 text-yellow-600":"text-muted-foreground"}`,children:[n.jsxs("span",{className:"opacity-50",children:["[",new Date(G.timestamp).toLocaleTimeString(),"]"]})," ",G.message]},fe))})})]}),n.jsxs(he,{className:"bg-muted/30",children:[n.jsx(ke,{children:n.jsx(be,{className:"text-sm font-medium",children:"How to Record"})}),n.jsx(me,{className:"text-sm text-muted-foreground space-y-4",children:n.jsxs("ol",{className:"list-decimal list-inside space-y-3",children:[n.jsxs("li",{children:[n.jsx("strong",{children:"Launch a dedicated Chrome instance"})," with debugging enabled:",n.jsxs("div",{className:"relative mt-1",children:[n.jsx("code",{className:"block bg-background px-2 py-1.5 pr-10 rounded text-xs font-mono select-all",children:'/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --remote-debugging-port=9222 --user-data-dir="$HOME/.reshot/chrome-debug"'}),n.jsx(T,{variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 -translate-y-1/2 h-6 w-6",onClick:()=>{navigator.clipboard.writeText('/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --remote-debugging-port=9222 --user-data-dir="$HOME/.reshot/chrome-debug"'),a({title:"Copied",description:"Command copied to clipboard"})},title:"Copy command",children:n.jsx(rn,{className:"h-3 w-3"})})]}),n.jsx("p",{className:"text-xs text-muted-foreground/70 mt-1 italic",children:"This uses a separate Chrome profile. Your main browser stays untouched."})]}),n.jsxs("li",{children:[n.jsx("strong",{children:"Navigate to your application"})," in the Chrome window that opens"]}),n.jsxs("li",{children:[n.jsx("strong",{children:'Click "Refresh"'})," in the Chrome Status card above to verify connection"]}),n.jsxs("li",{children:["Configure a new visual or select an existing scenario, then click"," ",n.jsx("strong",{children:'"Start Recording"'})]}),n.jsxs("li",{children:["Interact with your app - clicks and inputs will be captured. Click"," ",n.jsx("strong",{children:'"Capture Screen"'})," for screenshots."]}),n.jsxs("li",{children:["Click ",n.jsx("strong",{children:'"Stop & Save"'})," when finished"]})]})})]})]})}const ca=d.forwardRef(({checked:e,onCheckedChange:t,className:s,disabled:r},i)=>n.jsx("button",{ref:i,role:"switch","aria-checked":e,disabled:r,onClick:()=>t(!e),className:Y("inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background","disabled:cursor-not-allowed disabled:opacity-50",e?"bg-primary":"bg-muted",s),children:n.jsx("span",{className:Y("pointer-events-none h-5 w-5 rounded-full bg-foreground shadow-lg transition-transform duration-150",e?"translate-x-5":"translate-x-0.5")})}));ca.displayName="Switch";const js=d.forwardRef(({selected:e,onClick:t,label:s,children:r,className:i},a)=>n.jsxs("button",{ref:a,onClick:t,className:Y("group flex flex-col items-center gap-1.5 rounded-lg p-3 cursor-pointer transition-all duration-150","active:scale-[0.98]",e?"ring-2 ring-primary bg-primary/5 border-transparent":"border border-border/40 bg-card/30 hover:bg-card/60 hover:border-border/60 hover:shadow-[0_2px_8px_rgba(0,0,0,0.2)]",i),children:[n.jsx("div",{className:"w-full h-12 flex items-center justify-center",children:r}),n.jsx("span",{className:"text-xs text-muted-foreground group-hover:text-foreground transition-colors duration-150",children:s})]}));js.displayName="OptionCard";function Wi(e,t,s){const r=(e-t)/(s-t)*100;return`linear-gradient(to right, hsl(262 83% 58%) ${r}%, hsl(217 33% 17%) ${r}%)`}const F1=[{key:"locale",label:"Language",description:"Internationalization (i18n)",icon:ur},{key:"role",label:"User Role",description:"RBAC / Permissions",icon:tm},{key:"theme",label:"Theme",description:"Light/Dark mode",icon:Xc}];function $1(){var je,B,oe,se,re,qe,De,At;const[e,t]=d.useState(null),[s,r]=d.useState(!0),[i,a]=d.useState(!1),[o,l]=d.useState(null),[c,u]=d.useState(!1),[m,f]=d.useState(!1),[g,R]=d.useState(""),[k,C]=d.useState(""),[j,p]=d.useState(""),[h,x]=d.useState({}),[w,N]=d.useState(null),[S,P]=d.useState(!1),[b,O]=d.useState({enabled:!1,method:"redact",blurRadius:8,selectors:[]}),[D,v]=d.useState(""),[L,V]=d.useState(!1),[y,_]=d.useState({enabled:!1,frame:"none",shadow:"medium",padding:40,background:"transparent",borderRadius:0}),[F,$]=d.useState(!1),[E,A]=d.useState(null),[z,W]=d.useState(!1),[J,G]=d.useState([]),[fe,ye]=d.useState([]),[ge,Re]=d.useState(""),[U,X]=d.useState(null),{toast:Z}=Pt(),ce=d.useCallback(async()=>{try{const ee=await(await fetch("/api/config")).json();t(ee.config);const Ce=await(await fetch("/api/viewports")).json();x(Ce.all||{});const Ge=await(await fetch("/api/output-template")).json();G(Ge.presets||[]),ye(Ge.availableVariables||[]),Re(Ge.currentTemplate||"");const pn=await(await fetch("/api/privacy")).json();O(pn);const mn=await(await fetch("/api/style")).json();_(mn)}catch(I){console.error("Failed to load config:",I),Z({title:"Error",description:"Failed to load configuration",variant:"destructive"})}finally{r(!1)}},[Z]);d.useEffect(()=>{ce()},[ce]);const ie=d.useCallback(async I=>{if(!I){X(null);return}try{const pe=await(await fetch("/api/output-template/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({template:I})})).json();X(pe)}catch{X({valid:!1,error:"Failed to validate"})}},[]);d.useEffect(()=>{const I=setTimeout(()=>{ge&&ie(ge)},500);return()=>clearTimeout(I)},[ge,ie]),d.useEffect(()=>{if(!y.enabled)return;const I=setTimeout(async()=>{W(!0);try{const ee=await fetch("/api/style/preview",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({style:y})}),pe=await ee.json();ee.ok&&pe.preview&&A(pe.preview)}catch{}finally{W(!1)}},600);return()=>clearTimeout(I)},[y]);const ae=async()=>{var I;if(e){a(!0);try{const ee=await fetch("/api/config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(ge&&ge!==((I=e.output)==null?void 0:I.template)&&await fetch("/api/output-template",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({template:ge})}),ee.ok)Z({title:"Saved",description:"Configuration updated successfully",variant:"success"});else throw new Error("Failed to save")}catch{Z({title:"Error",description:"Failed to save configuration",variant:"destructive"})}finally{a(!1)}}},Se=(I,ee)=>{e&&t({...e,[I]:ee})},Ie=(I,ee)=>{e&&t({...e,viewport:{width:I,height:ee}})},mt=(I,ee,pe)=>{var Ge;if(!e||!I.trim())return;const Ce=I.toLowerCase().replace(/\s+/g,"-"),Oe=((Ge=e.variants)==null?void 0:Ge.dimensions)||{};if(Oe[Ce]){Z({title:"Already exists",description:`Dimension "${Ce}" already exists`,variant:"destructive"});return}t({...e,variants:{...e.variants,dimensions:{...Oe,[Ce]:{label:ee||I,description:pe,options:{}}}}}),l(Ce),u(!1),R("")},Nt=I=>{var pe;if(!e)return;const ee={...(pe=e.variants)==null?void 0:pe.dimensions};delete ee[I],t({...e,variants:{...e.variants,dimensions:ee}}),o===I&&l(Object.keys(ee)[0]||null)},Ft=(I,ee,pe)=>{var ls;if(!e||!ee.trim())return;const Ce=ee.toLowerCase().replace(/\s+/g,"-"),Oe=((ls=e.variants)==null?void 0:ls.dimensions)||{},Ge=Oe[I];if(Ge){if(Ge.options[Ce]){Z({title:"Already exists",description:`Option "${Ce}" already exists`,variant:"destructive"});return}t({...e,variants:{...e.variants,dimensions:{...Oe,[I]:{...Ge,options:{...Ge.options,[Ce]:{name:pe||ee,inject:[]}}}}}}),f(!1),C(""),p("")}},Yt=(I,ee)=>{var Ge;if(!e)return;const pe=((Ge=e.variants)==null?void 0:Ge.dimensions)||{},Ce=pe[I];if(!Ce)return;const Oe={...Ce.options};delete Oe[ee],t({...e,variants:{...e.variants,dimensions:{...pe,[I]:{...Ce,options:Oe}}}})},$t=(I,ee,pe,Ce,Oe)=>{var mn;if(!e)return;const Ge=((mn=e.variants)==null?void 0:mn.dimensions)||{},ls=Ge[I];if(!ls)return;const pn=ls.options[ee];if(!pn)return;const ki=Ce||Oe?[{method:pe,key:Ce,value:Oe}]:[];t({...e,variants:{...e.variants,dimensions:{...Ge,[I]:{...ls,options:{...ls.options,[ee]:{...pn,inject:ki}}}}}})};if(s)return n.jsx("div",{className:"h-full flex items-center justify-center",children:n.jsx(_e,{className:"h-6 w-6 animate-spin text-muted-foreground"})});if(!e)return n.jsx("div",{className:"p-6",children:n.jsx(he,{children:n.jsxs(me,{className:"py-12 text-center",children:[n.jsx(Ia,{className:"h-10 w-10 mx-auto mb-3 opacity-30"}),n.jsx("p",{className:"text-muted-foreground",children:"No configuration found."}),n.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Create a reshot.config.json file to get started."})]})})});const kt=((je=e.variants)==null?void 0:je.dimensions)||{},Tt=Object.keys(kt),Vt=o?kt[o]:null;return n.jsxs("div",{"data-testid":"studio-config","data-loaded":"true",className:"h-full flex flex-col",children:[n.jsxs("div",{className:"shrink-0 px-4 py-3 border-b flex items-center justify-between bg-card",children:[n.jsxs("div",{children:[n.jsx("h1",{className:"text-sm font-semibold",children:"Configuration"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"reshot.config.json"})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx(T,{variant:"ghost",size:"sm",onClick:ce,className:"h-7",children:n.jsx(_t,{className:"h-3 w-3"})}),n.jsxs(T,{size:"sm",onClick:ae,disabled:i,className:"h-7",children:[i?n.jsx(_e,{className:"h-3 w-3 animate-spin"}):n.jsx(Hr,{className:"h-3 w-3 mr-1"}),"Save"]})]})]}),n.jsxs("div",{className:"flex-1 overflow-auto p-4 space-y-4",children:[n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[n.jsxs("div",{className:"space-y-1",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Base URL"}),n.jsx(ve,{value:e.baseUrl,onChange:I=>Se("baseUrl",I.target.value),placeholder:"http://localhost:3000",className:"h-8 text-sm"})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Asset Directory"}),n.jsx(ve,{value:e.assetDir,onChange:I=>Se("assetDir",I.target.value),placeholder:".reshot/output",className:"h-8 text-sm"})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Viewport"}),n.jsxs("div",{className:"flex gap-1",children:[n.jsx(T,{variant:e.viewport.width===1280?"default":"outline",size:"sm",className:"h-8 text-xs flex-1",onClick:()=>Ie(1280,720),children:"720p"}),n.jsx(T,{variant:e.viewport.width===1920?"default":"outline",size:"sm",className:"h-8 text-xs flex-1",onClick:()=>Ie(1920,1080),children:"1080p"})]})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Options"}),n.jsxs("div",{className:"flex items-center gap-3 h-8",children:[n.jsxs("label",{className:"flex items-center gap-1.5 text-xs cursor-pointer",children:[n.jsx(ns,{checked:e.headless,onCheckedChange:I=>Se("headless",!!I)}),"Headless"]}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"text-xs text-muted-foreground",children:"×"}),n.jsx(ve,{type:"number",value:e.concurrency,onChange:I=>Se("concurrency",parseInt(I.target.value)||1),className:"h-7 w-12 text-xs text-center",min:1,max:8})]})]})]})]}),n.jsxs(he,{children:[n.jsx(ke,{className:"py-3 px-4",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx($y,{className:"h-4 w-4 text-muted-foreground"}),n.jsxs("div",{children:[n.jsx(be,{className:"text-sm",children:"Visual Diffing"}),n.jsx(at,{className:"text-xs",children:"Compare generated assets against approved baselines"})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-xs text-muted-foreground",children:(B=e.diffing)!=null&&B.enabled?"Enabled":"Disabled"}),n.jsx(ca,{checked:((oe=e.diffing)==null?void 0:oe.enabled)??!1,onCheckedChange:I=>{var ee,pe;return t({...e,diffing:{enabled:I,threshold:((ee=e.diffing)==null?void 0:ee.threshold)??.1,includeAA:((pe=e.diffing)==null?void 0:pe.includeAA)??!1}})}})]})]})}),((se=e.diffing)==null?void 0:se.enabled)&&n.jsx(me,{className:"pt-0 pb-4 px-4 space-y-4 border-t",children:n.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsxs(q,{className:"text-xs text-muted-foreground",children:["Sensitivity Threshold:"," ",((((re=e.diffing)==null?void 0:re.threshold)??.1)*100).toFixed(0),"%"]}),n.jsx("input",{type:"range",min:"0",max:"100",value:(((qe=e.diffing)==null?void 0:qe.threshold)??.1)*100,onChange:I=>t({...e,diffing:{...e.diffing,threshold:parseInt(I.target.value)/100}}),className:"slider-primary w-full",style:{background:Wi((((De=e.diffing)==null?void 0:De.threshold)??.1)*100,0,100)}}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Lower = more sensitive. 10% is recommended."})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Options"}),n.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[n.jsx(ns,{checked:((At=e.diffing)==null?void 0:At.includeAA)??!1,onCheckedChange:I=>t({...e,diffing:{...e.diffing,includeAA:!!I}})}),"Include anti-aliasing in diff"]}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"When disabled, minor rendering differences are ignored."})]})]})})]}),n.jsxs(he,{children:[n.jsx(ke,{className:"py-3 px-4",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(xr,{className:"h-4 w-4 text-muted-foreground"}),n.jsxs("div",{children:[n.jsx(be,{className:"text-sm",children:"Privacy Masking"}),n.jsx(at,{className:"text-xs",children:"Hide or redact sensitive elements before capture"})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-xs text-muted-foreground",children:b.enabled?"Enabled":"Disabled"}),n.jsx(ca,{checked:b.enabled,onCheckedChange:I=>O({...b,enabled:I})})]})]})}),b.enabled&&n.jsxs(me,{className:"pt-0 pb-4 px-4 space-y-4 border-t",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Default Method"}),n.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[n.jsx(js,{selected:b.method==="redact",onClick:()=>O({...b,method:"redact"}),label:"Redact",children:n.jsxs("div",{className:"w-full flex flex-col gap-1.5 px-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[9px] text-muted-foreground",children:"Email"}),n.jsx("div",{className:"w-14 h-2.5 bg-foreground rounded-sm"})]}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[9px] text-muted-foreground",children:"Phone"}),n.jsx("div",{className:"w-10 h-2.5 bg-foreground rounded-sm"})]})]})}),n.jsx(js,{selected:b.method==="blur",onClick:()=>O({...b,method:"blur"}),label:"Blur",children:n.jsxs("div",{className:"w-full flex flex-col gap-1.5 px-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[9px] text-muted-foreground",children:"Email"}),n.jsx("span",{className:"text-[9px] text-muted-foreground select-none",style:{filter:"blur(3px)"},children:"j@acme.co"})]}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[9px] text-muted-foreground",children:"Phone"}),n.jsx("span",{className:"text-[9px] text-muted-foreground select-none",style:{filter:"blur(3px)"},children:"555-0123"})]})]})}),n.jsx(js,{selected:b.method==="hide",onClick:()=>O({...b,method:"hide"}),label:"Hide",children:n.jsxs("div",{className:"w-full flex flex-col gap-1.5 px-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[9px] text-muted-foreground",children:"Email"}),n.jsx("div",{className:"w-14 h-3 border border-dashed border-muted-foreground/30 rounded-sm"})]}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[9px] text-muted-foreground",children:"Phone"}),n.jsx("div",{className:"w-10 h-3 border border-dashed border-muted-foreground/30 rounded-sm"})]})]})}),n.jsx(js,{selected:b.method==="remove",onClick:()=>O({...b,method:"remove"}),label:"Remove",children:n.jsxs("div",{className:"w-full flex flex-col gap-1.5 px-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[9px] text-muted-foreground",children:"Email"}),n.jsx("span",{className:"text-[8px] italic text-muted-foreground/30",children:"removed"})]}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[9px] text-muted-foreground",children:"Phone"}),n.jsx("span",{className:"text-[8px] italic text-muted-foreground/30",children:"removed"})]})]})})]})]}),b.method==="blur"&&n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"bg-muted/50 rounded-lg p-3 flex items-center justify-center",children:n.jsx("span",{className:"text-sm text-muted-foreground font-mono select-none",style:{filter:`blur(${b.blurRadius}px)`},children:"john@acme.com"})}),n.jsxs(q,{className:"text-xs text-muted-foreground",children:["Blur Radius: ",b.blurRadius,"px"]}),n.jsx("input",{type:"range",min:"1",max:"100",value:b.blurRadius,onChange:I=>O({...b,blurRadius:parseInt(I.target.value)}),className:"slider-primary w-full",style:{background:Wi(b.blurRadius,1,100)}})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsxs(q,{className:"text-xs text-muted-foreground",children:["CSS Selectors (",b.selectors.length,")"]}),b.selectors.length>0&&n.jsx("div",{className:"space-y-1",children:b.selectors.map((I,ee)=>{const pe=typeof I=="string"?I:I.selector,Ce=typeof I=="object"?I.method:void 0;return n.jsxs("div",{className:"flex items-center gap-2 bg-muted/50 rounded px-2 py-1",children:[n.jsx("code",{className:"text-xs font-mono flex-1 truncate",children:pe}),Ce&&n.jsx(ue,{variant:"secondary",className:"text-[10px]",children:Ce}),n.jsx(T,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 text-muted-foreground hover:text-destructive",onClick:()=>{const Oe=[...b.selectors];Oe.splice(ee,1),O({...b,selectors:Oe})},children:n.jsx(ln,{className:"h-3 w-3"})})]},ee)})}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx(ve,{value:D,onChange:I=>v(I.target.value),placeholder:".pii-email, [data-sensitive], .user-avatar",className:"h-7 text-xs font-mono",onKeyDown:I=>{I.key==="Enter"&&D.trim()&&(O({...b,selectors:[...b.selectors,D.trim()]}),v(""))}}),n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!D.trim(),onClick:()=>{D.trim()&&(O({...b,selectors:[...b.selectors,D.trim()]}),v(""))},children:[n.jsx(as,{className:"h-3 w-3 mr-1"}),"Add"]})]})]}),n.jsx("div",{className:"pt-2 border-t border-border/20",children:n.jsxs(T,{size:"sm",className:"h-7 text-xs",disabled:L,onClick:async()=>{V(!0);try{const I=await fetch("/api/privacy",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)});if(I.ok)Z({title:"Saved",description:"Privacy configuration updated",variant:"success"});else{const ee=await I.json();Z({title:"Error",description:ee.error||"Failed to save",variant:"destructive"})}}catch{Z({title:"Error",description:"Failed to save privacy config",variant:"destructive"})}finally{V(!1)}},children:[L?n.jsx(_e,{className:"h-3 w-3 animate-spin mr-1"}):n.jsx(Hr,{className:"h-3 w-3 mr-1"}),"Save Privacy Config"]})})]})]}),n.jsxs(he,{children:[n.jsx(ke,{className:"py-3 px-4",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(ao,{className:"h-4 w-4 text-muted-foreground"}),n.jsxs("div",{children:[n.jsx(be,{className:"text-sm",children:"Style & Framing"}),n.jsx(at,{className:"text-xs",children:"Add frames, shadows, and backgrounds to screenshots"})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-xs text-muted-foreground",children:y.enabled?"Enabled":"Disabled"}),n.jsx(ca,{checked:y.enabled,onCheckedChange:I=>_({...y,enabled:I})})]})]})}),y.enabled&&n.jsxs(me,{className:"pt-0 pb-4 px-4 space-y-4 border-t",children:[n.jsx("div",{className:"space-y-2 pt-3",children:E?n.jsxs("div",{className:`border rounded-md p-2 bg-muted/30 relative ${z?"opacity-50":""}`,children:[n.jsx("img",{src:E,alt:"Style preview",className:"max-w-full h-auto rounded"}),z&&n.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:n.jsx(_e,{className:"h-5 w-5 animate-spin text-primary"})})]}):n.jsxs("div",{className:"rounded-lg border border-border/30 bg-gradient-to-b from-muted/20 to-muted/10 preview-grid-bg flex items-center justify-center relative p-6",style:{minHeight:200},children:[n.jsx("div",{className:"relative overflow-hidden transition-all duration-150",style:{background:y.background,padding:`${Math.min(y.padding,40)*.4}px`,borderRadius:`${y.borderRadius*.5}px`,boxShadow:y.shadow==="small"?"0 1px 2px rgba(0,0,0,0.3)":y.shadow==="medium"?"0 4px 6px -1px rgba(0,0,0,0.3)":y.shadow==="large"?"0 10px 25px -5px rgba(0,0,0,0.4)":"none"},children:n.jsxs("div",{className:"w-64 rounded overflow-hidden",style:{borderRadius:`${Math.max(y.borderRadius*.3,2)}px`},children:[y.frame==="macos"&&n.jsxs("div",{className:"bg-[#2a2a2a] px-2.5 py-1.5 flex items-center gap-1",children:[n.jsx("span",{className:"w-[7px] h-[7px] rounded-full bg-[#ff5f57] inline-block"}),n.jsx("span",{className:"w-[7px] h-[7px] rounded-full bg-[#febc2e] inline-block"}),n.jsx("span",{className:"w-[7px] h-[7px] rounded-full bg-[#28c840] inline-block"})]}),y.frame==="windows"&&n.jsx("div",{className:"bg-[#2a2a2a] px-2 py-1 flex items-center justify-end",children:n.jsxs("span",{className:"text-[8px] text-muted-foreground flex gap-1.5",children:[n.jsx("span",{children:"—"}),n.jsx("span",{children:"□"}),n.jsx("span",{children:"×"})]})}),n.jsxs("div",{className:"bg-[#1e1e2e] p-2.5 space-y-2",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground/20"}),n.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground/20"}),n.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground/20"}),n.jsx("div",{className:"flex-1"}),n.jsx("div",{className:"w-8 h-1.5 rounded bg-muted-foreground/15"})]}),n.jsxs("div",{className:"space-y-1.5 pt-1",children:[n.jsx("div",{className:"w-3/4 h-1.5 rounded bg-muted-foreground/15"}),n.jsx("div",{className:"w-full h-1.5 rounded bg-muted-foreground/10"}),n.jsx("div",{className:"w-5/6 h-1.5 rounded bg-muted-foreground/10"}),n.jsx("div",{className:"w-2/3 h-1.5 rounded bg-muted-foreground/10"})]})]})]})}),z&&n.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/50 rounded-lg",children:n.jsx(_e,{className:"h-5 w-5 animate-spin text-primary"})})]})}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Frame"}),n.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[n.jsx(js,{selected:y.frame==="none",onClick:()=>_({...y,frame:"none"}),label:"None",children:n.jsx("div",{className:"w-full h-10 rounded bg-gradient-to-br from-muted/60 to-muted/30"})}),n.jsx(js,{selected:y.frame==="macos",onClick:()=>_({...y,frame:"macos"}),label:"macOS",children:n.jsxs("div",{className:"w-full rounded overflow-hidden",children:[n.jsxs("div",{className:"bg-[#2a2a2a] px-1.5 py-1 flex items-center gap-[3px]",children:[n.jsx("span",{className:"w-[6px] h-[6px] rounded-full bg-[#ff5f57] inline-block"}),n.jsx("span",{className:"w-[6px] h-[6px] rounded-full bg-[#febc2e] inline-block"}),n.jsx("span",{className:"w-[6px] h-[6px] rounded-full bg-[#28c840] inline-block"})]}),n.jsx("div",{className:"h-6 bg-gradient-to-br from-muted/60 to-muted/30"})]})}),n.jsx(js,{selected:y.frame==="windows",onClick:()=>_({...y,frame:"windows"}),label:"Windows",children:n.jsxs("div",{className:"w-full rounded overflow-hidden",children:[n.jsx("div",{className:"bg-[#2a2a2a] px-1.5 py-1 flex items-center justify-end",children:n.jsxs("span",{className:"text-[9px] text-muted-foreground flex gap-1",children:[n.jsx("span",{children:"—"}),n.jsx("span",{children:"□"}),n.jsx("span",{children:"×"})]})}),n.jsx("div",{className:"h-6 bg-gradient-to-br from-muted/60 to-muted/30"})]})})]})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Shadow"}),n.jsx("div",{className:"grid grid-cols-4 gap-2",children:[{key:"none",label:"None",shadow:"shadow-none"},{key:"small",label:"Small",shadow:"shadow-sm"},{key:"medium",label:"Medium",shadow:"shadow-md"},{key:"large",label:"Large",shadow:"shadow-xl"}].map(({key:I,label:ee,shadow:pe})=>n.jsx(js,{selected:y.shadow===I,onClick:()=>_({...y,shadow:I}),label:ee,children:n.jsx("div",{className:`w-10 h-7 rounded bg-card border border-border/50 ${pe}`})},I))})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsxs(q,{className:"text-xs text-muted-foreground",children:["Padding: ",y.padding,"px"]}),n.jsx("input",{type:"range",min:"0",max:"200",value:y.padding,onChange:I=>_({...y,padding:parseInt(I.target.value)||0}),className:"slider-primary w-full",style:{background:Wi(y.padding,0,200)}})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsxs(q,{className:"text-xs text-muted-foreground",children:["Border Radius: ",y.borderRadius,"px"]}),n.jsx("input",{type:"range",min:"0",max:"50",value:y.borderRadius,onChange:I=>_({...y,borderRadius:parseInt(I.target.value)||0}),className:"slider-primary w-full",style:{background:Wi(y.borderRadius,0,50)}})]})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Background"}),n.jsx("div",{className:"flex gap-2 flex-wrap",children:["transparent","#ffffff","#f5f5f5","#1a1a2e","#0f172a","linear-gradient(135deg, #667eea, #764ba2)","linear-gradient(135deg, #f093fb, #f5576c)","linear-gradient(135deg, #4facfe, #00f2fe)"].map(I=>n.jsx("button",{onClick:()=>_({...y,background:I}),className:`w-8 h-8 rounded-md transition-all duration-150 cursor-pointer shrink-0 hover:scale-110 active:scale-100 ${I==="transparent"?"checkerboard":""} ${y.background===I?"ring-2 ring-primary ring-offset-2 ring-offset-background":"border border-border hover:border-primary/50"}`,style:I!=="transparent"?{background:I}:void 0,title:I},I))}),n.jsx(ve,{value:y.background,onChange:I=>_({...y,background:I.target.value}),placeholder:"transparent, #hex, or linear-gradient(...)",className:"h-7 text-xs font-mono"})]}),n.jsx("div",{className:"pt-2 border-t border-border/20",children:n.jsxs(T,{size:"sm",className:"h-7 text-xs",disabled:F,onClick:async()=>{$(!0);try{const I=await fetch("/api/style",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(y)});if(I.ok)Z({title:"Saved",description:"Style configuration updated",variant:"success"});else{const ee=await I.json();Z({title:"Error",description:ee.error||"Failed to save",variant:"destructive"})}}catch{Z({title:"Error",description:"Failed to save style config",variant:"destructive"})}finally{$(!1)}},children:[F?n.jsx(_e,{className:"h-3 w-3 animate-spin mr-1"}):n.jsx(Hr,{className:"h-3 w-3 mr-1"}),"Save Style Config"]})})]})]}),n.jsxs(he,{children:[n.jsx(ke,{className:"py-3 px-4",children:n.jsx("div",{className:"flex items-center justify-between",children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(oh,{className:"h-4 w-4 text-muted-foreground"}),n.jsxs("div",{children:[n.jsx(be,{className:"text-sm",children:"Viewport Presets"}),n.jsx(at,{className:"text-xs",children:"Device sizes for responsive screenshots"})]})]})})}),n.jsx(me,{className:"pt-0 pb-4 px-4 border-t",children:n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"grid grid-cols-4 gap-2",children:Object.entries(h).filter(([I,ee])=>["desktop","tablet","mobile"].includes(ee.category)).slice(0,8).map(([I,ee])=>{const pe=e.viewport.width===ee.width&&e.viewport.height===ee.height,Ce=ee.category==="mobile"?Xy:ee.category==="tablet"?Zy:oh;return n.jsxs(T,{variant:pe?"default":"outline",size:"sm",className:"h-auto py-2 px-3 flex flex-col items-start",onClick:()=>Ie(ee.width,ee.height),children:[n.jsxs("div",{className:"flex items-center gap-1.5 w-full",children:[n.jsx(Ce,{className:"h-3 w-3"}),n.jsx("span",{className:"text-xs font-medium truncate",children:ee.name})]}),n.jsxs("span",{className:"text-[10px] text-muted-foreground mt-0.5",children:[ee.width,"×",ee.height]})]},I)})}),n.jsxs("div",{className:"flex items-center gap-2 pt-2 border-t",children:[n.jsx(q,{className:"text-xs text-muted-foreground whitespace-nowrap",children:"Custom:"}),n.jsx(ve,{type:"number",value:e.viewport.width,onChange:I=>Ie(parseInt(I.target.value)||1280,e.viewport.height),className:"h-7 w-20 text-xs",placeholder:"Width"}),n.jsx("span",{className:"text-xs text-muted-foreground",children:"×"}),n.jsx(ve,{type:"number",value:e.viewport.height,onChange:I=>Ie(e.viewport.width,parseInt(I.target.value)||720),className:"h-7 w-20 text-xs",placeholder:"Height"}),n.jsx("div",{className:"flex-1"}),n.jsx(q,{className:"text-xs text-muted-foreground",children:"Scale:"}),n.jsxs("select",{value:e.viewport.deviceScaleFactor||2,onChange:I=>t({...e,viewport:{...e.viewport,deviceScaleFactor:parseFloat(I.target.value)}}),className:"h-7 px-2 text-xs border rounded bg-background",children:[n.jsx("option",{value:"1",children:"1x"}),n.jsx("option",{value:"2",children:"2x (Retina)"}),n.jsx("option",{value:"3",children:"3x"})]})]})]})})]}),n.jsxs(he,{children:[n.jsx(ke,{className:"py-3 px-4",children:n.jsx("div",{className:"flex items-center justify-between",children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(zy,{className:"h-4 w-4 text-muted-foreground"}),n.jsxs("div",{children:[n.jsx(be,{className:"text-sm",children:"Output Path Template"}),n.jsx(at,{className:"text-xs",children:"Customize where captured assets are saved"})]})]})})}),n.jsxs(me,{className:"pt-0 pb-4 px-4 border-t space-y-4",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Quick Presets"}),n.jsx("div",{className:"flex flex-wrap gap-1.5",children:J.slice(0,6).map(I=>n.jsx(T,{variant:ge===I.template?"default":"outline",size:"sm",className:"h-6 text-xs px-2",onClick:()=>Re(I.template),title:I.description,children:I.name},I.name))})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Custom Template"}),n.jsxs("div",{className:"relative",children:[n.jsx(ve,{value:ge,onChange:I=>Re(I.target.value),placeholder:"./docs/assets/{{locale}}/{{scenario}}/{{name}}.{{ext}}",className:`h-8 text-sm font-mono pr-8 ${(U==null?void 0:U.valid)===!1?"border-red-500":""}`}),U&&n.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2",children:U.valid?n.jsx("span",{className:"text-green-500 text-xs",children:"✓"}):n.jsx("span",{className:"text-red-500 text-xs",children:"✗"})})]}),(U==null?void 0:U.error)&&n.jsx("p",{className:"text-xs text-red-500",children:U.error}),(U==null?void 0:U.warning)&&n.jsx("p",{className:"text-xs text-yellow-600",children:U.warning})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Available Variables"}),n.jsx("div",{className:"flex flex-wrap gap-1",children:fe.slice(0,12).map(I=>n.jsx(ue,{variant:"secondary",className:"text-[10px] cursor-pointer hover:bg-accent",onClick:()=>Re(ee=>ee+`{{${I.name}}}`),title:I.description,children:`{{${I.name}}}`},I.name))}),n.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Click a variable to insert it into the template"})]})]})]}),n.jsxs(he,{children:[n.jsx(ke,{className:"py-3 px-4",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx(be,{className:"text-sm",children:"Variants"}),n.jsx(at,{className:"text-xs",children:"Configure locales, roles, themes"})]}),n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>u(!0),children:[n.jsx(as,{className:"h-3 w-3 mr-1"}),"Add"]})]})}),n.jsx(me,{className:"p-0",children:Tt.length===0?n.jsxs("div",{className:"py-8 text-center border-t",children:[n.jsx(ur,{className:"h-8 w-8 mx-auto mb-2 opacity-20"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"No variants configured"}),n.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Add locale, role, or theme dimensions"})]}):n.jsxs("div",{className:"flex border-t",children:[n.jsx("div",{className:"w-48 border-r shrink-0",children:Tt.map(I=>{const ee=kt[I],pe=I==="locale"?ur:I==="role"?tm:I==="theme"?Xc:Ia,Ce=Object.keys(ee.options).length;return n.jsxs("button",{onClick:()=>l(I),className:`w-full px-3 py-2 text-left flex items-center gap-2 hover:bg-accent/50 transition-colors ${o===I?"bg-accent":""}`,children:[n.jsx(pe,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium truncate",children:ee.label}),n.jsxs("div",{className:"text-xs text-muted-foreground",children:[Ce," option",Ce!==1?"s":""]})]}),n.jsx(Ps,{className:"h-3.5 w-3.5 opacity-40"})]},I)})}),n.jsx("div",{className:"flex-1 min-w-0",children:Vt&&o?n.jsxs("div",{children:[n.jsxs("div",{className:"px-4 py-3 border-b bg-muted/30 flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"font-medium text-sm",children:Vt.label}),n.jsx("div",{className:"text-xs text-muted-foreground",children:Vt.description||"No description"})]}),n.jsxs("div",{className:"flex gap-1",children:[n.jsxs(T,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>f(!0),children:[n.jsx(as,{className:"h-3 w-3 mr-1"}),"Option"]}),n.jsx(T,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-destructive hover:text-destructive",onClick:()=>Nt(o),children:n.jsx(ps,{className:"h-3 w-3"})})]})]}),n.jsx("div",{className:"divide-y",children:Object.keys(Vt.options).length===0?n.jsx("div",{className:"py-6 text-center text-muted-foreground text-sm",children:"No options yet. Add one to get started."}):Object.entries(Vt.options).map(([I,ee])=>{var Ce;const pe=((Ce=ee.inject)==null?void 0:Ce[0])||{method:"localStorage",key:"",value:""};return n.jsx("div",{className:"px-4 py-3",children:n.jsxs("div",{className:"flex items-start gap-3",children:[n.jsx("div",{className:"shrink-0 pt-0.5",children:n.jsx(ue,{variant:"secondary",className:"text-xs",children:I})}),n.jsxs("div",{className:"flex-1 space-y-2 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium",children:ee.name}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("select",{value:pe.method,onChange:Oe=>$t(o,I,Oe.target.value,pe.key||"",pe.value||""),className:"h-7 text-xs rounded border bg-background px-2",children:[n.jsx("option",{value:"localStorage",children:"localStorage"}),n.jsx("option",{value:"cookie",children:"cookie"}),n.jsx("option",{value:"urlParam",children:"URL param"}),n.jsx("option",{value:"browser",children:"browser"}),n.jsx("option",{value:"header",children:"header"})]}),n.jsx(ve,{value:pe.key||"",onChange:Oe=>$t(o,I,pe.method,Oe.target.value,pe.value||""),placeholder:"key",className:"h-7 text-xs w-24"}),n.jsx(ve,{value:pe.value||"",onChange:Oe=>$t(o,I,pe.method,pe.key||"",Oe.target.value),placeholder:"value",className:"h-7 text-xs flex-1"})]})]}),n.jsx(T,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>Yt(o,I),children:n.jsx(ln,{className:"h-3 w-3"})})]})},I)})})]}):n.jsx("div",{className:"py-12 text-center text-muted-foreground text-sm",children:"Select a dimension to edit"})})]})})]})]}),n.jsx(st,{open:c,onOpenChange:u,children:n.jsxs(nt,{className:"max-w-sm",children:[n.jsx(Xe,{children:n.jsx(Ze,{children:"Add Variant Dimension"})}),n.jsxs("div",{className:"space-y-4 py-2",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs text-muted-foreground",children:"Quick Add"}),n.jsx("div",{className:"grid grid-cols-3 gap-2",children:F1.map(I=>{const ee=kt[I.key],pe=I.icon;return n.jsxs(T,{variant:"outline",size:"sm",disabled:!!ee,onClick:()=>mt(I.key,I.label,I.description),className:"h-auto py-2 flex-col gap-1",children:[n.jsx(pe,{className:"h-4 w-4"}),n.jsx("span",{className:"text-xs",children:I.label})]},I.key)})})]}),n.jsxs("div",{className:"relative",children:[n.jsx("div",{className:"absolute inset-0 flex items-center",children:n.jsx("span",{className:"w-full border-t"})}),n.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:n.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"or custom"})})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(q,{className:"text-xs",children:"Custom Dimension Key"}),n.jsx(ve,{value:g,onChange:I=>R(I.target.value),placeholder:"e.g., viewport, env, feature",className:"h-8"})]})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"ghost",size:"sm",onClick:()=>u(!1),children:"Cancel"}),n.jsx(T,{size:"sm",onClick:()=>mt(g,g,""),disabled:!g.trim(),children:"Add"})]})]})}),n.jsx(st,{open:m,onOpenChange:f,children:n.jsxs(nt,{className:"max-w-sm",children:[n.jsx(Xe,{children:n.jsx(Ze,{children:"Add Option"})}),n.jsxs("div",{className:"space-y-3 py-2",children:[n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(q,{className:"text-xs",children:"Option Key"}),n.jsx(ve,{value:k,onChange:I=>C(I.target.value),placeholder:o==="locale"?"e.g., en, ko, ja":o==="role"?"e.g., admin, user":"e.g., light, dark",className:"h-8"})]}),n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(q,{className:"text-xs",children:"Display Name"}),n.jsx(ve,{value:j,onChange:I=>p(I.target.value),placeholder:o==="locale"?"e.g., English, 한국어":o==="role"?"e.g., Administrator":"e.g., Light Mode",className:"h-8"})]})]}),n.jsxs(lt,{children:[n.jsx(T,{variant:"ghost",size:"sm",onClick:()=>u(!1),children:"Cancel"}),n.jsx(T,{size:"sm",onClick:()=>o&&Ft(o,k,j),disabled:!k.trim(),children:"Add Option"})]})]})})]})}function V1(){return n.jsx(V0,{children:n.jsx(Ij,{children:n.jsx(yy,{children:n.jsx(c1,{children:n.jsxs("div",{className:"min-h-screen bg-background",children:[n.jsx(U1,{}),n.jsx(d1,{})]})})})})})}function U1(){const e=On(),t=Os(),[s,r]=d.useState("Project"),[i,a]=d.useState(!1),[o,l]=d.useState(!1),[c,u]=d.useState("not-running"),m=d.useRef(null),f=()=>{fetch("/api/status").then(h=>h.json()).then(h=>{var x,w;(x=h.settings)!=null&&x.projectName&&r(h.settings.projectName),a(((w=h.settings)==null?void 0:w.isAuthenticated)||!1)}).catch(()=>{})};d.useEffect(()=>{f()},[]);const g=d.useCallback(()=>{fetch("/api/recorder/check-chrome").then(h=>h.json()).then(h=>{h.chromeAvailable&&h.hasValidTab?u("ready"):h.chromeAvailable?u("no-tabs"):u("not-running")}).catch(()=>u("not-running"))},[]);d.useEffect(()=>(g(),m.current=setInterval(g,12e3),()=>{m.current&&clearInterval(m.current)}),[g]),d.useEffect(()=>{const h=x=>{if((x.metaKey||x.ctrlKey)&&x.key>="1"&&x.key<="9"){x.preventDefault();const w=["/","/recorder","/config"],N=parseInt(x.key)-1;w[N]&&t(w[N])}};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[t]);const R=[{path:"/",label:"Home",icon:My,shortcut:"1"}],k=[{path:"/scenarios",label:"All Scenarios",icon:Rn},{path:"/assets",label:"Assets",icon:fn},{path:"/jobs",label:"Jobs",icon:By}],C=()=>{const h=e.pathname;if(h==="/")return{title:"Overview",breadcrumb:null};if(h.startsWith("/scenarios/"))return{title:h.split("/")[2],breadcrumb:"Scenarios"};if(h.startsWith("/assets/"))return{title:"Asset",breadcrumb:"Assets"};const x=[...R,...k,{path:"/config",label:"Settings"}].find(w=>h===w.path||h.startsWith(w.path+"/"));return{title:(x==null?void 0:x.label)||"Page",breadcrumb:null}},{title:j,breadcrumb:p}=C();return n.jsxs("div",{className:"flex h-screen bg-background",children:[n.jsxs("aside",{className:"w-[200px] border-r border-sidebar-border bg-sidebar-background flex flex-col",children:[n.jsx("div",{className:"h-12 flex items-center px-3 border-b border-sidebar-border",children:n.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[n.jsx("div",{className:"w-6 h-6 rounded-md bg-primary/20 flex items-center justify-center",children:n.jsx(Ty,{className:"h-3.5 w-3.5 text-primary"})}),n.jsx("div",{className:"flex-1 min-w-0",children:n.jsx("p",{className:"text-[13px] font-medium text-sidebar-foreground truncate",children:s})})]})}),n.jsxs("nav",{className:"flex-1 py-2 px-2 space-y-0.5 overflow-y-auto linear-scrollbar",children:[R.map(h=>{const x=h.icon,w=e.pathname===h.path||h.path!=="/"&&e.pathname.startsWith(h.path);return n.jsxs(Kt,{to:h.path,className:Y("group flex items-center gap-2.5 px-2 py-1.5 rounded-md text-[13px] transition-colors",w?"bg-sidebar-accent text-sidebar-foreground":"text-muted-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground"),children:[n.jsx(x,{className:Y("h-4 w-4 shrink-0",w?"text-primary":"text-muted-foreground group-hover:text-sidebar-foreground")}),n.jsx("span",{className:"flex-1",children:h.label}),h.shortcut&&n.jsxs("span",{className:"kbd opacity-0 group-hover:opacity-100 transition-opacity",children:["⌘",h.shortcut]})]},h.path)}),n.jsx("div",{className:"h-px bg-sidebar-border my-2"}),n.jsxs(Kt,{to:"/recorder",className:Y("flex items-center gap-2.5 px-2 py-2 rounded-md text-[13px] transition-colors border",e.pathname==="/recorder"?"bg-primary text-primary-foreground border-primary":"border-primary/30 text-primary hover:bg-primary/10 hover:border-primary/50"),children:[n.jsx(_n,{className:"h-4 w-4 shrink-0"}),n.jsx("span",{className:"flex-1 font-medium",children:"Record New Scenario"})]}),n.jsx("div",{className:"h-px bg-sidebar-border my-2"}),k.map(h=>{const x=h.icon,w=e.pathname.startsWith(h.path);return n.jsxs(Kt,{to:h.path,className:Y("flex items-center gap-2.5 px-2 py-1.5 rounded-md text-[13px] transition-colors",w?"bg-sidebar-accent/50 text-sidebar-foreground":"text-muted-foreground/70 hover:bg-sidebar-accent/30 hover:text-muted-foreground"),children:[n.jsx(x,{className:"h-4 w-4 shrink-0"}),n.jsx("span",{children:h.label})]},h.path)})]}),n.jsxs("div",{className:"p-2 border-t border-sidebar-border space-y-0.5",children:[n.jsxs(Kt,{to:"/config",className:Y("group flex items-center gap-2.5 px-2 py-1.5 rounded-md text-[13px] transition-colors",e.pathname==="/config"?"bg-sidebar-accent text-sidebar-foreground":"text-muted-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground"),children:[n.jsx(Ia,{className:"h-4 w-4 shrink-0"}),n.jsx("span",{className:"flex-1",children:"Settings"}),n.jsx("span",{className:"kbd opacity-0 group-hover:opacity-100 transition-opacity",children:"⌘5"})]}),n.jsxs("button",{onClick:()=>l(!0),className:Y("w-full flex items-center gap-2.5 px-2 py-1.5 rounded-md text-[13px] transition-colors","text-muted-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground"),children:[n.jsx("div",{className:Y("status-dot",i?"status-dot-success":"status-dot-neutral")}),n.jsx("span",{className:"flex-1 text-left",children:i?"Connected":"Not connected"}),!i&&n.jsx(em,{className:"h-3.5 w-3.5 opacity-50"})]}),n.jsxs("button",{onClick:()=>t("/recorder"),className:Y("w-full flex items-center gap-2.5 px-2 py-1.5 rounded-md text-[13px] transition-colors","text-muted-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground"),children:[n.jsx("div",{className:Y("status-dot",c==="ready"?"status-dot-success":c==="no-tabs"?"status-dot-warning":"status-dot-neutral")}),n.jsx("span",{className:"flex-1 text-left",children:c==="ready"?"Chrome ready":c==="no-tabs"?"Chrome: no tabs":"Chrome: not running"}),n.jsx(Yp,{className:"h-3.5 w-3.5 opacity-50"})]})]}),n.jsx(wi,{open:o,onOpenChange:l,onAuthenticated:f})]}),n.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[n.jsxs("header",{className:"h-12 border-b border-border bg-background/50 backdrop-blur-sm flex items-center justify-between px-4",children:[n.jsxs("div",{className:"flex items-center gap-2 text-[13px]",children:[p&&n.jsxs(n.Fragment,{children:[n.jsx(Kt,{to:`/${p.toLowerCase()}`,className:"text-muted-foreground hover:text-foreground transition-colors",children:p}),n.jsx(Ps,{className:"h-3.5 w-3.5 text-muted-foreground/50"})]}),n.jsx("span",{className:"font-medium text-foreground",children:j})]}),n.jsxs("button",{onClick:()=>l(!0),className:"flex items-center gap-2 text-[13px] text-muted-foreground hover:text-foreground transition-colors px-2 py-1 rounded-md hover:bg-sidebar-accent/50",children:[n.jsx("div",{className:Y("w-2 h-2 rounded-full",i?"bg-green-500":"bg-neutral-400")}),n.jsx("span",{children:s})]})]}),n.jsx("main",{className:"flex-1 overflow-auto bg-background linear-scrollbar",children:n.jsxs(uy,{children:[n.jsx(us,{path:"/",element:n.jsx(p1,{})}),n.jsx(us,{path:"/recorder",element:n.jsx(D1,{})}),n.jsx(us,{path:"/connection",element:n.jsx(z1,{})}),n.jsx(us,{path:"/scenarios",element:n.jsx(x1,{})}),n.jsx(us,{path:"/scenarios/:key",element:n.jsx(T1,{})}),n.jsx(us,{path:"/assets",element:n.jsx(O1,{})}),n.jsx(us,{path:"/assets/:scenarioKey/:variationSlug/:captureKey",element:n.jsx(M1,{})}),n.jsx(us,{path:"/jobs",element:n.jsx(L1,{})}),n.jsx(us,{path:"/config",element:n.jsx($1,{})})]})})]})]})}window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{localStorage.getItem("reshot-theme")||(document.documentElement.classList.toggle("dark",e.matches),document.documentElement.style.colorScheme=e.matches?"dark":"light")});Ho.createRoot(document.getElementById("root")).render(n.jsx(Oh.StrictMode,{children:n.jsx(V1,{})}));