tycono 0.1.41 → 0.1.42

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.
@@ -78,7 +78,7 @@ Error generating stack: `+o.message+`
78
78
  `))}function x(v,S,j,E){const C=j.enter("tableCell"),A=j.enter("phrasing"),M=j.containerPhrasing(v,{...E,before:u,after:u});return A(),C(),M}function f(v,S){return Qk(v,{align:S,alignDelimiters:i,padding:r,stringLength:c})}function g(v,S,j){const E=v.children;let C=-1;const A=[],M=S.enter("table");for(;++C<E.length;)A[C]=y(E[C],S,j);return M(),A}function y(v,S,j){const E=v.children;let C=-1;const A=[],M=S.enter("tableRow");for(;++C<E.length;)A[C]=x(E[C],v,S,j);return M(),A}function b(v,S,j){let E=qy.inlineCode(v,S,j);return j.stack.includes("tableCell")&&(E=E.replace(/\|/g,"\\$&")),E}}function B4(){return{exit:{taskListCheckValueChecked:a0,taskListCheckValueUnchecked:a0,paragraph:$4}}}function L4(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:H4}}}function a0(t){const l=this.stack[this.stack.length-2];l.type,l.checked=t.type==="taskListCheckValueChecked"}function $4(t){const l=this.stack[this.stack.length-2];if(l&&l.type==="listItem"&&typeof l.checked=="boolean"){const r=this.stack[this.stack.length-1];r.type;const i=r.children[0];if(i&&i.type==="text"){const c=l.children;let u=-1,d;for(;++u<c.length;){const m=c[u];if(m.type==="paragraph"){d=m;break}}d===r&&(i.value=i.value.slice(1),i.value.length===0?r.children.shift():r.position&&i.position&&typeof i.position.start.offset=="number"&&(i.position.start.column++,i.position.start.offset++,r.position.start=Object.assign({},i.position.start)))}}this.exit(t)}function H4(t,l,r,i){const c=t.children[0],u=typeof t.checked=="boolean"&&c&&c.type==="paragraph",d="["+(t.checked?"x":" ")+"] ",m=r.createTracker(i);u&&m.move(d);let x=qy.listItem(t,l,r,{...i,...m.current()});return u&&(x=x.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,f)),x;function f(g){return g+d}}function U4(){return[bk(),Hk(),qk(),T4(),B4()]}function I4(t){return{extensions:[vk(),Uk(t),Xk(),O4(t),L4()]}}const Y4={tokenize:W4,partial:!0},Xy={tokenize:Q4,partial:!0},Vy={tokenize:Z4,partial:!0},Gy={tokenize:J4,partial:!0},q4={tokenize:P4,partial:!0},Ky={name:"wwwAutolink",tokenize:G4,previous:Qy},Wy={name:"protocolAutolink",tokenize:K4,previous:Zy},rr={name:"emailAutolink",tokenize:V4,previous:Jy},Ml={};function X4(){return{text:Ml}}let ma=48;for(;ma<123;)Ml[ma]=rr,ma++,ma===58?ma=65:ma===91&&(ma=97);Ml[43]=rr;Ml[45]=rr;Ml[46]=rr;Ml[95]=rr;Ml[72]=[rr,Wy];Ml[104]=[rr,Wy];Ml[87]=[rr,Ky];Ml[119]=[rr,Ky];function V4(t,l,r){const i=this;let c,u;return d;function d(y){return!Gf(y)||!Jy.call(i,i.previous)||kh(i.events)?r(y):(t.enter("literalAutolink"),t.enter("literalAutolinkEmail"),m(y))}function m(y){return Gf(y)?(t.consume(y),m):y===64?(t.consume(y),x):r(y)}function x(y){return y===46?t.check(q4,g,f)(y):y===45||y===95||Sn(y)?(u=!0,t.consume(y),x):g(y)}function f(y){return t.consume(y),c=!0,x}function g(y){return u&&c&&Tn(i.previous)?(t.exit("literalAutolinkEmail"),t.exit("literalAutolink"),l(y)):r(y)}}function G4(t,l,r){const i=this;return c;function c(d){return d!==87&&d!==119||!Qy.call(i,i.previous)||kh(i.events)?r(d):(t.enter("literalAutolink"),t.enter("literalAutolinkWww"),t.check(Y4,t.attempt(Xy,t.attempt(Vy,u),r),r)(d))}function u(d){return t.exit("literalAutolinkWww"),t.exit("literalAutolink"),l(d)}}function K4(t,l,r){const i=this;let c="",u=!1;return d;function d(y){return(y===72||y===104)&&Zy.call(i,i.previous)&&!kh(i.events)?(t.enter("literalAutolink"),t.enter("literalAutolinkHttp"),c+=String.fromCodePoint(y),t.consume(y),m):r(y)}function m(y){if(Tn(y)&&c.length<5)return c+=String.fromCodePoint(y),t.consume(y),m;if(y===58){const b=c.toLowerCase();if(b==="http"||b==="https")return t.consume(y),x}return r(y)}function x(y){return y===47?(t.consume(y),u?f:(u=!0,x)):r(y)}function f(y){return y===null||Ac(y)||Rt(y)||wa(y)||Lc(y)?r(y):t.attempt(Xy,t.attempt(Vy,g),r)(y)}function g(y){return t.exit("literalAutolinkHttp"),t.exit("literalAutolink"),l(y)}}function W4(t,l,r){let i=0;return c;function c(d){return(d===87||d===119)&&i<3?(i++,t.consume(d),c):d===46&&i===3?(t.consume(d),u):r(d)}function u(d){return d===null?r(d):l(d)}}function Q4(t,l,r){let i,c,u;return d;function d(f){return f===46||f===95?t.check(Gy,x,m)(f):f===null||Rt(f)||wa(f)||f!==45&&Lc(f)?x(f):(u=!0,t.consume(f),d)}function m(f){return f===95?i=!0:(c=i,i=void 0),t.consume(f),d}function x(f){return c||i||!u?r(f):l(f)}}function Z4(t,l){let r=0,i=0;return c;function c(d){return d===40?(r++,t.consume(d),c):d===41&&i<r?u(d):d===33||d===34||d===38||d===39||d===41||d===42||d===44||d===46||d===58||d===59||d===60||d===63||d===93||d===95||d===126?t.check(Gy,l,u)(d):d===null||Rt(d)||wa(d)?l(d):(t.consume(d),c)}function u(d){return d===41&&i++,t.consume(d),c}}function J4(t,l,r){return i;function i(m){return m===33||m===34||m===39||m===41||m===42||m===44||m===46||m===58||m===59||m===63||m===95||m===126?(t.consume(m),i):m===38?(t.consume(m),u):m===93?(t.consume(m),c):m===60||m===null||Rt(m)||wa(m)?l(m):r(m)}function c(m){return m===null||m===40||m===91||Rt(m)||wa(m)?l(m):i(m)}function u(m){return Tn(m)?d(m):r(m)}function d(m){return m===59?(t.consume(m),i):Tn(m)?(t.consume(m),d):r(m)}}function P4(t,l,r){return i;function i(u){return t.consume(u),c}function c(u){return Sn(u)?r(u):l(u)}}function Qy(t){return t===null||t===40||t===42||t===95||t===91||t===93||t===126||Rt(t)}function Zy(t){return!Tn(t)}function Jy(t){return!(t===47||Gf(t))}function Gf(t){return t===43||t===45||t===46||t===95||Sn(t)}function kh(t){let l=t.length,r=!1;for(;l--;){const i=t[l][1];if((i.type==="labelLink"||i.type==="labelImage")&&!i._balanced){r=!0;break}if(i._gfmAutolinkLiteralWalkedInto){r=!1;break}}return t.length>0&&!r&&(t[t.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),r}const ej={tokenize:oj,partial:!0};function tj(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:aj,continuation:{tokenize:ij},exit:sj}},text:{91:{name:"gfmFootnoteCall",tokenize:rj},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:nj,resolveTo:lj}}}}function nj(t,l,r){const i=this;let c=i.events.length;const u=i.parser.gfmFootnotes||(i.parser.gfmFootnotes=[]);let d;for(;c--;){const x=i.events[c][1];if(x.type==="labelImage"){d=x;break}if(x.type==="gfmFootnoteCall"||x.type==="labelLink"||x.type==="label"||x.type==="image"||x.type==="link")break}return m;function m(x){if(!d||!d._balanced)return r(x);const f=gl(i.sliceSerialize({start:d.end,end:i.now()}));return f.codePointAt(0)!==94||!u.includes(f.slice(1))?r(x):(t.enter("gfmFootnoteCallLabelMarker"),t.consume(x),t.exit("gfmFootnoteCallLabelMarker"),l(x))}}function lj(t,l){let r=t.length;for(;r--;)if(t[r][1].type==="labelImage"&&t[r][0]==="enter"){t[r][1];break}t[r+1][1].type="data",t[r+3][1].type="gfmFootnoteCallLabelMarker";const i={type:"gfmFootnoteCall",start:Object.assign({},t[r+3][1].start),end:Object.assign({},t[t.length-1][1].end)},c={type:"gfmFootnoteCallMarker",start:Object.assign({},t[r+3][1].end),end:Object.assign({},t[r+3][1].end)};c.end.column++,c.end.offset++,c.end._bufferIndex++;const u={type:"gfmFootnoteCallString",start:Object.assign({},c.end),end:Object.assign({},t[t.length-1][1].start)},d={type:"chunkString",contentType:"string",start:Object.assign({},u.start),end:Object.assign({},u.end)},m=[t[r+1],t[r+2],["enter",i,l],t[r+3],t[r+4],["enter",c,l],["exit",c,l],["enter",u,l],["enter",d,l],["exit",d,l],["exit",u,l],t[t.length-2],t[t.length-1],["exit",i,l]];return t.splice(r,t.length-r+1,...m),t}function rj(t,l,r){const i=this,c=i.parser.gfmFootnotes||(i.parser.gfmFootnotes=[]);let u=0,d;return m;function m(y){return t.enter("gfmFootnoteCall"),t.enter("gfmFootnoteCallLabelMarker"),t.consume(y),t.exit("gfmFootnoteCallLabelMarker"),x}function x(y){return y!==94?r(y):(t.enter("gfmFootnoteCallMarker"),t.consume(y),t.exit("gfmFootnoteCallMarker"),t.enter("gfmFootnoteCallString"),t.enter("chunkString").contentType="string",f)}function f(y){if(u>999||y===93&&!d||y===null||y===91||Rt(y))return r(y);if(y===93){t.exit("chunkString");const b=t.exit("gfmFootnoteCallString");return c.includes(gl(i.sliceSerialize(b)))?(t.enter("gfmFootnoteCallLabelMarker"),t.consume(y),t.exit("gfmFootnoteCallLabelMarker"),t.exit("gfmFootnoteCall"),l):r(y)}return Rt(y)||(d=!0),u++,t.consume(y),y===92?g:f}function g(y){return y===91||y===92||y===93?(t.consume(y),u++,f):f(y)}}function aj(t,l,r){const i=this,c=i.parser.gfmFootnotes||(i.parser.gfmFootnotes=[]);let u,d=0,m;return x;function x(S){return t.enter("gfmFootnoteDefinition")._container=!0,t.enter("gfmFootnoteDefinitionLabel"),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(S),t.exit("gfmFootnoteDefinitionLabelMarker"),f}function f(S){return S===94?(t.enter("gfmFootnoteDefinitionMarker"),t.consume(S),t.exit("gfmFootnoteDefinitionMarker"),t.enter("gfmFootnoteDefinitionLabelString"),t.enter("chunkString").contentType="string",g):r(S)}function g(S){if(d>999||S===93&&!m||S===null||S===91||Rt(S))return r(S);if(S===93){t.exit("chunkString");const j=t.exit("gfmFootnoteDefinitionLabelString");return u=gl(i.sliceSerialize(j)),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(S),t.exit("gfmFootnoteDefinitionLabelMarker"),t.exit("gfmFootnoteDefinitionLabel"),b}return Rt(S)||(m=!0),d++,t.consume(S),S===92?y:g}function y(S){return S===91||S===92||S===93?(t.consume(S),d++,g):g(S)}function b(S){return S===58?(t.enter("definitionMarker"),t.consume(S),t.exit("definitionMarker"),c.includes(u)||c.push(u),pt(t,v,"gfmFootnoteDefinitionWhitespace")):r(S)}function v(S){return l(S)}}function ij(t,l,r){return t.check(Hs,l,t.attempt(ej,l,r))}function sj(t){t.exit("gfmFootnoteDefinition")}function oj(t,l,r){const i=this;return pt(t,c,"gfmFootnoteDefinitionIndent",5);function c(u){const d=i.events[i.events.length-1];return d&&d[1].type==="gfmFootnoteDefinitionIndent"&&d[2].sliceSerialize(d[1],!0).length===4?l(u):r(u)}}function cj(t){let r=(t||{}).singleTilde;const i={name:"strikethrough",tokenize:u,resolveAll:c};return r==null&&(r=!0),{text:{126:i},insideSpan:{null:[i]},attentionMarkers:{null:[126]}};function c(d,m){let x=-1;for(;++x<d.length;)if(d[x][0]==="enter"&&d[x][1].type==="strikethroughSequenceTemporary"&&d[x][1]._close){let f=x;for(;f--;)if(d[f][0]==="exit"&&d[f][1].type==="strikethroughSequenceTemporary"&&d[f][1]._open&&d[x][1].end.offset-d[x][1].start.offset===d[f][1].end.offset-d[f][1].start.offset){d[x][1].type="strikethroughSequence",d[f][1].type="strikethroughSequence";const g={type:"strikethrough",start:Object.assign({},d[f][1].start),end:Object.assign({},d[x][1].end)},y={type:"strikethroughText",start:Object.assign({},d[f][1].end),end:Object.assign({},d[x][1].start)},b=[["enter",g,m],["enter",d[f][1],m],["exit",d[f][1],m],["enter",y,m]],v=m.parser.constructs.insideSpan.null;v&&el(b,b.length,0,$c(v,d.slice(f+1,x),m)),el(b,b.length,0,[["exit",y,m],["enter",d[x][1],m],["exit",d[x][1],m],["exit",g,m]]),el(d,f-1,x-f+3,b),x=f+b.length-2;break}}for(x=-1;++x<d.length;)d[x][1].type==="strikethroughSequenceTemporary"&&(d[x][1].type="data");return d}function u(d,m,x){const f=this.previous,g=this.events;let y=0;return b;function b(S){return f===126&&g[g.length-1][1].type!=="characterEscape"?x(S):(d.enter("strikethroughSequenceTemporary"),v(S))}function v(S){const j=pi(f);if(S===126)return y>1?x(S):(d.consume(S),y++,v);if(y<2&&!r)return x(S);const E=d.exit("strikethroughSequenceTemporary"),C=pi(S);return E._open=!C||C===2&&!!j,E._close=!j||j===2&&!!C,m(S)}}}class uj{constructor(){this.map=[]}add(l,r,i){dj(this,l,r,i)}consume(l){if(this.map.sort(function(u,d){return u[0]-d[0]}),this.map.length===0)return;let r=this.map.length;const i=[];for(;r>0;)r-=1,i.push(l.slice(this.map[r][0]+this.map[r][1]),this.map[r][2]),l.length=this.map[r][0];i.push(l.slice()),l.length=0;let c=i.pop();for(;c;){for(const u of c)l.push(u);c=i.pop()}this.map.length=0}}function dj(t,l,r,i){let c=0;if(!(r===0&&i.length===0)){for(;c<t.map.length;){if(t.map[c][0]===l){t.map[c][1]+=r,t.map[c][2].push(...i);return}c+=1}t.map.push([l,r,i])}}function fj(t,l){let r=!1;const i=[];for(;l<t.length;){const c=t[l];if(r){if(c[0]==="enter")c[1].type==="tableContent"&&i.push(t[l+1][1].type==="tableDelimiterMarker"?"left":"none");else if(c[1].type==="tableContent"){if(t[l-1][1].type==="tableDelimiterMarker"){const u=i.length-1;i[u]=i[u]==="left"?"center":"right"}}else if(c[1].type==="tableDelimiterRow")break}else c[0]==="enter"&&c[1].type==="tableDelimiterRow"&&(r=!0);l+=1}return i}function hj(){return{flow:{null:{name:"table",tokenize:mj,resolveAll:xj}}}}function mj(t,l,r){const i=this;let c=0,u=0,d;return m;function m(T){let U=i.events.length-1;for(;U>-1;){const ne=i.events[U][1].type;if(ne==="lineEnding"||ne==="linePrefix")U--;else break}const O=U>-1?i.events[U][1].type:null,J=O==="tableHead"||O==="tableRow"?_:x;return J===_&&i.parser.lazy[i.now().line]?r(T):J(T)}function x(T){return t.enter("tableHead"),t.enter("tableRow"),f(T)}function f(T){return T===124||(d=!0,u+=1),g(T)}function g(T){return T===null?r(T):qe(T)?u>1?(u=0,i.interrupt=!0,t.exit("tableRow"),t.enter("lineEnding"),t.consume(T),t.exit("lineEnding"),v):r(T):ut(T)?pt(t,g,"whitespace")(T):(u+=1,d&&(d=!1,c+=1),T===124?(t.enter("tableCellDivider"),t.consume(T),t.exit("tableCellDivider"),d=!0,g):(t.enter("data"),y(T)))}function y(T){return T===null||T===124||Rt(T)?(t.exit("data"),g(T)):(t.consume(T),T===92?b:y)}function b(T){return T===92||T===124?(t.consume(T),y):y(T)}function v(T){return i.interrupt=!1,i.parser.lazy[i.now().line]?r(T):(t.enter("tableDelimiterRow"),d=!1,ut(T)?pt(t,S,"linePrefix",i.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(T):S(T))}function S(T){return T===45||T===58?E(T):T===124?(d=!0,t.enter("tableCellDivider"),t.consume(T),t.exit("tableCellDivider"),j):$(T)}function j(T){return ut(T)?pt(t,E,"whitespace")(T):E(T)}function E(T){return T===58?(u+=1,d=!0,t.enter("tableDelimiterMarker"),t.consume(T),t.exit("tableDelimiterMarker"),C):T===45?(u+=1,C(T)):T===null||qe(T)?B(T):$(T)}function C(T){return T===45?(t.enter("tableDelimiterFiller"),A(T)):$(T)}function A(T){return T===45?(t.consume(T),A):T===58?(d=!0,t.exit("tableDelimiterFiller"),t.enter("tableDelimiterMarker"),t.consume(T),t.exit("tableDelimiterMarker"),M):(t.exit("tableDelimiterFiller"),M(T))}function M(T){return ut(T)?pt(t,B,"whitespace")(T):B(T)}function B(T){return T===124?S(T):T===null||qe(T)?!d||c!==u?$(T):(t.exit("tableDelimiterRow"),t.exit("tableHead"),l(T)):$(T)}function $(T){return r(T)}function _(T){return t.enter("tableRow"),V(T)}function V(T){return T===124?(t.enter("tableCellDivider"),t.consume(T),t.exit("tableCellDivider"),V):T===null||qe(T)?(t.exit("tableRow"),l(T)):ut(T)?pt(t,V,"whitespace")(T):(t.enter("data"),G(T))}function G(T){return T===null||T===124||Rt(T)?(t.exit("data"),V(T)):(t.consume(T),T===92?Y:G)}function Y(T){return T===92||T===124?(t.consume(T),G):G(T)}}function xj(t,l){let r=-1,i=!0,c=0,u=[0,0,0,0],d=[0,0,0,0],m=!1,x=0,f,g,y;const b=new uj;for(;++r<t.length;){const v=t[r],S=v[1];v[0]==="enter"?S.type==="tableHead"?(m=!1,x!==0&&(i0(b,l,x,f,g),g=void 0,x=0),f={type:"table",start:Object.assign({},S.start),end:Object.assign({},S.end)},b.add(r,0,[["enter",f,l]])):S.type==="tableRow"||S.type==="tableDelimiterRow"?(i=!0,y=void 0,u=[0,0,0,0],d=[0,r+1,0,0],m&&(m=!1,g={type:"tableBody",start:Object.assign({},S.start),end:Object.assign({},S.end)},b.add(r,0,[["enter",g,l]])),c=S.type==="tableDelimiterRow"?2:g?3:1):c&&(S.type==="data"||S.type==="tableDelimiterMarker"||S.type==="tableDelimiterFiller")?(i=!1,d[2]===0&&(u[1]!==0&&(d[0]=d[1],y=oc(b,l,u,c,void 0,y),u=[0,0,0,0]),d[2]=r)):S.type==="tableCellDivider"&&(i?i=!1:(u[1]!==0&&(d[0]=d[1],y=oc(b,l,u,c,void 0,y)),u=d,d=[u[1],r,0,0])):S.type==="tableHead"?(m=!0,x=r):S.type==="tableRow"||S.type==="tableDelimiterRow"?(x=r,u[1]!==0?(d[0]=d[1],y=oc(b,l,u,c,r,y)):d[1]!==0&&(y=oc(b,l,d,c,r,y)),c=0):c&&(S.type==="data"||S.type==="tableDelimiterMarker"||S.type==="tableDelimiterFiller")&&(d[3]=r)}for(x!==0&&i0(b,l,x,f,g),b.consume(l.events),r=-1;++r<l.events.length;){const v=l.events[r];v[0]==="enter"&&v[1].type==="table"&&(v[1]._align=fj(l.events,r))}return t}function oc(t,l,r,i,c,u){const d=i===1?"tableHeader":i===2?"tableDelimiter":"tableData",m="tableContent";r[0]!==0&&(u.end=Object.assign({},fi(l.events,r[0])),t.add(r[0],0,[["exit",u,l]]));const x=fi(l.events,r[1]);if(u={type:d,start:Object.assign({},x),end:Object.assign({},x)},t.add(r[1],0,[["enter",u,l]]),r[2]!==0){const f=fi(l.events,r[2]),g=fi(l.events,r[3]),y={type:m,start:Object.assign({},f),end:Object.assign({},g)};if(t.add(r[2],0,[["enter",y,l]]),i!==2){const b=l.events[r[2]],v=l.events[r[3]];if(b[1].end=Object.assign({},v[1].end),b[1].type="chunkText",b[1].contentType="text",r[3]>r[2]+1){const S=r[2]+1,j=r[3]-r[2]-1;t.add(S,j,[])}}t.add(r[3]+1,0,[["exit",y,l]])}return c!==void 0&&(u.end=Object.assign({},fi(l.events,c)),t.add(c,0,[["exit",u,l]]),u=void 0),u}function i0(t,l,r,i,c){const u=[],d=fi(l.events,r);c&&(c.end=Object.assign({},d),u.push(["exit",c,l])),i.end=Object.assign({},d),u.push(["exit",i,l]),t.add(r+1,0,u)}function fi(t,l){const r=t[l],i=r[0]==="enter"?"start":"end";return r[1][i]}const pj={name:"tasklistCheck",tokenize:gj};function yj(){return{text:{91:pj}}}function gj(t,l,r){const i=this;return c;function c(x){return i.previous!==null||!i._gfmTasklistFirstContentOfListItem?r(x):(t.enter("taskListCheck"),t.enter("taskListCheckMarker"),t.consume(x),t.exit("taskListCheckMarker"),u)}function u(x){return Rt(x)?(t.enter("taskListCheckValueUnchecked"),t.consume(x),t.exit("taskListCheckValueUnchecked"),d):x===88||x===120?(t.enter("taskListCheckValueChecked"),t.consume(x),t.exit("taskListCheckValueChecked"),d):r(x)}function d(x){return x===93?(t.enter("taskListCheckMarker"),t.consume(x),t.exit("taskListCheckMarker"),t.exit("taskListCheck"),m):r(x)}function m(x){return qe(x)?l(x):ut(x)?t.check({tokenize:bj},l,r)(x):r(x)}}function bj(t,l,r){return pt(t,i,"whitespace");function i(c){return c===null?r(c):l(c)}}function vj(t){return cy([X4(),tj(),cj(t),hj(),yj()])}const wj={};function jh(t){const l=this,r=t||wj,i=l.data(),c=i.micromarkExtensions||(i.micromarkExtensions=[]),u=i.fromMarkdownExtensions||(i.fromMarkdownExtensions=[]),d=i.toMarkdownExtensions||(i.toMarkdownExtensions=[]);c.push(vj(r)),u.push(U4()),d.push(I4(r))}function Is({content:t,className:l=""}){return s.jsx("div",{className:`office-markdown ${l}`,children:s.jsx(bh,{remarkPlugins:[jh],components:{code:kj,table:({children:r})=>s.jsx("div",{className:"overflow-x-auto my-2",children:s.jsx("table",{className:"office-table",children:r})})},children:t})})}function kj({className:t,children:l,...r}){const i=/language-(\w+)/.exec(t??"");return i||typeof l=="string"&&l.includes(`
79
79
  `)?s.jsx(jj,{language:i==null?void 0:i[1],children:l}):s.jsx("code",{className:"bg-gray-100 text-gray-700 px-1 py-0.5 rounded text-[0.9em] font-mono",...r,children:l})}function jj({children:t,language:l}){const[r,i]=k.useState(!1),c=String(t).replace(/\n$/,""),u=()=>{navigator.clipboard.writeText(c),i(!0),setTimeout(()=>i(!1),1500)};return s.jsxs("div",{className:"office-code-block group relative my-2",children:[l&&s.jsx("div",{className:"text-[10px] text-gray-400 px-3 pt-1.5",children:l}),s.jsx("button",{onClick:u,className:"absolute top-1.5 right-2 text-[10px] text-gray-400 hover:text-gray-600 opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",children:r?"Copied!":"Copy"}),s.jsx("pre",{className:"overflow-x-auto p-3 text-xs leading-relaxed",children:s.jsx("code",{children:c})})]})}const s0={$skin:"skinColor",$hair:"hairColor",$shirt:"shirtColor",$pants:"pantsColor",$shoes:"shoeColor"},Sj=/^(darken|lighten)\((\$\w+),\s*(\d+)\)$/;function Cj(t,l){const r=parseInt(t.replace("#",""),16),i=Math.max(0,(r>>16&255)-l),c=Math.max(0,(r>>8&255)-l),u=Math.max(0,(r&255)-l);return`#${(i<<16|c<<8|u).toString(16).padStart(6,"0")}`}function Ej(t,l){const r=parseInt(t.replace("#",""),16),i=Math.min(255,(r>>16&255)+l),c=Math.min(255,(r>>8&255)+l),u=Math.min(255,(r&255)+l);return`#${(i<<16|c<<8|u).toString(16).padStart(6,"0")}`}function Py(t,l){const r=s0[t];if(r&&l)return l[r];const i=Sj.exec(t);if(i){const[,c,u,d]=i,m=s0[u],x=m&&l?l[m]:u,f=parseInt(d,10);return c==="darken"?Cj(x,f):Ej(x,f)}return t}function o0(t,l=12){return t.map(r=>({...r,x:l-r.x-r.w}))}function Nj(t,l){return l==="down"?t.down:l==="up"&&t.up?t.up:l==="left"&&t.left?t.left:l==="right"&&t.right?t.right:l==="right"&&t.left?{name:t.left.name,pixels:o0(t.left.pixels)}:l==="left"&&t.right?{name:t.right.name,pixels:o0(t.right.pixels)}:t.down}function Aj(t,l){return Kf(t,"hair",l,1)}function Kf(t,l,r,i){const c=t.layers.findIndex(d=>d.name===l),u=[...t.layers];if(c>=0)u[c]={...r,name:l};else{const d=i??u.length;u.splice(d,0,{...r,name:l})}return{...t,layers:u}}const Sh=new Map,Ch=new Map;function eg(t,l){Sh.set(t,l)}function Yc(t,l){Ch.set(t,l)}function Wf(t){return Sh.get(t)}function Dj(t){return Ch.get(t)}function jN(){return Array.from(Sh.keys())}function SN(){return Array.from(Ch.keys())}function Tj(t,l,r,i,c=2){t.clearRect(0,0,l.width*c,l.height*c);for(const u of l.layers)tg(t,u.pixels,c,r,i)}function Qf(t,l,r,i,c){for(const u of l){const d=Py(u.c,c);u.a!==void 0&&u.a!==1&&(t.globalAlpha=u.a),t.fillStyle=d,t.fillRect(r+u.x,i+u.y,u.w,u.h),u.a!==void 0&&u.a!==1&&(t.globalAlpha=1)}}function zj(t,l){const r=l.scale;t.clearRect(0,0,l.canvasWidth,l.canvasHeight),tg(t,l.pixels,r,0)}function tg(t,l,r,i,c){for(const u of l){const d=Py(u.c,c);u.a!==void 0&&u.a!==1&&(t.globalAlpha=u.a),t.fillStyle=d,t.fillRect(u.x*r,(u.y+i)*r,u.w*r,u.h*r),u.a!==void 0&&u.a!==1&&(t.globalAlpha=1)}}const Mc=new Map;function Xr(t,l,r){if("down"in r&&!("pixels"in r)){const c=r;Mc.set(t,{id:t,name:l,layer:{...c.down,name:"hair"},directions:{down:{...c.down,name:"hair"},up:c.up?{...c.up,name:"hair"}:void 0,left:c.left?{...c.left,name:"hair"}:void 0,right:c.right?{...c.right,name:"hair"}:void 0}})}else{const c=r;Mc.set(t,{id:t,name:l,layer:{...c,name:"hair"}})}}function Mj(t){return Mc.get(t)}function ng(){return Array.from(Mc.values())}Xr("short","Short",{down:{name:"hair",pixels:[{x:1,y:0,w:10,h:2,c:"$hair"},{x:0,y:1,w:2,h:2,c:"$hair"},{x:10,y:1,w:2,h:2,c:"$hair"},{x:2,y:0,w:8,h:1,c:"lighten($hair, 25)",a:.3}]},up:{name:"hair",pixels:[{x:1,y:0,w:10,h:3,c:"$hair"},{x:0,y:1,w:2,h:2,c:"$hair"},{x:10,y:1,w:2,h:2,c:"$hair"}]},left:{name:"hair",pixels:[{x:1,y:0,w:9,h:2,c:"$hair"},{x:0,y:1,w:2,h:2,c:"$hair"},{x:2,y:0,w:6,h:1,c:"lighten($hair, 25)",a:.3}]}});Xr("messy","Messy",{down:{name:"hair",pixels:[{x:1,y:0,w:10,h:3,c:"$hair"},{x:0,y:1,w:2,h:3,c:"$hair"},{x:10,y:0,w:2,h:4,c:"$hair"},{x:3,y:-1,w:3,h:2,c:"$hair"},{x:7,y:-1,w:2,h:2,c:"lighten($hair, 20)"},{x:2,y:0,w:4,h:1,c:"lighten($hair, 30)",a:.3}]},up:{name:"hair",pixels:[{x:1,y:0,w:10,h:4,c:"$hair"},{x:0,y:1,w:2,h:3,c:"$hair"},{x:10,y:0,w:2,h:4,c:"$hair"},{x:3,y:-1,w:3,h:2,c:"$hair"},{x:7,y:-1,w:2,h:2,c:"$hair"}]},left:{name:"hair",pixels:[{x:1,y:0,w:9,h:3,c:"$hair"},{x:0,y:1,w:2,h:3,c:"$hair"},{x:3,y:-1,w:3,h:2,c:"$hair"},{x:2,y:0,w:4,h:1,c:"lighten($hair, 30)",a:.3}]}});Xr("bun","Bun",{down:{name:"hair",pixels:[{x:1,y:0,w:10,h:2,c:"$hair"},{x:0,y:1,w:2,h:2,c:"$hair"},{x:10,y:1,w:2,h:2,c:"$hair"},{x:4,y:-2,w:4,h:3,c:"$hair"},{x:5,y:-2,w:2,h:1,c:"lighten($hair, 30)",a:.4}]},up:{name:"hair",pixels:[{x:1,y:0,w:10,h:3,c:"$hair"},{x:0,y:1,w:2,h:2,c:"$hair"},{x:10,y:1,w:2,h:2,c:"$hair"},{x:4,y:-2,w:4,h:3,c:"$hair"},{x:5,y:-2,w:2,h:1,c:"lighten($hair, 30)",a:.4}]},left:{name:"hair",pixels:[{x:1,y:0,w:9,h:2,c:"$hair"},{x:0,y:1,w:2,h:2,c:"$hair"},{x:4,y:-2,w:4,h:3,c:"$hair"},{x:5,y:-2,w:2,h:1,c:"lighten($hair, 30)",a:.4}]}});Xr("long","Long",{down:{name:"hair",pixels:[{x:0,y:0,w:12,h:3,c:"$hair"},{x:-1,y:1,w:2,h:7,c:"$hair"},{x:11,y:1,w:2,h:7,c:"$hair"},{x:-1,y:6,w:2,h:3,c:"darken($hair, 15)",a:.5},{x:11,y:6,w:2,h:3,c:"darken($hair, 15)",a:.5},{x:2,y:0,w:8,h:1,c:"lighten($hair, 25)",a:.3}]},up:{name:"hair",pixels:[{x:0,y:0,w:12,h:3,c:"$hair"},{x:-1,y:1,w:2,h:7,c:"$hair"},{x:11,y:1,w:2,h:7,c:"$hair"},{x:1,y:2,w:10,h:6,c:"$hair"},{x:2,y:6,w:8,h:2,c:"darken($hair, 10)",a:.3}]},left:{name:"hair",pixels:[{x:0,y:0,w:10,h:3,c:"$hair"},{x:-1,y:1,w:2,h:7,c:"$hair"},{x:-1,y:6,w:2,h:3,c:"darken($hair, 15)",a:.5},{x:2,y:0,w:6,h:1,c:"lighten($hair, 25)",a:.3}]}});Xr("mohawk","Mohawk",{down:{name:"hair",pixels:[{x:4,y:-2,w:4,h:4,c:"$hair"},{x:5,y:-3,w:2,h:2,c:"lighten($hair, 20)"},{x:1,y:1,w:3,h:2,c:"$hair"},{x:8,y:1,w:3,h:2,c:"$hair"}]},up:{name:"hair",pixels:[{x:4,y:-2,w:4,h:4,c:"$hair"},{x:5,y:-3,w:2,h:2,c:"lighten($hair, 20)"},{x:1,y:1,w:3,h:2,c:"$hair"},{x:8,y:1,w:3,h:2,c:"$hair"}]},left:{name:"hair",pixels:[{x:4,y:-2,w:3,h:4,c:"$hair"},{x:5,y:-3,w:2,h:2,c:"lighten($hair, 20)"},{x:1,y:1,w:3,h:2,c:"$hair"}]}});Xr("slicked","Slicked Back",{down:{name:"hair",pixels:[{x:1,y:0,w:10,h:2,c:"$hair"},{x:0,y:1,w:2,h:2,c:"$hair"},{x:10,y:1,w:2,h:2,c:"$hair"},{x:2,y:0,w:8,h:1,c:"lighten($hair, 15)",a:.4},{x:3,y:1,w:6,h:1,c:"lighten($hair, 10)",a:.2}]},up:{name:"hair",pixels:[{x:1,y:0,w:10,h:3,c:"$hair"},{x:0,y:1,w:2,h:2,c:"$hair"},{x:10,y:1,w:2,h:2,c:"$hair"},{x:2,y:0,w:8,h:1,c:"lighten($hair, 15)",a:.4}]},left:{name:"hair",pixels:[{x:1,y:0,w:9,h:2,c:"$hair"},{x:0,y:1,w:2,h:2,c:"$hair"},{x:2,y:0,w:6,h:1,c:"lighten($hair, 15)",a:.4}]}});Xr("bob","Bob Cut",{down:{name:"hair",pixels:[{x:0,y:0,w:12,h:3,c:"$hair"},{x:-1,y:1,w:2,h:5,c:"$hair"},{x:11,y:1,w:2,h:5,c:"$hair"},{x:-1,y:5,w:2,h:1,c:"darken($hair, 15)",a:.4},{x:11,y:5,w:2,h:1,c:"darken($hair, 15)",a:.4},{x:2,y:0,w:8,h:1,c:"lighten($hair, 25)",a:.3}]},up:{name:"hair",pixels:[{x:0,y:0,w:12,h:3,c:"$hair"},{x:-1,y:1,w:2,h:5,c:"$hair"},{x:11,y:1,w:2,h:5,c:"$hair"},{x:1,y:2,w:10,h:4,c:"$hair"},{x:2,y:5,w:8,h:1,c:"darken($hair, 10)",a:.3}]},left:{name:"hair",pixels:[{x:0,y:0,w:10,h:3,c:"$hair"},{x:-1,y:1,w:2,h:5,c:"$hair"},{x:-1,y:5,w:2,h:1,c:"darken($hair, 15)",a:.4},{x:2,y:0,w:6,h:1,c:"lighten($hair, 25)",a:.3}]}});Xr("curly","Curly",{down:{name:"hair",pixels:[{x:0,y:0,w:12,h:4,c:"$hair"},{x:-1,y:1,w:2,h:5,c:"$hair"},{x:11,y:1,w:2,h:5,c:"$hair"},{x:2,y:0,w:2,h:1,c:"lighten($hair, 25)",a:.4},{x:6,y:0,w:2,h:1,c:"lighten($hair, 25)",a:.4},{x:4,y:2,w:2,h:1,c:"lighten($hair, 15)",a:.3},{x:8,y:2,w:2,h:1,c:"lighten($hair, 15)",a:.3}]},up:{name:"hair",pixels:[{x:0,y:0,w:12,h:4,c:"$hair"},{x:-1,y:1,w:2,h:5,c:"$hair"},{x:11,y:1,w:2,h:5,c:"$hair"},{x:1,y:2,w:10,h:4,c:"$hair"},{x:3,y:1,w:2,h:1,c:"lighten($hair, 15)",a:.3},{x:7,y:1,w:2,h:1,c:"lighten($hair, 15)",a:.3}]},left:{name:"hair",pixels:[{x:0,y:0,w:10,h:4,c:"$hair"},{x:-1,y:1,w:2,h:5,c:"$hair"},{x:2,y:0,w:2,h:1,c:"lighten($hair, 25)",a:.4},{x:5,y:0,w:2,h:1,c:"lighten($hair, 25)",a:.4},{x:3,y:2,w:2,h:1,c:"lighten($hair, 15)",a:.3}]}});const Fc=new Map;function Fl(t,l,r){if("down"in r&&!("pixels"in r)){const c=r;Fc.set(t,{id:t,name:l,layer:{...c.down,name:"torso"},directions:{down:{...c.down,name:"torso"},up:c.up?{...c.up,name:"torso"}:void 0,left:c.left?{...c.left,name:"torso"}:void 0,right:c.right?{...c.right,name:"torso"}:void 0}})}else{const c=r;Fc.set(t,{id:t,name:l,layer:{...c,name:"torso"}})}}function Fj(t){return Fc.get(t)}function lg(){return Array.from(Fc.values())}Fl("tshirt","T-Shirt",{down:{name:"torso",pixels:[{x:1,y:10,w:10,h:6,c:"$shirt"},{x:2,y:10,w:8,h:1,c:"lighten($shirt, 18)",a:.3},{x:1,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:10,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:-1,y:11,w:2,h:5,c:"$shirt"},{x:11,y:11,w:2,h:5,c:"$shirt"},{x:-1,y:15,w:2,h:1,c:"$skin"},{x:11,y:15,w:2,h:1,c:"$skin"}]},up:{name:"torso",pixels:[{x:1,y:10,w:10,h:6,c:"$shirt"},{x:1,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:10,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:5,y:10,w:2,h:3,c:"darken($shirt, 10)",a:.15},{x:-1,y:11,w:2,h:5,c:"$shirt"},{x:11,y:11,w:2,h:5,c:"$shirt"},{x:-1,y:15,w:2,h:1,c:"$skin"},{x:11,y:15,w:2,h:1,c:"$skin"}]},left:{name:"torso",pixels:[{x:1,y:10,w:9,h:6,c:"$shirt"},{x:2,y:10,w:7,h:1,c:"lighten($shirt, 18)",a:.3},{x:1,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:-1,y:11,w:3,h:5,c:"$shirt"},{x:-1,y:15,w:3,h:1,c:"$skin"}]}});Fl("suit","Suit",{down:{name:"torso",pixels:[{x:1,y:10,w:10,h:6,c:"$shirt"},{x:2,y:10,w:8,h:1,c:"lighten($shirt, 12)",a:.3},{x:1,y:10,w:1,h:5,c:"darken($shirt, 30)",a:.3},{x:10,y:10,w:1,h:5,c:"darken($shirt, 30)",a:.3},{x:2,y:10,w:3,h:3,c:"darken($shirt, 20)",a:.3},{x:7,y:10,w:3,h:3,c:"darken($shirt, 20)",a:.3},{x:5,y:10,w:2,h:5,c:"#E8E8E8",a:.5},{x:-1,y:11,w:2,h:5,c:"$shirt"},{x:11,y:11,w:2,h:5,c:"$shirt"},{x:-1,y:11,w:2,h:1,c:"darken($shirt, 20)",a:.2},{x:11,y:11,w:2,h:1,c:"darken($shirt, 20)",a:.2},{x:-1,y:15,w:2,h:1,c:"$skin"},{x:11,y:15,w:2,h:1,c:"$skin"}]},up:{name:"torso",pixels:[{x:1,y:10,w:10,h:6,c:"$shirt"},{x:1,y:10,w:1,h:5,c:"darken($shirt, 30)",a:.3},{x:10,y:10,w:1,h:5,c:"darken($shirt, 30)",a:.3},{x:5,y:12,w:2,h:4,c:"darken($shirt, 10)",a:.15},{x:-1,y:11,w:2,h:5,c:"$shirt"},{x:11,y:11,w:2,h:5,c:"$shirt"},{x:-1,y:15,w:2,h:1,c:"$skin"},{x:11,y:15,w:2,h:1,c:"$skin"}]},left:{name:"torso",pixels:[{x:1,y:10,w:9,h:6,c:"$shirt"},{x:1,y:10,w:1,h:5,c:"darken($shirt, 30)",a:.3},{x:2,y:10,w:3,h:3,c:"darken($shirt, 20)",a:.3},{x:-1,y:11,w:3,h:5,c:"$shirt"},{x:-1,y:11,w:3,h:1,c:"darken($shirt, 20)",a:.2},{x:-1,y:15,w:3,h:1,c:"$skin"}]}});Fl("hoodie","Hoodie",{down:{name:"torso",pixels:[{x:0,y:10,w:12,h:6,c:"$shirt"},{x:1,y:10,w:10,h:1,c:"lighten($shirt, 15)",a:.25},{x:0,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.3},{x:11,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.3},{x:2,y:8,w:8,h:2,c:"$shirt",a:.4},{x:3,y:13,w:6,h:2,c:"darken($shirt, 15)",a:.2},{x:5,y:10,w:1,h:2,c:"#DDD",a:.3},{x:6,y:10,w:1,h:2,c:"#DDD",a:.3},{x:-1,y:11,w:2,h:5,c:"$shirt"},{x:11,y:11,w:2,h:5,c:"$shirt"},{x:-1,y:15,w:2,h:1,c:"$skin"},{x:11,y:15,w:2,h:1,c:"$skin"}]},up:{name:"torso",pixels:[{x:0,y:10,w:12,h:6,c:"$shirt"},{x:0,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.3},{x:11,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.3},{x:2,y:7,w:8,h:3,c:"$shirt",a:.5},{x:3,y:7,w:6,h:1,c:"darken($shirt, 10)",a:.3},{x:-1,y:11,w:2,h:5,c:"$shirt"},{x:11,y:11,w:2,h:5,c:"$shirt"},{x:-1,y:15,w:2,h:1,c:"$skin"},{x:11,y:15,w:2,h:1,c:"$skin"}]},left:{name:"torso",pixels:[{x:0,y:10,w:10,h:6,c:"$shirt"},{x:1,y:10,w:8,h:1,c:"lighten($shirt, 15)",a:.25},{x:0,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.3},{x:2,y:8,w:6,h:2,c:"$shirt",a:.4},{x:-1,y:11,w:3,h:5,c:"$shirt"},{x:-1,y:15,w:3,h:1,c:"$skin"}]}});Fl("vest","Vest",{down:{name:"torso",pixels:[{x:1,y:10,w:10,h:6,c:"$shirt"},{x:2,y:10,w:8,h:1,c:"lighten($shirt, 18)",a:.3},{x:1,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:10,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:5,y:10,w:2,h:2,c:"$skin",a:.6},{x:-1,y:11,w:2,h:5,c:"$skin"},{x:11,y:11,w:2,h:5,c:"$skin"},{x:-1,y:15,w:2,h:1,c:"darken($skin, 10)"},{x:11,y:15,w:2,h:1,c:"darken($skin, 10)"}]},up:{name:"torso",pixels:[{x:1,y:10,w:10,h:6,c:"$shirt"},{x:1,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:10,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:-1,y:11,w:2,h:5,c:"$skin"},{x:11,y:11,w:2,h:5,c:"$skin"},{x:-1,y:15,w:2,h:1,c:"darken($skin, 10)"},{x:11,y:15,w:2,h:1,c:"darken($skin, 10)"}]},left:{name:"torso",pixels:[{x:1,y:10,w:9,h:6,c:"$shirt"},{x:1,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:-1,y:11,w:3,h:5,c:"$skin"},{x:-1,y:15,w:3,h:1,c:"darken($skin, 10)"}]}});Fl("tank","Tank Top",{down:{name:"torso",pixels:[{x:2,y:10,w:8,h:6,c:"$shirt"},{x:3,y:10,w:6,h:1,c:"lighten($shirt, 18)",a:.3},{x:2,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:9,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:0,y:10,w:2,h:2,c:"$skin"},{x:10,y:10,w:2,h:2,c:"$skin"},{x:-1,y:11,w:2,h:5,c:"$skin"},{x:11,y:11,w:2,h:5,c:"$skin"},{x:-1,y:15,w:2,h:1,c:"darken($skin, 10)"},{x:11,y:15,w:2,h:1,c:"darken($skin, 10)"}]},up:{name:"torso",pixels:[{x:2,y:10,w:8,h:6,c:"$shirt"},{x:2,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:9,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:0,y:10,w:2,h:2,c:"$skin"},{x:10,y:10,w:2,h:2,c:"$skin"},{x:-1,y:11,w:2,h:5,c:"$skin"},{x:11,y:11,w:2,h:5,c:"$skin"},{x:-1,y:15,w:2,h:1,c:"darken($skin, 10)"},{x:11,y:15,w:2,h:1,c:"darken($skin, 10)"}]},left:{name:"torso",pixels:[{x:2,y:10,w:7,h:6,c:"$shirt"},{x:2,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:0,y:10,w:2,h:2,c:"$skin"},{x:-1,y:11,w:3,h:5,c:"$skin"},{x:-1,y:15,w:3,h:1,c:"darken($skin, 10)"}]}});Fl("polo","Polo",{down:{name:"torso",pixels:[{x:1,y:10,w:10,h:6,c:"$shirt"},{x:2,y:10,w:8,h:1,c:"lighten($shirt, 18)",a:.3},{x:1,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:10,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:3,y:9,w:6,h:2,c:"lighten($shirt, 25)",a:.5},{x:5,y:9,w:2,h:1,c:"$skin",a:.4},{x:5,y:10,w:2,h:3,c:"darken($shirt, 15)",a:.15},{x:-1,y:11,w:2,h:5,c:"$shirt"},{x:11,y:11,w:2,h:5,c:"$shirt"},{x:-1,y:15,w:2,h:1,c:"$skin"},{x:11,y:15,w:2,h:1,c:"$skin"}]},up:{name:"torso",pixels:[{x:1,y:10,w:10,h:6,c:"$shirt"},{x:1,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:10,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:3,y:9,w:6,h:1,c:"lighten($shirt, 25)",a:.5},{x:-1,y:11,w:2,h:5,c:"$shirt"},{x:11,y:11,w:2,h:5,c:"$shirt"},{x:-1,y:15,w:2,h:1,c:"$skin"},{x:11,y:15,w:2,h:1,c:"$skin"}]},left:{name:"torso",pixels:[{x:1,y:10,w:9,h:6,c:"$shirt"},{x:1,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:3,y:9,w:4,h:2,c:"lighten($shirt, 25)",a:.5},{x:-1,y:11,w:3,h:5,c:"$shirt"},{x:-1,y:15,w:3,h:1,c:"$skin"}]}});Fl("labcoat","Lab Coat",{down:{name:"torso",pixels:[{x:4,y:10,w:4,h:5,c:"$shirt"},{x:0,y:10,w:4,h:7,c:"#F0F0F0"},{x:8,y:10,w:4,h:7,c:"#F0F0F0"},{x:1,y:10,w:10,h:1,c:"#FAFAFA"},{x:0,y:10,w:1,h:7,c:"#DDD",a:.5},{x:11,y:10,w:1,h:7,c:"#DDD",a:.5},{x:1,y:13,w:2,h:2,c:"#E0E0E0",a:.4},{x:9,y:13,w:2,h:2,c:"#E0E0E0",a:.4},{x:-1,y:11,w:2,h:5,c:"#F0F0F0"},{x:11,y:11,w:2,h:5,c:"#F0F0F0"},{x:-1,y:15,w:2,h:1,c:"$skin"},{x:11,y:15,w:2,h:1,c:"$skin"}]},up:{name:"torso",pixels:[{x:0,y:10,w:12,h:7,c:"#F0F0F0"},{x:0,y:10,w:1,h:7,c:"#DDD",a:.5},{x:11,y:10,w:1,h:7,c:"#DDD",a:.5},{x:5,y:11,w:2,h:5,c:"#E8E8E8",a:.3},{x:-1,y:11,w:2,h:5,c:"#F0F0F0"},{x:11,y:11,w:2,h:5,c:"#F0F0F0"},{x:-1,y:15,w:2,h:1,c:"$skin"},{x:11,y:15,w:2,h:1,c:"$skin"}]},left:{name:"torso",pixels:[{x:3,y:10,w:3,h:5,c:"$shirt"},{x:0,y:10,w:3,h:7,c:"#F0F0F0"},{x:6,y:10,w:4,h:7,c:"#F0F0F0"},{x:1,y:10,w:8,h:1,c:"#FAFAFA"},{x:0,y:10,w:1,h:7,c:"#DDD",a:.5},{x:1,y:13,w:2,h:2,c:"#E0E0E0",a:.4},{x:-1,y:11,w:3,h:5,c:"#F0F0F0"},{x:-1,y:15,w:3,h:1,c:"$skin"}]}});Fl("overalls","Overalls",{down:{name:"torso",pixels:[{x:1,y:10,w:10,h:3,c:"$shirt"},{x:2,y:10,w:8,h:1,c:"lighten($shirt, 18)",a:.3},{x:3,y:11,w:6,h:5,c:"#3D6B99"},{x:3,y:10,w:2,h:1,c:"#3D6B99"},{x:7,y:10,w:2,h:1,c:"#3D6B99"},{x:3,y:11,w:1,h:1,c:"#FFD700",a:.6},{x:8,y:11,w:1,h:1,c:"#FFD700",a:.6},{x:1,y:13,w:2,h:3,c:"#3D6B99"},{x:9,y:13,w:2,h:3,c:"#3D6B99"},{x:5,y:13,w:2,h:2,c:"#345E87",a:.4},{x:-1,y:11,w:2,h:5,c:"$shirt"},{x:11,y:11,w:2,h:5,c:"$shirt"},{x:-1,y:15,w:2,h:1,c:"$skin"},{x:11,y:15,w:2,h:1,c:"$skin"}]},up:{name:"torso",pixels:[{x:1,y:10,w:10,h:3,c:"$shirt"},{x:3,y:10,w:2,h:1,c:"#3D6B99"},{x:7,y:10,w:2,h:1,c:"#3D6B99"},{x:1,y:13,w:10,h:3,c:"#3D6B99"},{x:-1,y:11,w:2,h:5,c:"$shirt"},{x:11,y:11,w:2,h:5,c:"$shirt"},{x:-1,y:15,w:2,h:1,c:"$skin"},{x:11,y:15,w:2,h:1,c:"$skin"}]},left:{name:"torso",pixels:[{x:1,y:10,w:9,h:3,c:"$shirt"},{x:3,y:11,w:5,h:5,c:"#3D6B99"},{x:3,y:10,w:2,h:1,c:"#3D6B99"},{x:3,y:11,w:1,h:1,c:"#FFD700",a:.6},{x:1,y:13,w:2,h:3,c:"#3D6B99"},{x:-1,y:11,w:3,h:5,c:"$shirt"},{x:-1,y:15,w:3,h:1,c:"$skin"}]}});Fl("turtleneck","Turtleneck",{down:{name:"torso",pixels:[{x:1,y:10,w:10,h:6,c:"$shirt"},{x:1,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:10,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:3,y:8,w:6,h:2,c:"$shirt"},{x:4,y:8,w:4,h:1,c:"lighten($shirt, 12)",a:.3},{x:3,y:9,w:1,h:1,c:"darken($shirt, 15)",a:.2},{x:8,y:9,w:1,h:1,c:"darken($shirt, 15)",a:.2},{x:-1,y:11,w:2,h:5,c:"$shirt"},{x:11,y:11,w:2,h:5,c:"$shirt"},{x:-1,y:15,w:2,h:1,c:"$skin"},{x:11,y:15,w:2,h:1,c:"$skin"}]},up:{name:"torso",pixels:[{x:1,y:10,w:10,h:6,c:"$shirt"},{x:1,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:10,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:3,y:8,w:6,h:2,c:"$shirt"},{x:4,y:8,w:4,h:1,c:"lighten($shirt, 12)",a:.3},{x:-1,y:11,w:2,h:5,c:"$shirt"},{x:11,y:11,w:2,h:5,c:"$shirt"},{x:-1,y:15,w:2,h:1,c:"$skin"},{x:11,y:15,w:2,h:1,c:"$skin"}]},left:{name:"torso",pixels:[{x:1,y:10,w:9,h:6,c:"$shirt"},{x:1,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:3,y:8,w:4,h:2,c:"$shirt"},{x:3,y:8,w:3,h:1,c:"lighten($shirt, 12)",a:.3},{x:-1,y:11,w:3,h:5,c:"$shirt"},{x:-1,y:15,w:3,h:1,c:"$skin"}]}});Fl("robe","Robe",{down:{name:"torso",pixels:[{x:0,y:10,w:12,h:7,c:"$shirt"},{x:0,y:10,w:1,h:6,c:"darken($shirt, 25)",a:.3},{x:11,y:10,w:1,h:6,c:"darken($shirt, 25)",a:.3},{x:3,y:10,w:3,h:4,c:"lighten($shirt, 15)",a:.25},{x:6,y:10,w:3,h:4,c:"darken($shirt, 10)",a:.2},{x:1,y:14,w:10,h:1,c:"darken($shirt, 35)"},{x:2,y:14,w:8,h:1,c:"darken($shirt, 25)",a:.4},{x:-2,y:11,w:3,h:5,c:"$shirt"},{x:11,y:11,w:3,h:5,c:"$shirt"},{x:-2,y:15,w:3,h:1,c:"darken($shirt, 15)",a:.3},{x:11,y:15,w:3,h:1,c:"darken($shirt, 15)",a:.3},{x:-1,y:15,w:2,h:1,c:"$skin"},{x:11,y:15,w:2,h:1,c:"$skin"}]},up:{name:"torso",pixels:[{x:0,y:10,w:12,h:7,c:"$shirt"},{x:0,y:10,w:1,h:6,c:"darken($shirt, 25)",a:.3},{x:11,y:10,w:1,h:6,c:"darken($shirt, 25)",a:.3},{x:1,y:14,w:10,h:1,c:"darken($shirt, 35)"},{x:-2,y:11,w:3,h:5,c:"$shirt"},{x:11,y:11,w:3,h:5,c:"$shirt"},{x:-2,y:15,w:3,h:1,c:"darken($shirt, 15)",a:.3},{x:11,y:15,w:3,h:1,c:"darken($shirt, 15)",a:.3},{x:-1,y:15,w:2,h:1,c:"$skin"},{x:11,y:15,w:2,h:1,c:"$skin"}]},left:{name:"torso",pixels:[{x:0,y:10,w:10,h:7,c:"$shirt"},{x:0,y:10,w:1,h:6,c:"darken($shirt, 25)",a:.3},{x:1,y:14,w:8,h:1,c:"darken($shirt, 35)"},{x:-2,y:11,w:4,h:5,c:"$shirt"},{x:-2,y:15,w:4,h:1,c:"darken($shirt, 15)",a:.3},{x:-1,y:15,w:2,h:1,c:"$skin"}]}});const Rs=new Map;function kt(t,l,r){if("down"in r&&!("pixels"in r)){const c=r;Rs.set(t,{id:t,name:l,layer:{...c.down,name:"accessory"},directions:{down:{...c.down,name:"accessory"},up:c.up?{...c.up,name:"accessory"}:void 0,left:c.left?{...c.left,name:"accessory"}:void 0,right:c.right?{...c.right,name:"accessory"}:void 0}})}else{const c=r;Rs.set(t,{id:t,name:l,layer:{...c,name:"accessory"}})}}function Rj(t){return Rs.get(t)}function _j(t,l){const r=Rs.get(t);if(!r)return;if(r.directions)return Nj(r.directions,l);if(l==="down")return r.layer;const i=r.layer.pixels.filter(u=>u.y<2);if(i.length===0)return;const c=l==="right"?1:l==="left"?-1:0;return{name:r.layer.name,pixels:c?i.map(u=>({...u,x:u.x+c})):i}}function rg(){return Array.from(Rs.values())}kt("none","None",{name:"accessory",pixels:[]});kt("glasses","Glasses",{down:{name:"accessory",pixels:[{x:2,y:4,w:3,h:2,c:"#2A3A50",a:.5},{x:7,y:4,w:3,h:2,c:"#2A3A50",a:.5},{x:5,y:4,w:2,h:1,c:"#2A3A50",a:.3}]},up:{name:"accessory",pixels:[{x:0,y:3,w:2,h:1,c:"#2A3A50",a:.4},{x:10,y:3,w:2,h:1,c:"#2A3A50",a:.4}]},left:{name:"accessory",pixels:[{x:2,y:4,w:3,h:2,c:"#2A3A50",a:.5},{x:5,y:4,w:6,h:1,c:"#2A3A50",a:.3}]}});kt("round-glasses","Round Glasses",{down:{name:"accessory",pixels:[{x:2,y:3,w:3,h:3,c:"#8B7355",a:.4},{x:7,y:3,w:3,h:3,c:"#8B7355",a:.4},{x:3,y:4,w:1,h:1,c:"#B0E0FF",a:.15},{x:8,y:4,w:1,h:1,c:"#B0E0FF",a:.15},{x:5,y:4,w:2,h:1,c:"#8B7355",a:.3}]},up:{name:"accessory",pixels:[{x:0,y:3,w:2,h:1,c:"#8B7355",a:.3},{x:10,y:3,w:2,h:1,c:"#8B7355",a:.3}]},left:{name:"accessory",pixels:[{x:2,y:3,w:3,h:3,c:"#8B7355",a:.4},{x:3,y:4,w:1,h:1,c:"#B0E0FF",a:.15},{x:5,y:4,w:6,h:1,c:"#8B7355",a:.25}]}});kt("sunglasses","Sunglasses",{down:{name:"accessory",pixels:[{x:2,y:4,w:3,h:2,c:"#1A1A2E",a:.7},{x:7,y:4,w:3,h:2,c:"#1A1A2E",a:.7},{x:5,y:4,w:2,h:1,c:"#1A1A2E",a:.4},{x:3,y:4,w:1,h:1,c:"#334",a:.3},{x:8,y:4,w:1,h:1,c:"#334",a:.3}]},up:{name:"accessory",pixels:[{x:0,y:3,w:2,h:1,c:"#1A1A2E",a:.4},{x:10,y:3,w:2,h:1,c:"#1A1A2E",a:.4}]},left:{name:"accessory",pixels:[{x:2,y:4,w:3,h:2,c:"#1A1A2E",a:.7},{x:3,y:4,w:1,h:1,c:"#334",a:.3},{x:5,y:4,w:6,h:1,c:"#1A1A2E",a:.35}]}});kt("headphones","Headphones",{down:{name:"accessory",pixels:[{x:0,y:0,w:12,h:1,c:"#333",a:.7},{x:-1,y:1,w:2,h:5,c:"#444"},{x:11,y:1,w:2,h:5,c:"#444"},{x:-1,y:2,w:2,h:3,c:"#555",a:.3},{x:11,y:2,w:2,h:3,c:"#555",a:.3}]},up:{name:"accessory",pixels:[{x:0,y:0,w:12,h:1,c:"#333",a:.7},{x:-1,y:1,w:2,h:5,c:"#444"},{x:11,y:1,w:2,h:5,c:"#444"},{x:-1,y:2,w:2,h:3,c:"#555",a:.3},{x:11,y:2,w:2,h:3,c:"#555",a:.3}]},left:{name:"accessory",pixels:[{x:1,y:0,w:10,h:1,c:"#333",a:.7},{x:-1,y:1,w:3,h:5,c:"#444"},{x:-1,y:2,w:3,h:3,c:"#555",a:.3}]}});kt("beret","Beret",{down:{name:"accessory",pixels:[{x:2,y:-1,w:8,h:2,c:"#E91E63"},{x:1,y:0,w:2,h:1,c:"#E91E63",a:.6},{x:4,y:-1,w:4,h:1,c:"#F06292",a:.3}]},up:{name:"accessory",pixels:[{x:2,y:-1,w:8,h:2,c:"#E91E63"},{x:9,y:0,w:2,h:1,c:"#E91E63",a:.6}]},left:{name:"accessory",pixels:[{x:0,y:-1,w:8,h:2,c:"#E91E63"},{x:2,y:-1,w:4,h:1,c:"#F06292",a:.3}]}});kt("cap","Cap",{down:{name:"accessory",pixels:[{x:1,y:-1,w:10,h:2,c:"#1565C0"},{x:0,y:1,w:12,h:1,c:"#0D47A1"},{x:3,y:-1,w:6,h:1,c:"#1E88E5",a:.3}]},up:{name:"accessory",pixels:[{x:1,y:-1,w:10,h:2,c:"#1565C0"},{x:3,y:-1,w:6,h:1,c:"#1E88E5",a:.3},{x:5,y:1,w:2,h:1,c:"#0D47A1",a:.5}]},left:{name:"accessory",pixels:[{x:0,y:-1,w:9,h:2,c:"#1565C0"},{x:-2,y:1,w:6,h:1,c:"#0D47A1"},{x:2,y:-1,w:5,h:1,c:"#1E88E5",a:.3}]}});kt("badge","Badge",{down:{name:"accessory",pixels:[{x:5,y:8,w:2,h:3,c:"#2196F3",a:.4},{x:4,y:11,w:4,h:3,c:"#FFF",a:.5},{x:5,y:12,w:2,h:1,c:"#333",a:.3}]},up:{name:"accessory",pixels:[]},left:{name:"accessory",pixels:[{x:3,y:8,w:1,h:3,c:"#2196F3",a:.4},{x:2,y:11,w:3,h:3,c:"#FFF",a:.5}]}});kt("lapels","Lapels",{down:{name:"accessory",pixels:[{x:1,y:10,w:3,h:2,c:"#1A1A2E",a:.4},{x:8,y:10,w:3,h:2,c:"#1A1A2E",a:.4}]},up:{name:"accessory",pixels:[]},left:{name:"accessory",pixels:[{x:1,y:10,w:3,h:2,c:"#1A1A2E",a:.4}]}});kt("blush","Blush",{down:{name:"accessory",pixels:[{x:2,y:6,w:1,h:1,c:"#FFCDD2",a:.3},{x:9,y:6,w:1,h:1,c:"#FFCDD2",a:.3}]},up:{name:"accessory",pixels:[]},left:{name:"accessory",pixels:[{x:2,y:6,w:1,h:1,c:"#FFCDD2",a:.3}]}});kt("scarf","Scarf",{down:{name:"accessory",pixels:[{x:2,y:9,w:8,h:2,c:"#E53935",a:.6},{x:3,y:9,w:6,h:1,c:"#EF5350",a:.3},{x:3,y:11,w:2,h:3,c:"#E53935",a:.5}]},up:{name:"accessory",pixels:[{x:2,y:9,w:8,h:2,c:"#E53935",a:.6},{x:3,y:9,w:6,h:1,c:"#EF5350",a:.3}]},left:{name:"accessory",pixels:[{x:1,y:9,w:8,h:2,c:"#E53935",a:.6},{x:2,y:9,w:5,h:1,c:"#EF5350",a:.3},{x:1,y:11,w:2,h:3,c:"#E53935",a:.5}]}});kt("tie","Tie",{down:{name:"accessory",pixels:[{x:5,y:9,w:2,h:1,c:"#B71C1C"},{x:5,y:10,w:2,h:4,c:"#D32F2F"},{x:5,y:10,w:1,h:4,c:"#E53935",a:.3},{x:5,y:14,w:2,h:1,c:"#B71C1C",a:.8}]},up:{name:"accessory",pixels:[]},left:{name:"accessory",pixels:[{x:4,y:9,w:2,h:1,c:"#B71C1C"},{x:4,y:10,w:2,h:4,c:"#D32F2F"},{x:4,y:14,w:2,h:1,c:"#B71C1C",a:.8}]}});kt("bowtie","Bowtie",{down:{name:"accessory",pixels:[{x:3,y:9,w:2,h:1,c:"#D32F2F"},{x:7,y:9,w:2,h:1,c:"#D32F2F"},{x:5,y:9,w:2,h:1,c:"#B71C1C"},{x:4,y:9,w:1,h:1,c:"#E53935",a:.3},{x:7,y:9,w:1,h:1,c:"#E53935",a:.3}]},up:{name:"accessory",pixels:[]},left:{name:"accessory",pixels:[{x:3,y:9,w:3,h:1,c:"#D32F2F"},{x:4,y:9,w:1,h:1,c:"#B71C1C"}]}});kt("cat-ears","Cat Ears",{down:{name:"accessory",pixels:[{x:1,y:-3,w:2,h:1,c:"#555"},{x:0,y:-2,w:3,h:1,c:"#555"},{x:0,y:-1,w:3,h:1,c:"#555"},{x:1,y:-2,w:1,h:1,c:"#FFB0C0",a:.6},{x:9,y:-3,w:2,h:1,c:"#555"},{x:9,y:-2,w:3,h:1,c:"#555"},{x:9,y:-1,w:3,h:1,c:"#555"},{x:10,y:-2,w:1,h:1,c:"#FFB0C0",a:.6}]},up:{name:"accessory",pixels:[{x:1,y:-3,w:2,h:1,c:"#555"},{x:0,y:-2,w:3,h:1,c:"#555"},{x:0,y:-1,w:3,h:1,c:"#555"},{x:9,y:-3,w:2,h:1,c:"#555"},{x:9,y:-2,w:3,h:1,c:"#555"},{x:9,y:-1,w:3,h:1,c:"#555"}]},left:{name:"accessory",pixels:[{x:2,y:-3,w:2,h:1,c:"#555"},{x:1,y:-2,w:3,h:1,c:"#555"},{x:1,y:-1,w:3,h:1,c:"#555"},{x:2,y:-2,w:1,h:1,c:"#FFB0C0",a:.6}]}});kt("bear-ears","Bear Ears",{down:{name:"accessory",pixels:[{x:0,y:-2,w:3,h:2,c:"#8B6914"},{x:1,y:-1,w:1,h:1,c:"#C4A24A",a:.5},{x:9,y:-2,w:3,h:2,c:"#8B6914"},{x:10,y:-1,w:1,h:1,c:"#C4A24A",a:.5}]},up:{name:"accessory",pixels:[{x:0,y:-2,w:3,h:2,c:"#8B6914"},{x:9,y:-2,w:3,h:2,c:"#8B6914"}]},left:{name:"accessory",pixels:[{x:1,y:-2,w:3,h:2,c:"#8B6914"},{x:2,y:-1,w:1,h:1,c:"#C4A24A",a:.5}]}});kt("bunny-ears","Bunny Ears",{down:{name:"accessory",pixels:[{x:2,y:-5,w:2,h:4,c:"#F5F5F5"},{x:2,y:-4,w:1,h:2,c:"#FFB0C0",a:.5},{x:8,y:-5,w:2,h:4,c:"#F5F5F5"},{x:9,y:-4,w:1,h:2,c:"#FFB0C0",a:.5},{x:9,y:-6,w:2,h:1,c:"#F5F5F5"}]},up:{name:"accessory",pixels:[{x:2,y:-5,w:2,h:4,c:"#F5F5F5"},{x:8,y:-5,w:2,h:4,c:"#F5F5F5"},{x:9,y:-6,w:2,h:1,c:"#F5F5F5"}]},left:{name:"accessory",pixels:[{x:3,y:-5,w:2,h:4,c:"#F5F5F5"},{x:3,y:-4,w:1,h:2,c:"#FFB0C0",a:.5},{x:4,y:-6,w:2,h:1,c:"#F5F5F5"}]}});kt("dog-nose","Dog Nose",{down:{name:"accessory",pixels:[{x:4,y:5,w:4,h:3,c:"#D2B48C",a:.5},{x:5,y:5,w:2,h:1,c:"#222"},{x:6,y:7,w:1,h:1,c:"#FF6B8A",a:.7}]},up:{name:"accessory",pixels:[]},left:{name:"accessory",pixels:[{x:0,y:5,w:4,h:2,c:"#D2B48C",a:.5},{x:0,y:5,w:2,h:1,c:"#222"},{x:1,y:7,w:1,h:1,c:"#FF6B8A",a:.7}]}});kt("fox-mask","Fox Mask",{down:{name:"accessory",pixels:[{x:0,y:-3,w:2,h:1,c:"#E65100"},{x:-1,y:-2,w:3,h:1,c:"#E65100"},{x:0,y:-1,w:3,h:1,c:"#E65100"},{x:10,y:-3,w:2,h:1,c:"#E65100"},{x:10,y:-2,w:3,h:1,c:"#E65100"},{x:9,y:-1,w:3,h:1,c:"#E65100"},{x:0,y:-2,w:1,h:1,c:"#FFF",a:.4},{x:11,y:-2,w:1,h:1,c:"#FFF",a:.4},{x:1,y:5,w:2,h:2,c:"#FFF",a:.25},{x:9,y:5,w:2,h:2,c:"#FFF",a:.25},{x:5,y:6,w:2,h:1,c:"#222",a:.6}]},up:{name:"accessory",pixels:[{x:0,y:-3,w:2,h:1,c:"#E65100"},{x:-1,y:-2,w:3,h:1,c:"#E65100"},{x:0,y:-1,w:3,h:1,c:"#E65100"},{x:10,y:-3,w:2,h:1,c:"#E65100"},{x:10,y:-2,w:3,h:1,c:"#E65100"},{x:9,y:-1,w:3,h:1,c:"#E65100"}]},left:{name:"accessory",pixels:[{x:1,y:-3,w:2,h:1,c:"#E65100"},{x:0,y:-2,w:3,h:1,c:"#E65100"},{x:1,y:-1,w:3,h:1,c:"#E65100"},{x:1,y:-2,w:1,h:1,c:"#FFF",a:.4},{x:1,y:5,w:2,h:2,c:"#FFF",a:.25},{x:1,y:6,w:2,h:1,c:"#222",a:.6}]}});kt("crown","Crown",{down:{name:"accessory",pixels:[{x:2,y:-1,w:8,h:2,c:"#FFD700"},{x:3,y:-3,w:2,h:2,c:"#FFD700"},{x:5,y:-2,w:2,h:1,c:"#FFD700"},{x:7,y:-3,w:2,h:2,c:"#FFD700"},{x:4,y:-2,w:1,h:1,c:"#E53935",a:.8},{x:6,y:-1,w:1,h:1,c:"#42A5F5",a:.8},{x:8,y:-2,w:1,h:1,c:"#66BB6A",a:.8},{x:3,y:-1,w:6,h:1,c:"#FFF",a:.15}]},up:{name:"accessory",pixels:[{x:2,y:-1,w:8,h:2,c:"#FFD700"},{x:3,y:-3,w:2,h:2,c:"#FFD700"},{x:5,y:-2,w:2,h:1,c:"#FFD700"},{x:7,y:-3,w:2,h:2,c:"#FFD700"},{x:3,y:-1,w:6,h:1,c:"#FFF",a:.15}]},left:{name:"accessory",pixels:[{x:1,y:-1,w:7,h:2,c:"#FFD700"},{x:2,y:-3,w:2,h:2,c:"#FFD700"},{x:5,y:-2,w:2,h:1,c:"#FFD700"},{x:3,y:-2,w:1,h:1,c:"#E53935",a:.8},{x:5,y:-1,w:1,h:1,c:"#42A5F5",a:.8},{x:2,y:-1,w:5,h:1,c:"#FFF",a:.15}]}});kt("halo","Halo",{down:{name:"accessory",pixels:[{x:2,y:-3,w:8,h:1,c:"#FFE082",a:.7},{x:1,y:-2,w:1,h:1,c:"#FFE082",a:.5},{x:10,y:-2,w:1,h:1,c:"#FFE082",a:.5},{x:3,y:-4,w:6,h:1,c:"#FFF9C4",a:.4},{x:3,y:-3,w:6,h:1,c:"#FFF",a:.15}]},up:{name:"accessory",pixels:[{x:2,y:-3,w:8,h:1,c:"#FFE082",a:.7},{x:1,y:-2,w:1,h:1,c:"#FFE082",a:.5},{x:10,y:-2,w:1,h:1,c:"#FFE082",a:.5},{x:3,y:-4,w:6,h:1,c:"#FFF9C4",a:.4},{x:3,y:-3,w:6,h:1,c:"#FFF",a:.15}]},left:{name:"accessory",pixels:[{x:1,y:-3,w:7,h:1,c:"#FFE082",a:.7},{x:0,y:-2,w:1,h:1,c:"#FFE082",a:.5},{x:8,y:-2,w:1,h:1,c:"#FFE082",a:.5},{x:2,y:-4,w:5,h:1,c:"#FFF9C4",a:.4},{x:2,y:-3,w:5,h:1,c:"#FFF",a:.15}]}});kt("horns","Horns",{down:{name:"accessory",pixels:[{x:1,y:-1,w:2,h:2,c:"#8B0000"},{x:0,y:-3,w:2,h:2,c:"#A00"},{x:0,y:-4,w:1,h:1,c:"#C62828"},{x:9,y:-1,w:2,h:2,c:"#8B0000"},{x:10,y:-3,w:2,h:2,c:"#A00"},{x:11,y:-4,w:1,h:1,c:"#C62828"}]},up:{name:"accessory",pixels:[{x:1,y:-1,w:2,h:2,c:"#8B0000"},{x:0,y:-3,w:2,h:2,c:"#A00"},{x:0,y:-4,w:1,h:1,c:"#C62828"},{x:9,y:-1,w:2,h:2,c:"#8B0000"},{x:10,y:-3,w:2,h:2,c:"#A00"},{x:11,y:-4,w:1,h:1,c:"#C62828"}]},left:{name:"accessory",pixels:[{x:2,y:-1,w:2,h:2,c:"#8B0000"},{x:1,y:-3,w:2,h:2,c:"#A00"},{x:1,y:-4,w:1,h:1,c:"#C62828"}]}});kt("mask","Mask",{down:{name:"accessory",pixels:[{x:1,y:3,w:10,h:3,c:"#1A1A2E",a:.75},{x:3,y:4,w:2,h:1,c:"#000",a:0},{x:7,y:4,w:2,h:1,c:"#000",a:0},{x:1,y:3,w:10,h:1,c:"#FFD700",a:.3},{x:1,y:5,w:10,h:1,c:"#FFD700",a:.2}]},up:{name:"accessory",pixels:[{x:0,y:4,w:12,h:1,c:"#1A1A2E",a:.3}]},left:{name:"accessory",pixels:[{x:1,y:3,w:6,h:3,c:"#1A1A2E",a:.75},{x:2,y:4,w:2,h:1,c:"#000",a:0},{x:1,y:3,w:6,h:1,c:"#FFD700",a:.3},{x:1,y:5,w:6,h:1,c:"#FFD700",a:.2}]}});kt("bandana","Bandana",{down:{name:"accessory",pixels:[{x:0,y:1,w:12,h:2,c:"#E53935"},{x:1,y:1,w:10,h:1,c:"#EF5350",a:.3}]},up:{name:"accessory",pixels:[{x:0,y:1,w:12,h:2,c:"#E53935"},{x:1,y:1,w:10,h:1,c:"#EF5350",a:.3},{x:11,y:2,w:2,h:2,c:"#E53935",a:.7},{x:12,y:3,w:1,h:1,c:"#C62828",a:.5}]},left:{name:"accessory",pixels:[{x:0,y:1,w:10,h:2,c:"#E53935"},{x:1,y:1,w:8,h:1,c:"#EF5350",a:.3}]}});kt("eyepatch","Eye Patch",{down:{name:"accessory",pixels:[{x:0,y:3,w:12,h:1,c:"#222",a:.5},{x:2,y:3,w:3,h:3,c:"#1A1A1A"},{x:3,y:4,w:1,h:1,c:"#333",a:.3}]},up:{name:"accessory",pixels:[{x:0,y:3,w:12,h:1,c:"#222",a:.5}]},left:{name:"accessory",pixels:[{x:0,y:3,w:10,h:1,c:"#222",a:.5},{x:1,y:3,w:3,h:3,c:"#1A1A1A"},{x:2,y:4,w:1,h:1,c:"#333",a:.3}]}});kt("cat-face","Cat Face",{down:{name:"accessory",pixels:[{x:1,y:1,w:10,h:8,c:"#555"},{x:2,y:0,w:8,h:1,c:"#555"},{x:0,y:-2,w:3,h:2,c:"#555"},{x:1,y:-3,w:2,h:1,c:"#555"},{x:9,y:-2,w:3,h:2,c:"#555"},{x:9,y:-3,w:2,h:1,c:"#555"},{x:1,y:-1,w:1,h:1,c:"#FFB0C0",a:.7},{x:10,y:-1,w:1,h:1,c:"#FFB0C0",a:.7},{x:2,y:3,w:3,h:3,c:"#222"},{x:7,y:3,w:3,h:3,c:"#222"},{x:3,y:3,w:1,h:2,c:"#4FC3F7",a:.8},{x:8,y:3,w:1,h:2,c:"#4FC3F7",a:.8},{x:3,y:4,w:1,h:1,c:"#111"},{x:8,y:4,w:1,h:1,c:"#111"},{x:5,y:5,w:2,h:1,c:"#FFB0C0"},{x:4,y:6,w:1,h:1,c:"#444",a:.6},{x:7,y:6,w:1,h:1,c:"#444",a:.6},{x:0,y:5,w:2,h:1,c:"#888",a:.4},{x:10,y:5,w:2,h:1,c:"#888",a:.4},{x:0,y:6,w:2,h:1,c:"#888",a:.3},{x:10,y:6,w:2,h:1,c:"#888",a:.3}]},up:{name:"accessory",pixels:[{x:1,y:1,w:10,h:8,c:"#555"},{x:2,y:0,w:8,h:1,c:"#555"},{x:0,y:-2,w:3,h:2,c:"#555"},{x:1,y:-3,w:2,h:1,c:"#555"},{x:9,y:-2,w:3,h:2,c:"#555"},{x:9,y:-3,w:2,h:1,c:"#555"},{x:5,y:1,w:2,h:5,c:"#4A4A4A",a:.3},{x:9,y:8,w:2,h:2,c:"#555"},{x:10,y:7,w:1,h:1,c:"#555"}]},left:{name:"accessory",pixels:[{x:1,y:1,w:9,h:8,c:"#555"},{x:2,y:0,w:7,h:1,c:"#555"},{x:2,y:-2,w:3,h:2,c:"#555"},{x:3,y:-3,w:2,h:1,c:"#555"},{x:3,y:-1,w:1,h:1,c:"#FFB0C0",a:.7},{x:2,y:3,w:3,h:3,c:"#222"},{x:3,y:3,w:1,h:2,c:"#4FC3F7",a:.8},{x:3,y:4,w:1,h:1,c:"#111"},{x:0,y:5,w:3,h:2,c:"#555"},{x:0,y:5,w:2,h:1,c:"#FFB0C0"},{x:-1,y:5,w:2,h:1,c:"#888",a:.4},{x:-1,y:6,w:2,h:1,c:"#888",a:.3}]}});kt("bear-face","Bear Face",{down:{name:"accessory",pixels:[{x:1,y:0,w:10,h:9,c:"#8B6914"},{x:2,y:-1,w:8,h:1,c:"#8B6914"},{x:0,y:-1,w:3,h:3,c:"#8B6914"},{x:9,y:-1,w:3,h:3,c:"#8B6914"},{x:1,y:0,w:1,h:1,c:"#C4A24A",a:.6},{x:10,y:0,w:1,h:1,c:"#C4A24A",a:.6},{x:3,y:5,w:6,h:4,c:"#C4A24A",a:.7},{x:3,y:3,w:2,h:2,c:"#111"},{x:7,y:3,w:2,h:2,c:"#111"},{x:3,y:3,w:1,h:1,c:"#FFF",a:.3},{x:7,y:3,w:1,h:1,c:"#FFF",a:.3},{x:5,y:5,w:2,h:1,c:"#222"},{x:5,y:7,w:2,h:1,c:"#6B4F10",a:.5}]},up:{name:"accessory",pixels:[{x:1,y:0,w:10,h:9,c:"#8B6914"},{x:2,y:-1,w:8,h:1,c:"#8B6914"},{x:0,y:-1,w:3,h:3,c:"#8B6914"},{x:9,y:-1,w:3,h:3,c:"#8B6914"},{x:1,y:0,w:1,h:1,c:"#C4A24A",a:.6},{x:10,y:0,w:1,h:1,c:"#C4A24A",a:.6},{x:5,y:1,w:2,h:5,c:"#7A5B10",a:.3}]},left:{name:"accessory",pixels:[{x:1,y:0,w:9,h:9,c:"#8B6914"},{x:2,y:-1,w:7,h:1,c:"#8B6914"},{x:0,y:-1,w:3,h:3,c:"#8B6914"},{x:0,y:0,w:1,h:1,c:"#C4A24A",a:.6},{x:0,y:4,w:3,h:4,c:"#C4A24A",a:.7},{x:3,y:3,w:2,h:2,c:"#111"},{x:3,y:3,w:1,h:1,c:"#FFF",a:.3},{x:1,y:5,w:2,h:1,c:"#222"}]}});kt("panda-face","Panda Face",{down:{name:"accessory",pixels:[{x:1,y:0,w:10,h:9,c:"#F5F5F5"},{x:2,y:-1,w:8,h:1,c:"#F5F5F5"},{x:0,y:-2,w:3,h:3,c:"#222"},{x:9,y:-2,w:3,h:3,c:"#222"},{x:2,y:2,w:3,h:4,c:"#222"},{x:7,y:2,w:3,h:4,c:"#222"},{x:3,y:3,w:1,h:2,c:"#FFF"},{x:8,y:3,w:1,h:2,c:"#FFF"},{x:3,y:4,w:1,h:1,c:"#111"},{x:8,y:4,w:1,h:1,c:"#111"},{x:5,y:6,w:2,h:1,c:"#222"},{x:5,y:7,w:1,h:1,c:"#CCC",a:.4},{x:6,y:7,w:1,h:1,c:"#CCC",a:.4}]},up:{name:"accessory",pixels:[{x:1,y:0,w:10,h:9,c:"#F5F5F5"},{x:2,y:-1,w:8,h:1,c:"#F5F5F5"},{x:0,y:-2,w:3,h:3,c:"#222"},{x:9,y:-2,w:3,h:3,c:"#222"},{x:5,y:1,w:2,h:5,c:"#EEE",a:.3}]},left:{name:"accessory",pixels:[{x:1,y:0,w:9,h:9,c:"#F5F5F5"},{x:2,y:-1,w:7,h:1,c:"#F5F5F5"},{x:0,y:-2,w:3,h:3,c:"#222"},{x:2,y:2,w:3,h:4,c:"#222"},{x:3,y:3,w:1,h:2,c:"#FFF"},{x:3,y:4,w:1,h:1,c:"#111"},{x:0,y:5,w:3,h:2,c:"#F5F5F5"},{x:1,y:6,w:1,h:1,c:"#222"}]}});kt("frog-face","Frog Face",{down:{name:"accessory",pixels:[{x:1,y:1,w:10,h:8,c:"#4CAF50"},{x:2,y:0,w:8,h:1,c:"#4CAF50"},{x:1,y:-2,w:4,h:3,c:"#4CAF50"},{x:7,y:-2,w:4,h:3,c:"#4CAF50"},{x:2,y:-1,w:2,h:2,c:"#FFF"},{x:8,y:-1,w:2,h:2,c:"#FFF"},{x:3,y:0,w:1,h:1,c:"#111"},{x:9,y:0,w:1,h:1,c:"#111"},{x:3,y:5,w:6,h:3,c:"#81C784",a:.5},{x:2,y:7,w:8,h:1,c:"#388E3C",a:.6},{x:4,y:4,w:1,h:1,c:"#388E3C",a:.5},{x:7,y:4,w:1,h:1,c:"#388E3C",a:.5},{x:1,y:5,w:2,h:1,c:"#FF8A80",a:.25},{x:9,y:5,w:2,h:1,c:"#FF8A80",a:.25}]},up:{name:"accessory",pixels:[{x:1,y:1,w:10,h:8,c:"#4CAF50"},{x:2,y:0,w:8,h:1,c:"#4CAF50"},{x:1,y:-2,w:4,h:2,c:"#4CAF50"},{x:7,y:-2,w:4,h:2,c:"#4CAF50"},{x:5,y:2,w:2,h:4,c:"#388E3C",a:.2}]},left:{name:"accessory",pixels:[{x:1,y:1,w:9,h:8,c:"#4CAF50"},{x:2,y:0,w:7,h:1,c:"#4CAF50"},{x:0,y:-2,w:4,h:3,c:"#4CAF50"},{x:1,y:-1,w:2,h:2,c:"#FFF"},{x:2,y:0,w:1,h:1,c:"#111"},{x:0,y:5,w:3,h:3,c:"#81C784",a:.5},{x:0,y:7,w:8,h:1,c:"#388E3C",a:.6},{x:1,y:5,w:1,h:1,c:"#FF8A80",a:.25}]}});kt("rabbit-face","Rabbit Face",{down:{name:"accessory",pixels:[{x:1,y:1,w:10,h:8,c:"#F5F5F5"},{x:2,y:0,w:8,h:1,c:"#F5F5F5"},{x:2,y:-6,w:3,h:6,c:"#F5F5F5"},{x:7,y:-6,w:3,h:6,c:"#F5F5F5"},{x:3,y:-5,w:1,h:4,c:"#FFB0C0",a:.6},{x:8,y:-5,w:1,h:4,c:"#FFB0C0",a:.6},{x:2,y:3,w:3,h:3,c:"#E57373",a:.7},{x:7,y:3,w:3,h:3,c:"#E57373",a:.7},{x:3,y:3,w:1,h:1,c:"#FFF",a:.4},{x:8,y:3,w:1,h:1,c:"#FFF",a:.4},{x:5,y:5,w:2,h:1,c:"#FFB0C0"},{x:5,y:6,w:1,h:1,c:"#DDD",a:.4},{x:6,y:6,w:1,h:1,c:"#DDD",a:.4},{x:0,y:4,w:2,h:3,c:"#F5F5F5",a:.6},{x:10,y:4,w:2,h:3,c:"#F5F5F5",a:.6}]},up:{name:"accessory",pixels:[{x:1,y:1,w:10,h:8,c:"#F5F5F5"},{x:2,y:0,w:8,h:1,c:"#F5F5F5"},{x:2,y:-6,w:3,h:6,c:"#F5F5F5"},{x:7,y:-6,w:3,h:6,c:"#F5F5F5"},{x:3,y:-5,w:1,h:4,c:"#FFB0C0",a:.6},{x:8,y:-5,w:1,h:4,c:"#FFB0C0",a:.6},{x:5,y:8,w:3,h:2,c:"#FFF"}]},left:{name:"accessory",pixels:[{x:1,y:1,w:9,h:8,c:"#F5F5F5"},{x:2,y:0,w:7,h:1,c:"#F5F5F5"},{x:3,y:-6,w:3,h:6,c:"#F5F5F5"},{x:4,y:-5,w:1,h:4,c:"#FFB0C0",a:.6},{x:2,y:3,w:3,h:3,c:"#E57373",a:.7},{x:3,y:3,w:1,h:1,c:"#FFF",a:.4},{x:0,y:4,w:3,h:3,c:"#F5F5F5"},{x:1,y:5,w:1,h:1,c:"#FFB0C0"},{x:0,y:4,w:2,h:3,c:"#F5F5F5",a:.6}]}});kt("dog-face","Dog Face",{down:{name:"accessory",pixels:[{x:1,y:0,w:10,h:9,c:"#D2A25C"},{x:2,y:-1,w:8,h:1,c:"#D2A25C"},{x:-1,y:1,w:3,h:6,c:"#A67B3D"},{x:10,y:1,w:3,h:6,c:"#A67B3D"},{x:3,y:5,w:6,h:4,c:"#F5E6D0",a:.8},{x:3,y:2,w:2,h:3,c:"#3E2723"},{x:7,y:2,w:2,h:3,c:"#3E2723"},{x:3,y:2,w:1,h:1,c:"#FFF",a:.4},{x:7,y:2,w:1,h:1,c:"#FFF",a:.4},{x:5,y:5,w:2,h:2,c:"#222"},{x:5,y:7,w:2,h:2,c:"#FF6B8A",a:.8},{x:5,y:7,w:1,h:1,c:"#FF8A9E",a:.4}]},up:{name:"accessory",pixels:[{x:1,y:0,w:10,h:9,c:"#D2A25C"},{x:2,y:-1,w:8,h:1,c:"#D2A25C"},{x:-1,y:1,w:3,h:6,c:"#A67B3D"},{x:10,y:1,w:3,h:6,c:"#A67B3D"},{x:5,y:0,w:2,h:6,c:"#B8883C",a:.3},{x:2,y:8,w:8,h:1,c:"#A67B3D",a:.5}]},left:{name:"accessory",pixels:[{x:1,y:0,w:9,h:9,c:"#D2A25C"},{x:2,y:-1,w:7,h:1,c:"#D2A25C"},{x:-1,y:1,w:3,h:6,c:"#A67B3D"},{x:-1,y:4,w:3,h:4,c:"#D2A25C"},{x:-1,y:5,w:2,h:3,c:"#F5E6D0",a:.8},{x:3,y:2,w:2,h:3,c:"#3E2723"},{x:3,y:2,w:1,h:1,c:"#FFF",a:.4},{x:0,y:5,w:2,h:1,c:"#222"},{x:0,y:7,w:2,h:1,c:"#FF6B8A",a:.7}]}});const Oj={none:1,glasses:1,beret:1,cap:1,badge:1,blush:1,lapels:1,"round-glasses":2,headphones:2,scarf:3,tie:3,bowtie:3,sunglasses:4,bandana:4,eyepatch:4,crown:5,halo:5,horns:5,mask:5,"cat-ears":6,"bear-ears":6,"bunny-ears":6,"dog-nose":6,"fox-mask":6,"cat-face":7,"bear-face":7,"panda-face":7,"frog-face":8,"rabbit-face":8,"dog-face":8,"star-glasses":9};function ag(t){return Oj[t]??1}function ig(t,l){return l>=ag(t)}kt("star-glasses","Star Glasses",{down:{name:"accessory",pixels:[{x:1,y:3,w:4,h:3,c:"#FF4081",a:.6},{x:2,y:2,w:2,h:1,c:"#FF4081",a:.6},{x:2,y:6,w:2,h:1,c:"#FF4081",a:.6},{x:7,y:3,w:4,h:3,c:"#FF4081",a:.6},{x:8,y:2,w:2,h:1,c:"#FF4081",a:.6},{x:8,y:6,w:2,h:1,c:"#FF4081",a:.6},{x:5,y:4,w:2,h:1,c:"#FF4081",a:.4}]},up:{name:"accessory",pixels:[{x:0,y:3,w:2,h:1,c:"#FF4081",a:.3},{x:10,y:3,w:2,h:1,c:"#FF4081",a:.3}]},left:{name:"accessory",pixels:[{x:1,y:3,w:4,h:3,c:"#FF4081",a:.6},{x:2,y:2,w:2,h:1,c:"#FF4081",a:.6},{x:2,y:6,w:2,h:1,c:"#FF4081",a:.6},{x:5,y:4,w:6,h:1,c:"#FF4081",a:.3}]}});function vs({r:t,g:l,b:r}){return`#${(t<<16|l<<8|r).toString(16).padStart(6,"0")}`}function jc(t,l){const r=t.r-l.r,i=t.g-l.g,c=t.b-l.b;return r*r+i*i+c*c}function Bj(t,l){const r=[];r.push(t[Math.floor(Math.random()*t.length)]);for(let i=1;i<l;i++){const c=t.map(m=>{let x=1/0;for(const f of r)x=Math.min(x,jc(m,f));return x}),u=c.reduce((m,x)=>m+x,0);let d=Math.random()*u;for(let m=0;m<t.length;m++)if(d-=c[m],d<=0){r.push(t[m]);break}r.length<=i&&r.push(t[Math.floor(Math.random()*t.length)])}return r}function Lj(t,l,r=20){if(t.length===0)return[];const i=Bj(t,l);for(let u=0;u<r;u++){const d=Array.from({length:l},()=>[]);for(const x of t){let f=1/0,g=0;for(let y=0;y<l;y++){const b=jc(x,i[y]);b<f&&(f=b,g=y)}d[g].push(x)}let m=!0;for(let x=0;x<l;x++){if(d[x].length===0)continue;const f={r:0,g:0,b:0};for(const b of d[x])f.r+=b.r,f.g+=b.g,f.b+=b.b;const g=d[x].length,y={r:Math.round(f.r/g),g:Math.round(f.g/g),b:Math.round(f.b/g)};jc(y,i[x])>1&&(m=!1),i[x]=y}if(m)break}const c=new Array(l).fill(0);for(const u of t){let d=1/0,m=0;for(let x=0;x<l;x++){const f=jc(u,i[x]);f<d&&(d=f,m=x)}c[m]++}return i.map((u,d)=>({c:u,count:c[d]})).sort((u,d)=>d.count-u.count).map(u=>u.c)}function $j(t,l=1e4){const r=document.createElement("canvas"),i=t instanceof HTMLImageElement?t.naturalWidth:t.width,c=t instanceof HTMLImageElement?t.naturalHeight:t.height;r.width=i,r.height=c;const u=r.getContext("2d");u.drawImage(t,0,0);const d=u.getImageData(0,0,i,c).data,m=i*c,x=Math.max(1,Math.floor(m/l)),f=[];for(let g=0;g<m;g+=x){const y=g*4;d[y+3]<128||f.push({r:d[y],g:d[y+1],b:d[y+2]})}return f}function c0(t){return .299*t.r+.587*t.g+.114*t.b}function u0(t){const l=Math.max(t.r,t.g,t.b),r=Math.min(t.r,t.g,t.b);return l===0?0:(l-r)/l*255}function Hj(t,l=8){const r=$j(t),i=Lj(r,l);if(i.length<5)return{skinColor:"#F5CBA7",hairColor:"#2C1810",shirtColor:"#1565C0",pantsColor:"#37474F",shoeColor:"#212121"};const c=[...i].sort((y,b)=>c0(b)-c0(y)),u=[...i].sort((y,b)=>u0(b)-u0(y)),d=c[0],m=c[c.length-1],x=u[0],f=c[c.length-2],g=c[c.length-1];return{skinColor:vs(d),hairColor:vs(m),shirtColor:vs(x),pantsColor:vs(f),shoeColor:vs(g)}}const Uj=[{x:1,y:19,w:10,h:2,c:"#100A06",a:.15},{x:2,y:15,w:3,h:4,c:"$pants"},{x:7,y:15,w:3,h:4,c:"$pants"},{x:2,y:19,w:3,h:2,c:"$shoes"},{x:7,y:19,w:3,h:2,c:"$shoes"},{x:2,y:19,w:3,h:1,c:"lighten($shoes, 20)",a:.4},{x:7,y:19,w:3,h:1,c:"lighten($shoes, 20)",a:.4}],Ij=[{x:1,y:10,w:10,h:6,c:"$shirt"},{x:2,y:10,w:8,h:1,c:"lighten($shirt, 18)",a:.3},{x:1,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:10,y:10,w:1,h:5,c:"darken($shirt, 25)",a:.25},{x:4,y:10,w:4,h:2,c:"darken($shirt, 25)",a:.2},{x:-1,y:11,w:2,h:5,c:"$shirt"},{x:11,y:11,w:2,h:5,c:"$shirt"},{x:-1,y:15,w:2,h:1,c:"$skin"},{x:11,y:15,w:2,h:1,c:"$skin"}],Yj=[{x:4,y:8,w:4,h:3,c:"$skin"},{x:1,y:1,w:10,h:8,c:"$skin"},{x:3,y:4,w:2,h:2,c:"#1A1A2E"},{x:7,y:4,w:2,h:2,c:"#1A1A2E"},{x:3,y:4,w:1,h:1,c:"#FFF",a:.35},{x:7,y:4,w:1,h:1,c:"#FFF",a:.35},{x:5,y:7,w:2,h:1,c:"darken($skin, 25)",a:.4},{x:0,y:4,w:1,h:1,c:"$skin"},{x:11,y:4,w:1,h:1,c:"$skin"}],qj=[{x:1,y:0,w:10,h:3,c:"$hair"},{x:0,y:1,w:2,h:3,c:"$hair"},{x:10,y:1,w:2,h:3,c:"$hair"},{x:2,y:0,w:8,h:1,c:"lighten($hair, 25)",a:.3},{x:2,y:2,w:8,h:1,c:"darken($hair, 20)",a:.2}];function Xj(){return{width:12,height:22,layers:[{name:"lower",pixels:Uj},{name:"torso",pixels:Ij},{name:"head",pixels:Yj},{name:"hair",pixels:qj},{name:"accessory",pixels:[]}]}}const Vj=["cto","cbo","pm","engineer","designer","qa","data-analyst","default"];for(const t of Vj)eg(`mini:${t}`,Xj());const Gj=[{x:1,y:10,w:10,h:8,c:"$shirt"},{x:2,y:10,w:8,h:1,c:"lighten($shirt, 18)",a:.3},{x:1,y:10,w:1,h:7,c:"darken($shirt, 25)",a:.25},{x:10,y:10,w:1,h:7,c:"darken($shirt, 25)",a:.25},{x:4,y:10,w:4,h:2,c:"darken($shirt, 25)",a:.2},{x:-1,y:11,w:2,h:5,c:"$shirt"},{x:11,y:11,w:2,h:5,c:"$shirt"}],Kj=[{x:4,y:8,w:4,h:3,c:"$skin"},{x:1,y:1,w:10,h:8,c:"$skin"},{x:3,y:4,w:2,h:2,c:"#1A1A2E"},{x:7,y:4,w:2,h:2,c:"#1A1A2E"},{x:3,y:4,w:1,h:1,c:"#FFF",a:.35},{x:7,y:4,w:1,h:1,c:"#FFF",a:.35},{x:5,y:7,w:2,h:1,c:"darken($skin, 25)",a:.4},{x:0,y:4,w:1,h:1,c:"$skin"},{x:11,y:4,w:1,h:1,c:"$skin"}],Wj=[{x:1,y:0,w:10,h:3,c:"$hair"},{x:0,y:1,w:2,h:3,c:"$hair"},{x:10,y:1,w:2,h:3,c:"$hair"},{x:2,y:0,w:8,h:1,c:"lighten($hair, 25)",a:.3},{x:2,y:2,w:8,h:1,c:"darken($hair, 20)",a:.2}];function Qj(){return{width:12,height:22,layers:[{name:"torso",pixels:Gj},{name:"head",pixels:Kj},{name:"hair",pixels:Wj},{name:"accessory",pixels:[]}]}}eg("mini-seated:default",Qj());const Zj={canvasWidth:160,canvasHeight:80,scale:2,pixels:[{x:0,y:0,w:80,h:40,c:"#1e2030"},{x:10,y:2,w:10,h:6,c:"#78889c"},{x:10,y:2,w:10,h:1,c:"#8899ad"},{x:24,y:0,w:10,h:6,c:"#78889c"},{x:24,y:0,w:10,h:1,c:"#8899ad"},{x:38,y:2,w:10,h:6,c:"#78889c"},{x:38,y:2,w:10,h:1,c:"#8899ad"},{x:54,y:2,w:10,h:6,c:"#78889c"},{x:54,y:2,w:10,h:1,c:"#8899ad"},{x:11,y:7,w:2,h:2,c:"#2a2a2a"},{x:17,y:7,w:2,h:2,c:"#2a2a2a"},{x:25,y:5,w:2,h:2,c:"#2a2a2a"},{x:31,y:5,w:2,h:2,c:"#2a2a2a"},{x:39,y:7,w:2,h:2,c:"#2a2a2a"},{x:45,y:7,w:2,h:2,c:"#2a2a2a"},{x:55,y:7,w:2,h:2,c:"#2a2a2a"},{x:61,y:7,w:2,h:2,c:"#2a2a2a"},{x:8,y:8,w:64,h:24,c:"#6b5b4b"},{x:4,y:10,w:72,h:20,c:"#7d6d5d"},{x:2,y:12,w:76,h:16,c:"#7d6d5d"},{x:2,y:12,w:76,h:2,c:"#8b7b6b"},{x:2,y:26,w:76,h:2,c:"#4b3b2b"},{x:2,y:28,w:76,h:3,c:"#4b3b2b"},{x:4,y:28,w:72,h:1,c:"#5b4b3b"},{x:6,y:30,w:3,h:2,c:"#3a2a1a"},{x:71,y:30,w:3,h:2,c:"#3a2a1a"},{x:18,y:14,w:44,h:12,c:"#6b5b4b",a:.5},{x:28,y:14,w:14,h:8,c:"#1a1a2e"},{x:29,y:15,w:12,h:6,c:"#1565C0",a:.5},{x:30,y:16,w:8,h:1,c:"#60A5FA",a:.45},{x:30,y:18,w:5,h:1,c:"#60A5FA",a:.3},{x:58,y:16,w:5,h:5,c:"#795548"},{x:59,y:17,w:3,h:3,c:"#A67C52"},{x:63,y:18,w:2,h:2,c:"#795548"},{x:10,y:16,w:10,h:8,c:"#FFEE58",a:.7},{x:11,y:17,w:8,h:1,c:"#9E9E9E",a:.5},{x:11,y:19,w:8,h:1,c:"#9E9E9E",a:.5},{x:11,y:21,w:6,h:1,c:"#9E9E9E",a:.5},{x:10,y:32,w:10,h:6,c:"#78889c"},{x:10,y:32,w:10,h:1,c:"#8899ad"},{x:24,y:34,w:10,h:6,c:"#78889c"},{x:24,y:34,w:10,h:1,c:"#8899ad"},{x:38,y:32,w:10,h:6,c:"#78889c"},{x:38,y:32,w:10,h:1,c:"#8899ad"},{x:54,y:32,w:10,h:6,c:"#78889c"},{x:54,y:32,w:10,h:1,c:"#8899ad"},{x:11,y:37,w:2,h:2,c:"#2a2a2a"},{x:17,y:37,w:2,h:2,c:"#2a2a2a"},{x:25,y:39,w:2,h:2,c:"#2a2a2a"},{x:31,y:39,w:2,h:2,c:"#2a2a2a"},{x:39,y:37,w:2,h:2,c:"#2a2a2a"},{x:45,y:37,w:2,h:2,c:"#2a2a2a"},{x:55,y:37,w:2,h:2,c:"#2a2a2a"},{x:61,y:37,w:2,h:2,c:"#2a2a2a"}]},Jj={canvasWidth:128,canvasHeight:96,scale:2,pixels:[{x:0,y:0,w:64,h:48,c:"#4b3b2b"},{x:3,y:3,w:58,h:42,c:"#8B7355"},{x:4,y:4,w:10,h:10,c:"#A0845C",a:.5},{x:20,y:8,w:8,h:8,c:"#A0845C",a:.4},{x:40,y:6,w:12,h:6,c:"#A0845C",a:.3},{x:8,y:30,w:14,h:10,c:"#A0845C",a:.25},{x:44,y:32,w:10,h:8,c:"#A0845C",a:.3},{x:6,y:8,w:18,h:12,c:"#FFEE58"},{x:5,y:7,w:3,h:3,c:"#EF5350"},{x:6,y:7,w:2,h:2,c:"#C62828"},{x:8,y:10,w:14,h:1,c:"#9E9E9E"},{x:8,y:12,w:12,h:1,c:"#9E9E9E"},{x:8,y:14,w:10,h:1,c:"#9E9E9E"},{x:28,y:6,w:16,h:14,c:"#B3E5FC"},{x:35,y:5,w:3,h:3,c:"#42A5F5"},{x:36,y:5,w:2,h:2,c:"#1565C0"},{x:30,y:9,w:12,h:1,c:"#9E9E9E"},{x:30,y:11,w:10,h:1,c:"#9E9E9E"},{x:30,y:13,w:11,h:1,c:"#9E9E9E"},{x:8,y:24,w:16,h:14,c:"#C8E6C9"},{x:15,y:23,w:3,h:3,c:"#66BB6A"},{x:16,y:23,w:2,h:2,c:"#388E3C"},{x:10,y:27,w:12,h:1,c:"#9E9E9E"},{x:10,y:29,w:8,h:1,c:"#9E9E9E"},{x:10,y:31,w:10,h:1,c:"#9E9E9E"},{x:28,y:24,w:28,h:16,c:"#FFCDD2"},{x:43,y:23,w:3,h:3,c:"#EF5350"},{x:44,y:23,w:2,h:2,c:"#B71C1C"},{x:32,y:27,w:24,h:1,c:"#9E9E9E"},{x:32,y:29,w:20,h:1,c:"#9E9E9E"},{x:32,y:31,w:22,h:1,c:"#9E9E9E"},{x:32,y:33,w:15,h:1,c:"#9E9E9E"},{x:0,y:0,w:64,h:3,c:"#5a4a3a"},{x:0,y:45,w:64,h:3,c:"#3a2a1a"}]},Pj={canvasWidth:128,canvasHeight:96,scale:2,pixels:[{x:2,y:0,w:60,h:48,c:"#3b1f0a"},{x:4,y:2,w:56,h:44,c:"#5a3310"},{x:4,y:13,w:56,h:2,c:"#2d1508"},{x:4,y:27,w:56,h:2,c:"#2d1508"},{x:4,y:41,w:56,h:2,c:"#2d1508"},{x:5,y:3,w:4,h:10,c:"#2563EB"},{x:5,y:3,w:4,h:2,c:"#1D4ED8"},{x:10,y:4,w:3,h:9,c:"#DC2626"},{x:10,y:4,w:3,h:2,c:"#B91C1C"},{x:14,y:3,w:5,h:10,c:"#16A34A"},{x:14,y:3,w:5,h:2,c:"#15803D"},{x:20,y:4,w:3,h:9,c:"#9333EA"},{x:20,y:4,w:3,h:2,c:"#7E22CE"},{x:24,y:3,w:4,h:10,c:"#D97706"},{x:24,y:3,w:4,h:2,c:"#B45309"},{x:29,y:4,w:3,h:9,c:"#0891B2"},{x:29,y:4,w:3,h:2,c:"#0E7490"},{x:33,y:3,w:5,h:10,c:"#BE123C"},{x:33,y:3,w:5,h:2,c:"#9F1239"},{x:39,y:4,w:4,h:9,c:"#4F46E5"},{x:39,y:4,w:4,h:2,c:"#3730A3"},{x:44,y:3,w:3,h:10,c:"#065F46"},{x:44,y:3,w:3,h:2,c:"#064E3B"},{x:48,y:4,w:4,h:9,c:"#92400E"},{x:48,y:4,w:4,h:2,c:"#78350F"},{x:53,y:3,w:5,h:10,c:"#1E3A5F"},{x:53,y:3,w:5,h:2,c:"#1e3060"},{x:6,y:6,w:2,h:1,c:"#BFDBFE",a:.7},{x:11,y:7,w:1,h:1,c:"#FCA5A5",a:.7},{x:16,y:6,w:3,h:1,c:"#BBF7D0",a:.7},{x:21,y:7,w:1,h:1,c:"#D8B4FE",a:.7},{x:25,y:6,w:2,h:1,c:"#FDE68A",a:.7},{x:5,y:16,w:5,h:11,c:"#0F766E"},{x:5,y:16,w:5,h:2,c:"#0D6056"},{x:11,y:17,w:3,h:10,c:"#C2410C"},{x:11,y:17,w:3,h:2,c:"#9A3412"},{x:15,y:16,w:4,h:11,c:"#7C3AED"},{x:15,y:16,w:4,h:2,c:"#6D28D9"},{x:20,y:17,w:3,h:10,c:"#1D4ED8"},{x:20,y:17,w:3,h:2,c:"#1E40AF"},{x:24,y:16,w:5,h:11,c:"#166534"},{x:24,y:16,w:5,h:2,c:"#14532D"},{x:30,y:17,w:4,h:10,c:"#991B1B"},{x:30,y:17,w:4,h:2,c:"#7F1D1D"},{x:35,y:16,w:3,h:11,c:"#854D0E"},{x:35,y:16,w:3,h:2,c:"#713F12"},{x:39,y:17,w:4,h:10,c:"#1E40AF"},{x:39,y:17,w:4,h:2,c:"#1E3A8A"},{x:44,y:16,w:5,h:11,c:"#065F46"},{x:44,y:16,w:5,h:2,c:"#064E3B"},{x:50,y:17,w:3,h:10,c:"#831843"},{x:50,y:17,w:3,h:2,c:"#6B21A8"},{x:54,y:16,w:5,h:11,c:"#374151"},{x:54,y:16,w:5,h:2,c:"#1F2937"},{x:5,y:30,w:4,h:11,c:"#0E7490"},{x:5,y:30,w:4,h:2,c:"#0C6B7E"},{x:10,y:31,w:3,h:10,c:"#B45309"},{x:10,y:31,w:3,h:2,c:"#92400E"},{x:14,y:30,w:5,h:11,c:"#6D28D9"},{x:14,y:30,w:5,h:2,c:"#5B21B6"},{x:20,y:30,w:7,h:8,c:"#1e293b"},{x:22,y:32,w:3,h:3,c:"#3b82f6",a:.9},{x:22,y:32,w:1,h:3,c:"#60a5fa",a:.6},{x:28,y:31,w:4,h:10,c:"#DC2626"},{x:28,y:31,w:4,h:2,c:"#B91C1C"},{x:33,y:30,w:3,h:11,c:"#065F46"},{x:33,y:30,w:3,h:2,c:"#064E3B"},{x:37,y:31,w:4,h:10,c:"#1D4ED8"},{x:37,y:31,w:4,h:2,c:"#1E40AF"},{x:42,y:35,w:6,h:6,c:"#92400E"},{x:43,y:30,w:4,h:6,c:"#16a34a",a:.8},{x:43,y:29,w:2,h:3,c:"#15803d",a:.7},{x:45,y:28,w:2,h:4,c:"#16a34a",a:.6},{x:49,y:30,w:3,h:11,c:"#7C3AED"},{x:49,y:30,w:3,h:2,c:"#6D28D9"},{x:53,y:31,w:5,h:10,c:"#B45309"},{x:53,y:31,w:5,h:2,c:"#92400E"},{x:2,y:46,w:60,h:2,c:"#1a0a03"},{x:2,y:0,w:60,h:2,c:"#4a2510"},{x:2,y:0,w:2,h:48,c:"#2d1508"},{x:60,y:0,w:2,h:48,c:"#2d1508"}]},eS={canvasWidth:96,canvasHeight:120,scale:2,pixels:[{x:2,y:0,w:44,h:60,c:"#546E7A"},{x:2,y:0,w:44,h:3,c:"#78909C"},{x:2,y:57,w:44,h:3,c:"#37474F"},{x:2,y:0,w:2,h:60,c:"#455A64"},{x:44,y:0,w:2,h:60,c:"#37474F"},{x:5,y:4,w:38,h:3,c:"#FFD54F",a:.5},{x:6,y:1,w:2,h:4,c:"#FFFDE7"},{x:10,y:0,w:2,h:5,c:"#FFF9C4"},{x:14,y:1,w:2,h:3,c:"#FFFDE7"},{x:18,y:0,w:2,h:4,c:"#FFF8E1"},{x:5,y:5,w:38,h:16,c:"#607D8B"},{x:5,y:5,w:38,h:2,c:"#78909C"},{x:15,y:12,w:18,h:4,c:"#37474F"},{x:22,y:11,w:4,h:6,c:"#455A64"},{x:23,y:13,w:2,h:2,c:"#B0BEC5"},{x:7,y:14,w:8,h:5,c:"#B0BEC5"},{x:8,y:15,w:6,h:1,c:"#607D8B"},{x:8,y:17,w:5,h:1,c:"#607D8B"},{x:5,y:23,w:38,h:16,c:"#607D8B"},{x:5,y:23,w:38,h:2,c:"#78909C"},{x:15,y:30,w:18,h:4,c:"#37474F"},{x:22,y:29,w:4,h:6,c:"#455A64"},{x:23,y:31,w:2,h:2,c:"#B0BEC5"},{x:7,y:32,w:8,h:5,c:"#B0BEC5"},{x:8,y:33,w:6,h:1,c:"#607D8B"},{x:8,y:35,w:4,h:1,c:"#607D8B"},{x:5,y:41,w:38,h:16,c:"#607D8B"},{x:5,y:41,w:38,h:2,c:"#78909C"},{x:15,y:48,w:18,h:4,c:"#37474F"},{x:22,y:47,w:4,h:6,c:"#455A64"},{x:23,y:49,w:2,h:2,c:"#B0BEC5"},{x:7,y:50,w:8,h:5,c:"#B0BEC5"},{x:8,y:51,w:6,h:1,c:"#607D8B"},{x:8,y:53,w:3,h:1,c:"#607D8B"}]};Yc("meeting",Zj);Yc("bulletin",Jj);Yc("decision",eS);Yc("knowledge",Pj);const pf=16,yf=24,tS=60,nS={cbo:0,cto:8,pm:15,engineer:22,designer:5,qa:12};function sg(t,l){if(!t)return t;let r=t;if(l!=null&&l.hairStyle){const i=Mj(l.hairStyle);i&&(r=Aj(r,i.layer))}if(l!=null&&l.outfitStyle){const i=Fj(l.outfitStyle);i&&(r=Kf(r,"torso",i.layer,1))}if(l!=null&&l.accessory&&l.accessory!=="none"){const i=Rj(l.accessory);i&&(r=Kf(r,"accessory",i.layer))}return r}function _s({roleId:t,className:l,appearance:r,scale:i}){const c=k.useRef(null),u=k.useRef(0),d=k.useRef(0),m=k.useRef(r);m.current=r;const x=i??4,f=pf*x,g=yf*x,y=k.useMemo(()=>{const b=Wf(`mini:${t}`)??Wf("mini:default");return sg(b,r)},[t,r==null?void 0:r.hairStyle,r==null?void 0:r.outfitStyle,r==null?void 0:r.accessory]);return k.useEffect(()=>{const b=c.current;if(!b)return;const v=b.getContext("2d");if(!v)return;const S=nS[t]??0,j=()=>{d.current++;const E=m.current;if(!E||!y){u.current=requestAnimationFrame(j);return}const A=(d.current+S)%tS<30?1:0;v.clearRect(0,0,pf,yf),v.save(),v.translate(2,1),Tj(v,y,A,E,1),v.restore(),u.current=requestAnimationFrame(j)};return u.current=requestAnimationFrame(j),()=>cancelAnimationFrame(u.current)},[t,y]),s.jsx("canvas",{ref:c,width:pf,height:yf,className:l,style:{imageRendering:"pixelated",display:"block",width:f,height:g}})}const lS="https://api.tycono.ai",Eh=lS;async function cc(t){const l=await fetch(`${Eh}${t}`);if(!l.ok)throw new Error(`Cloud API error: ${l.status}`);return l.json()}async function uc(t,l){const r=await fetch(`${Eh}${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!r.ok)throw new Error(`Cloud API error: ${r.status}`);return r.json()}const xi={health:()=>cc("/api/health"),getCharacters:()=>cc("/api/store/characters"),getCharacter:t=>cc(`/api/store/characters/${t}`),getCharacterVersion:t=>cc(`/api/store/characters/${t}/version`),syncCheck:t=>uc("/api/sync/check",{roles:t}),syncPull:t=>uc("/api/sync/pull",{sourceId:t}),publishCharacter:t=>uc("/api/store/publish",t),deleteCharacter:t=>fetch(`${Eh}/api/store/characters/${t}`,{method:"DELETE"}).then(l=>l.json()),uploadTelemetry:t=>uc("/api/telemetry",t)},rS={cto:"🏗️",cbo:"📊",pm:"📋",engineer:"⚙️",designer:"🎨",qa:"🔍"},gf={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C"},aS={cto:"Chief Technology Officer",cbo:"Chief Business Officer",pm:"Product Manager",engineer:"Software Engineer",designer:"UI/UX Designer",qa:"QA Engineer"},iS=500,d0=360,f0=700,sS=t=>`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`;function oS({role:t,allRoles:l,recentActivity:r,onClose:i,onFireRole:c,terminalWidth:u=0,activeJobId:d,activeTask:m,isWorking:x,jobStartedAt:f,onStopJob:g,sessions:y,streamingSessionId:b,onCreateSessionSilent:v,onSendMessage:S,onFocusTerminal:j,onCustomize:E,onUpdateRole:C,appearance:A,relationships:M,roleLevel:B}){var Fe,Ye;const[$,_]=k.useState(iS),[V,G]=k.useState(!1),Y=k.useRef(0),T=k.useRef(0),[U,O]=k.useState(!1),[J,ne]=k.useState(!1),[K,I]=k.useState(!1),[W,me]=k.useState(!1),[Se,D]=k.useState("talk"),[F,Q]=k.useState(!1),[z,ce]=k.useState(""),[Ee,ge]=k.useState(!1),Ae=k.useRef(null),{events:De,status:He}=K0(d??null),[ye,We]=k.useState(0);k.useEffect(()=>{if(!x||!f){We(0);return}const xe=new Date(f).getTime(),q=()=>We(Math.floor((Date.now()-xe)/1e3));q();const Te=setInterval(q,1e3);return()=>clearInterval(Te)},[x,f]);const de=u>0,fe=de?u:0,be=de?Math.max(d0,window.innerWidth-u-100):f0,Ce=Math.min($,be),ze=k.useCallback(xe=>{xe.preventDefault(),Y.current=xe.clientX,T.current=Ce,G(!0);const q=$e=>{const Ke=Y.current-$e.clientX,mt=Math.min(f0,Math.max(d0,T.current+Ke));_(mt)},Te=()=>{G(!1),document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",Te)};document.addEventListener("mousemove",q),document.addEventListener("mouseup",Te)},[Ce]),_e=k.useRef(null),Me=t?y.find(xe=>xe.roleId===t.id):null,ve=xe=>{if(!t)return;const q=x?"talk":Se;Me?(S(Me.id,xe,q),j(t.id)):(_e.current={content:xe,mode:q},v(t.id))};k.useEffect(()=>{if(Me&&_e.current){const{content:xe,mode:q}=_e.current;_e.current=null,S(Me.id,xe,q),t&&j(t.id)}},[Me==null?void 0:Me.id]);const Oe=(()=>{if(!De.length)return null;const xe=[];let q=0,Te=0,$e=0;for(const Ke of De)if(Ke.type==="thinking")q++;else if(Ke.type==="text")Te++;else if(Ke.type==="tool:start"){const mt=String(Ke.data.name??"");xe.includes(mt)||xe.push(mt)}else Ke.type==="dispatch:start"&&$e++;return{tools:xe,thinkCount:q,textCount:Te,dispatchCount:$e,total:De.length}})(),Je=m||(()=>{if(!Me)return null;const xe=Me.messages;for(let q=xe.length-1;q>=0;q--)if(xe[q].from==="ceo")return xe[q].content;return null})(),jt=(()=>{if(!Me)return null;const xe=Me.messages;for(let q=xe.length-1;q>=0;q--)if(xe[q].from==="role"&&xe[q].content)return xe[q].content;return null})();if(!t)return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"dimmer fixed top-0 left-0 bottom-0 bg-black/30 z-40 open",style:{right:fe},onClick:i}),s.jsx("div",{className:"side-panel open fixed top-0 h-full z-50 flex items-center justify-center border-l-[3px]",style:{right:fe,width:Ce,background:"var(--terminal-bg)",borderLeftColor:"var(--pixel-border)"},children:s.jsx("div",{className:"text-sm",style:{color:"var(--terminal-text-muted)"},children:"Loading role..."})})]});const $t=gf[t.id]??"#666",yt=rS[t.id]??"👤",Xt=l.filter(xe=>xe.reportsTo===t.id),re=Me&&b===Me.id,he=t.name||aS[t.id]||t.id;return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"dimmer fixed top-0 left-0 bottom-0 bg-black/30 z-40 open",style:{right:fe},onClick:i}),s.jsxs("div",{className:`side-panel open fixed top-0 h-full z-50 flex flex-col border-l-[3px] shadow-[-4px_0_20px_rgba(0,0,0,0.4)] ${V?"resizing":""}`,style:{borderLeftColor:$t,right:fe,width:Ce,background:"var(--terminal-bg)"},children:[s.jsx("div",{className:`absolute top-0 -left-[5px] w-[10px] h-full cursor-col-resize z-[60] transition-colors ${V?"bg-white/10":"hover:bg-white/5"}`,onMouseDown:ze}),s.jsxs("div",{className:"relative shrink-0 overflow-hidden",style:{background:`linear-gradient(135deg, ${$t}ee, ${$t}99)`},children:[s.jsx("div",{className:"absolute inset-0 opacity-[0.06]",style:{backgroundImage:"repeating-linear-gradient(45deg, transparent, transparent 8px, white 8px, white 9px)"}}),s.jsxs("div",{className:"absolute top-3 right-3 flex items-center gap-1.5 z-10",children:[E&&s.jsx("button",{onClick:()=>E(t.id),className:"w-7 h-7 rounded-full bg-black/20 text-white flex items-center justify-center text-sm hover:bg-black/30 cursor-pointer backdrop-blur-sm",title:"Customize",children:"🎨"}),s.jsx("button",{onClick:i,className:"w-7 h-7 rounded-full bg-black/20 text-white flex items-center justify-center text-lg hover:bg-black/30 cursor-pointer backdrop-blur-sm",children:"×"})]}),s.jsxs("div",{className:"relative flex items-end gap-4 px-4 pt-4 pb-3",children:[s.jsx("div",{className:"shrink-0 relative",style:{marginBottom:-2},children:s.jsx("div",{className:"rounded-lg p-1",style:{background:"rgba(0,0,0,0.2)"},children:s.jsx(_s,{roleId:t.id,appearance:A,scale:8})})}),s.jsxs("div",{className:"flex-1 min-w-0 text-white pb-1",children:[s.jsxs("div",{className:"text-lg font-bold flex items-center gap-2",style:{fontFamily:"var(--pixel-font)"},children:[yt," ",t.id.toUpperCase(),x&&s.jsx("span",{className:"text-[9px] font-semibold px-2 py-0.5 rounded-full animate-pulse",style:{background:"rgba(251,191,36,0.25)",color:"#fde68a"},children:"WORKING"})]}),F?s.jsxs("form",{className:"flex items-center gap-1.5 mt-0.5",onSubmit:async xe=>{xe.preventDefault();const q=z.trim();if(!q||q===he||!C){Q(!1);return}ge(!0);try{await C(t.id,{name:q})}catch{}ge(!1),Q(!1)},children:[s.jsx("input",{ref:Ae,value:z,onChange:xe=>ce(xe.target.value),onKeyDown:xe=>{xe.key==="Escape"&&Q(!1)},disabled:Ee,autoFocus:!0,className:"bg-white/20 text-white text-xs rounded px-1.5 py-0.5 outline-none focus:bg-white/30 w-full",style:{fontFamily:"inherit"}}),s.jsx("button",{type:"submit",disabled:Ee,className:"text-white/80 hover:text-white text-[10px] cursor-pointer shrink-0",children:"✓"}),s.jsx("button",{type:"button",onClick:()=>Q(!1),className:"text-white/60 hover:text-white text-[10px] cursor-pointer shrink-0",children:"✕"})]}):s.jsxs("div",{className:"text-xs opacity-75 mt-0.5 group/name flex items-center gap-1 cursor-pointer hover:opacity-100 transition-opacity",onClick:()=>{C&&(ce(he),Q(!0))},title:C?"Click to edit name":void 0,children:[he,C&&s.jsx("span",{className:"opacity-0 group-hover/name:opacity-60 text-[10px]",children:"✎"})]})]})]}),s.jsxs("div",{className:"relative flex items-center gap-3 px-4 py-2 text-[10px] font-bold text-white/80",style:{background:"rgba(0,0,0,0.2)",fontFamily:"var(--pixel-font)"},children:[s.jsxs("span",{children:["Lv.",B??1]}),s.jsx("span",{style:{color:"rgba(255,255,255,0.3)"},children:"|"}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"w-2 h-2 rounded-full",style:{background:x?"var(--idle-amber)":"var(--active-green)"}}),x?"Working":"Idle"]}),s.jsx("span",{style:{color:"rgba(255,255,255,0.3)"},children:"|"}),s.jsx("span",{children:t.level}),t.reportsTo&&s.jsxs(s.Fragment,{children:[s.jsx("span",{style:{color:"rgba(255,255,255,0.3)"},children:"|"}),s.jsxs("span",{className:"opacity-60",children:["→"," ",t.reportsTo]})]})]})]}),s.jsxs("div",{className:"flex-1 overflow-y-auto flex flex-col min-h-0",children:[x&&s.jsxs("div",{className:"px-4 py-3 shrink-0",style:{borderBottom:"1px solid var(--terminal-border)",background:"var(--hud-bg-alt)"},children:[s.jsxs("div",{className:"flex items-center justify-between mb-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"w-2 h-2 rounded-full animate-pulse",style:{background:"var(--idle-amber)"}}),s.jsxs("span",{className:"text-xs font-semibold",style:{color:"var(--idle-amber)"},children:["Working",ye>0?` · ${sS(ye)}`:""]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("button",{onClick:()=>j(t.id),className:"text-[10px] cursor-pointer hover:underline",style:{color:"var(--terminal-text-muted)"},children:"Open chat ↗"}),d&&g&&s.jsx("button",{onClick:()=>g(d),className:"text-[10px] px-2 py-0.5 rounded cursor-pointer font-semibold transition-colors",style:{background:"rgba(239,68,68,0.15)",color:"#ef4444"},children:"Stop"})]})]}),Je&&s.jsx("div",{className:"text-xs truncate",style:{color:"var(--terminal-text-secondary)"},children:Je})]}),x&&d&&Oe&&s.jsxs("div",{className:"px-4 py-2.5 shrink-0",style:{borderBottom:"1px solid var(--terminal-border)"},children:[s.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[s.jsx("div",{className:"text-[11px] font-bold uppercase tracking-wider",style:{color:"var(--terminal-text-secondary)"},children:"Activity"}),s.jsx("button",{onClick:()=>j(t.id),className:"text-[10px] cursor-pointer hover:underline",style:{color:"var(--terminal-text-muted)"},children:"View details ↗"})]}),s.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[Oe.thinkCount>0&&s.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px]",style:{background:"rgba(168,85,247,0.15)",color:"#c084fc"},children:[s.jsx("span",{className:"w-1.5 h-1.5 rounded-full",style:{background:"#a855f7"}}),"thinking ×",Oe.thinkCount]}),Oe.tools.map(xe=>s.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px]",style:{background:"rgba(59,130,246,0.15)",color:"#60a5fa"},children:xe},xe)),Oe.dispatchCount>0&&s.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[10px]",style:{background:"rgba(249,115,22,0.15)",color:"#fb923c"},children:["dispatch ×",Oe.dispatchCount]}),Oe.textCount>0&&s.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[10px]",style:{background:"rgba(34,197,94,0.15)",color:"#4ade80"},children:["output ×",Oe.textCount]}),(He==="streaming"||He==="connecting")&&s.jsx("span",{className:"inline-block w-1.5 h-3 animate-pulse rounded-sm",style:{background:"var(--active-green)"}})]}),s.jsxs("div",{className:"text-[10px] mt-1",style:{color:"var(--terminal-text-muted)"},children:[Oe.total," events"]})]}),x&&jt&&s.jsxs("div",{className:"px-4 py-2.5 shrink-0",style:{borderBottom:"1px solid var(--terminal-border)"},children:[s.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[s.jsx("div",{className:"text-[11px] font-bold uppercase tracking-wider",style:{color:"var(--terminal-text-secondary)"},children:"Last Message"}),s.jsx("button",{onClick:()=>j(t.id),className:"text-[10px] cursor-pointer hover:underline",style:{color:"var(--terminal-text-muted)"},children:"Open chat ↗"})]}),s.jsxs("div",{className:"rounded-lg p-2.5 text-xs leading-relaxed line-clamp-3 overflow-hidden",style:{background:"var(--hud-bg-alt)",border:"1px solid var(--terminal-border)",color:"var(--terminal-text-secondary)"},children:[jt.slice(0,200),jt.length>200&&"..."]})]}),x&&s.jsx("div",{className:"px-4 py-2.5 shrink-0",style:{borderBottom:"1px solid var(--terminal-border)"},children:s.jsx(h0,{onSend:ve,disabled:!!re,placeholder:"Ask something...",color:$t})}),!x&&s.jsxs("div",{className:"px-4 pt-4 pb-2",children:[s.jsx("div",{className:"text-[11px] font-bold uppercase tracking-wider mb-2",style:{color:"var(--terminal-text-secondary)"},children:"Latest"}),s.jsx(uS,{icon:yt,roleId:t.id,roleName:he,color:$t,text:r})]}),!x&&s.jsx("div",{className:"px-4 py-3",style:{borderBottom:"1px solid var(--terminal-border)"},children:s.jsxs("div",{className:"rounded-xl overflow-hidden",style:{background:"var(--hud-bg-alt)",border:"1px solid var(--terminal-border)"},children:[jt&&s.jsxs("div",{className:"px-3 pt-2.5 pb-2 cursor-pointer transition-colors",style:{borderBottom:"1px solid var(--terminal-border)"},onClick:()=>j(t.id),children:[s.jsxs("div",{className:"flex items-center justify-between mb-1",children:[s.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--terminal-text-muted)"},children:"Last response"}),s.jsx("span",{className:"text-[10px]",style:{color:"var(--terminal-text-muted)"},children:"View ↗"})]}),s.jsxs("div",{className:"text-xs leading-relaxed line-clamp-2 overflow-hidden",style:{color:"var(--terminal-text-secondary)"},children:[jt.slice(0,150),jt.length>150&&"..."]})]}),s.jsx("div",{className:"p-2",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"flex rounded-lg overflow-hidden shrink-0",style:{border:"1px solid var(--pixel-border)"},children:[s.jsx("button",{onClick:()=>D("talk"),className:"px-2 py-1 text-[10px] font-semibold cursor-pointer transition-colors",style:{background:Se==="talk"?"var(--accent)":"transparent",color:Se==="talk"?"#fff":"var(--terminal-text-secondary)"},children:"Talk"}),s.jsx("button",{onClick:()=>D("do"),className:"px-2 py-1 text-[10px] font-semibold cursor-pointer transition-colors",style:{background:Se==="do"?"var(--idle-amber)":"transparent",color:Se==="do"?"#fff":"var(--terminal-text-secondary)"},children:"Do"})]}),s.jsx(h0,{onSend:ve,disabled:!!re,placeholder:Se==="talk"?"Ask something...":"Give a directive...",color:$t})]})})]})}),s.jsxs("div",{className:"px-4 py-2 space-y-1",children:[s.jsxs(dc,{title:`Profile${t.persona?"":" (empty)"}`,open:U,onToggle:()=>O(xe=>!xe),children:[t.persona&&s.jsx("div",{className:"text-xs leading-relaxed rounded-lg p-3",style:{background:"var(--hud-bg-alt)",border:"1px solid var(--terminal-border)",color:"var(--terminal-text-secondary)"},children:t.persona}),s.jsxs("div",{className:"space-y-0 mt-2",children:[s.jsx(bf,{label:"Level",value:t.level}),s.jsx(bf,{label:"Reports to",value:t.reportsTo}),s.jsx(bf,{label:"Status",value:t.status})]}),Xt.length>0&&s.jsxs("div",{className:"mt-3",children:[s.jsx("div",{className:"text-[11px] font-semibold mb-1",style:{color:"var(--terminal-text-muted)"},children:"Direct Reports"}),s.jsx("div",{className:"space-y-1",children:Xt.map(xe=>s.jsxs("div",{className:"flex items-center gap-2 p-1.5 rounded-lg",style:{background:"var(--hud-bg-alt)"},children:[s.jsx("div",{className:"w-6 h-6 rounded flex items-center justify-center text-white text-[10px] font-bold",style:{background:gf[xe.id]??"#666"},children:xe.id.slice(0,2).toUpperCase()}),s.jsx("div",{className:"text-xs",style:{color:"var(--terminal-text)"},children:xe.name})]},xe.id))})]})]}),t.authority&&s.jsxs(dc,{title:"Authority",open:J,onToggle:()=>ne(xe=>!xe),children:[((Fe=t.authority.autonomous)==null?void 0:Fe.length)>0&&s.jsxs("div",{className:"mb-2",children:[s.jsx("div",{className:"text-xs font-semibold mb-1",style:{color:"var(--active-green)"},children:"Autonomous"}),t.authority.autonomous.map((xe,q)=>s.jsxs("div",{className:"text-xs pl-3 py-0.5",style:{color:"var(--terminal-text-secondary)"},children:["- ",xe]},q))]}),((Ye=t.authority.needsApproval)==null?void 0:Ye.length)>0&&s.jsxs("div",{children:[s.jsx("div",{className:"text-xs font-semibold mb-1",style:{color:"var(--idle-amber)"},children:"Needs Approval"}),t.authority.needsApproval.map((xe,q)=>s.jsxs("div",{className:"text-xs pl-3 py-0.5",style:{color:"var(--terminal-text-secondary)"},children:["- ",xe]},q))]})]}),t&&M&&(()=>{const xe=M.filter(q=>q.roleA===t.id||q.roleB===t.id).filter(q=>q.familiarity>0).sort((q,Te)=>Te.familiarity-q.familiarity);return xe.length===0?null:s.jsx(dc,{title:`Relationships (${xe.length})`,open:K,onToggle:()=>I(q=>!q),children:s.jsx("div",{className:"space-y-1.5",children:xe.map((q,Te)=>{const $e=q.roleA===t.id?q.roleB:q.roleA,Ke=l.find(It=>It.id===$e),mt=q.familiarity>=80?"Best Partner":q.familiarity>=50?"Friend":q.familiarity>=20?"Colleague":"Acquaintance",Qe=q.familiarity>=80?"#4CAF50":q.familiarity>=50?"#2196F3":q.familiarity>=20?"#FF9800":"#9E9E9E";return s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-xs w-20 truncate",style:{color:gf[$e]??"var(--terminal-text-secondary)"},children:(Ke==null?void 0:Ke.name)??$e}),s.jsx("div",{className:"flex-1 h-1.5 rounded-full bg-white/10",children:s.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${q.familiarity}%`,background:Qe}})}),s.jsx("span",{className:"text-[10px] w-16 text-right",style:{color:"var(--terminal-text-muted)"},children:mt})]},Te)})})})})(),t.journal&&s.jsx(dc,{title:`Journal (${(t.journal.match(/### /g)??[]).length})`,open:W,onToggle:()=>me(xe=>!xe),children:s.jsxs("div",{className:"text-xs leading-relaxed rounded-lg p-3 max-h-[300px] overflow-y-auto",style:{background:"var(--hud-bg-alt)",border:"1px solid var(--terminal-border)",color:"var(--terminal-text-secondary)"},children:[s.jsx(Is,{content:t.journal.slice(0,3e3)}),t.journal.length>3e3&&s.jsx("div",{className:"italic mt-2",style:{color:"var(--terminal-text-muted)"},children:"... (truncated)"})]})})]}),s.jsx(cS,{role:t,appearance:A}),c&&s.jsx("div",{className:"px-4 pb-4 mt-auto shrink-0",children:s.jsx("button",{onClick:()=>{c(t.id,t.name),i()},className:"w-full p-2 text-center text-xs font-medium border-2 border-dashed rounded-lg cursor-pointer transition-colors",style:{borderColor:"rgba(239,68,68,0.3)",color:"rgba(239,68,68,0.5)"},children:"Fire Role"})})]})]})]})}function cS({role:t,appearance:l}){const[r,i]=k.useState("idle"),[c,u]=k.useState(""),[d,m]=k.useState(!1),x=async()=>{var f,g;if(!d){m(!0);return}i("publishing");try{let y=null;try{y=await Ne.exportSkills(t.id)}catch{}const b={roleId:t.id,persona:t.persona??"",authority:t.authority??{autonomous:[],needsApproval:[]},level:t.level,tagline:((f=(t.persona??"").split(/[.\n]/)[0])==null?void 0:f.trim().slice(0,80))||t.name,chatStyle:"Professional and focused",skills:y??[],resume:{summary:((g=t.persona)==null?void 0:g.split(`
80
80
  `)[0])??"",strengths:[],specialties:[],experience:""},author:{id:"tycono",name:"Tycono"},tags:[t.level,t.id],price:"free",installs:0,rating:0,featured:!1,randomActive:!0,randomPersonality:""};l&&(b.appearance=l);let v="1.0.0";try{const S=await xi.getCharacterVersion(t.id);if(S!=null&&S.version){const j=S.version.split(".").map(Number);j[2]=(j[2]??0)+1,v=j.join(".")}}catch{}await xi.publishCharacter({id:t.id,name:t.name||t.id,version:v,data:b}),i("done"),u(`Published v${v}`),m(!1)}catch(y){i("error"),u(y instanceof Error?y.message:"Failed"),m(!1)}};return s.jsx("div",{className:"px-4 pb-2 shrink-0",children:s.jsx("div",{className:"rounded-lg overflow-hidden",style:{border:"1px solid var(--terminal-border)"},children:s.jsxs("div",{className:"px-3 py-2.5 flex items-center justify-between",style:{background:"var(--hud-bg-alt)"},children:[s.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",style:{color:"var(--terminal-text-secondary)",fontFamily:"var(--pixel-font)"},children:"Cloud Store"}),r==="done"?s.jsx("span",{className:"text-[10px] font-semibold",style:{color:"var(--active-green)"},children:c}):r==="error"?s.jsx("span",{className:"text-[10px] font-semibold",style:{color:"#ef4444"},children:c}):s.jsx("button",{onClick:x,disabled:r==="publishing",className:"text-[10px] px-2.5 py-1 rounded font-semibold cursor-pointer transition-colors disabled:opacity-50",style:{background:d?"rgba(59,130,246,0.3)":"rgba(59,130,246,0.15)",color:"#60a5fa",border:d?"1px solid rgba(59,130,246,0.5)":"1px solid transparent"},children:r==="publishing"?"Publishing...":d?"Confirm Publish?":"Publish to Store"})]})})})}function uS({icon:t,roleId:l,roleName:r,color:i,text:c}){const u=!!c;return s.jsx("div",{className:"relative",children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsxs("div",{className:"shrink-0",children:[s.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center text-xl shadow-sm",style:{background:`${i}18`,border:`2px solid ${i}44`},children:t}),s.jsx("div",{className:"text-[9px] font-bold text-center mt-0.5 uppercase tracking-wide",style:{color:i},children:l})]}),s.jsx("div",{className:"flex-1 min-w-0",children:s.jsxs("div",{className:"relative",children:[s.jsx("div",{className:"absolute top-3 -left-2 w-0 h-0",style:{borderTop:"6px solid transparent",borderBottom:"6px solid transparent",borderRight:`8px solid ${i}12`}}),s.jsxs("div",{className:"rounded-xl rounded-tl-sm p-4 border",style:{background:`${i}08`,borderColor:`${i}22`},children:[s.jsx("div",{className:"text-[10px] font-semibold mb-1.5 uppercase tracking-wider",style:{color:i},children:r}),u?s.jsx("div",{className:"text-sm leading-relaxed",style:{color:"var(--terminal-text)"},children:s.jsx(Is,{content:c})}):s.jsx("div",{className:"text-sm italic",style:{color:"var(--terminal-text-muted)"},children:"No recent activity."})]})]})})]})})}function dc({title:t,open:l,onToggle:r,children:i}){return s.jsxs("div",{className:"rounded-lg overflow-hidden",style:{border:"1px solid var(--terminal-border)"},children:[s.jsxs("button",{onClick:r,className:"w-full px-3 py-2.5 flex items-center justify-between cursor-pointer transition-colors group",style:{background:"var(--hud-bg-alt)"},children:[s.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",style:{color:"var(--terminal-text-secondary)",fontFamily:"var(--pixel-font)"},children:t}),s.jsx("span",{className:"text-[10px] transition-transform",style:{color:"var(--terminal-text-muted)",transform:l?"rotate(0deg)":"rotate(-90deg)"},children:"▼"})]}),l&&s.jsx("div",{className:"px-3 pb-3 pt-2",style:{borderTop:"1px solid var(--terminal-border)"},children:i})]})}function h0({onSend:t,disabled:l,placeholder:r,color:i}){const[c,u]=k.useState(""),d=()=>{const m=c.trim();!m||l||(t(m),u(""))};return s.jsxs("div",{className:"flex items-center gap-1.5 flex-1",children:[s.jsx("input",{type:"text",value:c,onChange:m=>u(m.target.value),onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),d())},placeholder:l?"Waiting...":r,disabled:l,className:"flex-1 rounded-lg px-2.5 py-1.5 text-xs focus:outline-none disabled:opacity-40",style:{background:"var(--hud-bg)",border:"1px solid var(--pixel-border)",color:"var(--terminal-text)"}}),s.jsx("button",{onClick:d,disabled:l||!c.trim(),className:"w-7 h-7 rounded-lg flex items-center justify-center shrink-0 cursor-pointer text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",style:{background:l||!c.trim()?"#666":i},children:s.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("path",{d:"M22 2L11 13"}),s.jsx("path",{d:"M22 2L15 22L11 13L2 9L22 2Z"})]})})]})}function bf({label:t,value:l}){return s.jsxs("div",{className:"flex justify-between py-1.5 text-xs",style:{borderBottom:"1px solid var(--terminal-border)"},children:[s.jsx("span",{style:{color:"var(--terminal-text-muted)"},children:t}),s.jsx("span",{className:"font-semibold",style:{color:"var(--terminal-text)"},children:l})]})}function dS(t,l){var r,i=1;t==null&&(t=0),l==null&&(l=0);function c(){var u,d=r.length,m,x=0,f=0;for(u=0;u<d;++u)m=r[u],x+=m.x,f+=m.y;for(x=(x/d-t)*i,f=(f/d-l)*i,u=0;u<d;++u)m=r[u],m.x-=x,m.y-=f}return c.initialize=function(u){r=u},c.x=function(u){return arguments.length?(t=+u,c):t},c.y=function(u){return arguments.length?(l=+u,c):l},c.strength=function(u){return arguments.length?(i=+u,c):i},c}function fS(t){const l=+this._x.call(null,t),r=+this._y.call(null,t);return og(this.cover(l,r),l,r,t)}function og(t,l,r,i){if(isNaN(l)||isNaN(r))return t;var c,u=t._root,d={data:i},m=t._x0,x=t._y0,f=t._x1,g=t._y1,y,b,v,S,j,E,C,A;if(!u)return t._root=d,t;for(;u.length;)if((j=l>=(y=(m+f)/2))?m=y:f=y,(E=r>=(b=(x+g)/2))?x=b:g=b,c=u,!(u=u[C=E<<1|j]))return c[C]=d,t;if(v=+t._x.call(null,u.data),S=+t._y.call(null,u.data),l===v&&r===S)return d.next=u,c?c[C]=d:t._root=d,t;do c=c?c[C]=new Array(4):t._root=new Array(4),(j=l>=(y=(m+f)/2))?m=y:f=y,(E=r>=(b=(x+g)/2))?x=b:g=b;while((C=E<<1|j)===(A=(S>=b)<<1|v>=y));return c[A]=u,c[C]=d,t}function hS(t){var l,r,i=t.length,c,u,d=new Array(i),m=new Array(i),x=1/0,f=1/0,g=-1/0,y=-1/0;for(r=0;r<i;++r)isNaN(c=+this._x.call(null,l=t[r]))||isNaN(u=+this._y.call(null,l))||(d[r]=c,m[r]=u,c<x&&(x=c),c>g&&(g=c),u<f&&(f=u),u>y&&(y=u));if(x>g||f>y)return this;for(this.cover(x,f).cover(g,y),r=0;r<i;++r)og(this,d[r],m[r],t[r]);return this}function mS(t,l){if(isNaN(t=+t)||isNaN(l=+l))return this;var r=this._x0,i=this._y0,c=this._x1,u=this._y1;if(isNaN(r))c=(r=Math.floor(t))+1,u=(i=Math.floor(l))+1;else{for(var d=c-r||1,m=this._root,x,f;r>t||t>=c||i>l||l>=u;)switch(f=(l<i)<<1|t<r,x=new Array(4),x[f]=m,m=x,d*=2,f){case 0:c=r+d,u=i+d;break;case 1:r=c-d,u=i+d;break;case 2:c=r+d,i=u-d;break;case 3:r=c-d,i=u-d;break}this._root&&this._root.length&&(this._root=m)}return this._x0=r,this._y0=i,this._x1=c,this._y1=u,this}function xS(){var t=[];return this.visit(function(l){if(!l.length)do t.push(l.data);while(l=l.next)}),t}function pS(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]}function zn(t,l,r,i,c){this.node=t,this.x0=l,this.y0=r,this.x1=i,this.y1=c}function yS(t,l,r){var i,c=this._x0,u=this._y0,d,m,x,f,g=this._x1,y=this._y1,b=[],v=this._root,S,j;for(v&&b.push(new zn(v,c,u,g,y)),r==null?r=1/0:(c=t-r,u=l-r,g=t+r,y=l+r,r*=r);S=b.pop();)if(!(!(v=S.node)||(d=S.x0)>g||(m=S.y0)>y||(x=S.x1)<c||(f=S.y1)<u))if(v.length){var E=(d+x)/2,C=(m+f)/2;b.push(new zn(v[3],E,C,x,f),new zn(v[2],d,C,E,f),new zn(v[1],E,m,x,C),new zn(v[0],d,m,E,C)),(j=(l>=C)<<1|t>=E)&&(S=b[b.length-1],b[b.length-1]=b[b.length-1-j],b[b.length-1-j]=S)}else{var A=t-+this._x.call(null,v.data),M=l-+this._y.call(null,v.data),B=A*A+M*M;if(B<r){var $=Math.sqrt(r=B);c=t-$,u=l-$,g=t+$,y=l+$,i=v.data}}return i}function gS(t){if(isNaN(g=+this._x.call(null,t))||isNaN(y=+this._y.call(null,t)))return this;var l,r=this._root,i,c,u,d=this._x0,m=this._y0,x=this._x1,f=this._y1,g,y,b,v,S,j,E,C;if(!r)return this;if(r.length)for(;;){if((S=g>=(b=(d+x)/2))?d=b:x=b,(j=y>=(v=(m+f)/2))?m=v:f=v,l=r,!(r=r[E=j<<1|S]))return this;if(!r.length)break;(l[E+1&3]||l[E+2&3]||l[E+3&3])&&(i=l,C=E)}for(;r.data!==t;)if(c=r,!(r=r.next))return this;return(u=r.next)&&delete r.next,c?(u?c.next=u:delete c.next,this):l?(u?l[E]=u:delete l[E],(r=l[0]||l[1]||l[2]||l[3])&&r===(l[3]||l[2]||l[1]||l[0])&&!r.length&&(i?i[C]=r:this._root=r),this):(this._root=u,this)}function bS(t){for(var l=0,r=t.length;l<r;++l)this.remove(t[l]);return this}function vS(){return this._root}function wS(){var t=0;return this.visit(function(l){if(!l.length)do++t;while(l=l.next)}),t}function kS(t){var l=[],r,i=this._root,c,u,d,m,x;for(i&&l.push(new zn(i,this._x0,this._y0,this._x1,this._y1));r=l.pop();)if(!t(i=r.node,u=r.x0,d=r.y0,m=r.x1,x=r.y1)&&i.length){var f=(u+m)/2,g=(d+x)/2;(c=i[3])&&l.push(new zn(c,f,g,m,x)),(c=i[2])&&l.push(new zn(c,u,g,f,x)),(c=i[1])&&l.push(new zn(c,f,d,m,g)),(c=i[0])&&l.push(new zn(c,u,d,f,g))}return this}function jS(t){var l=[],r=[],i;for(this._root&&l.push(new zn(this._root,this._x0,this._y0,this._x1,this._y1));i=l.pop();){var c=i.node;if(c.length){var u,d=i.x0,m=i.y0,x=i.x1,f=i.y1,g=(d+x)/2,y=(m+f)/2;(u=c[0])&&l.push(new zn(u,d,m,g,y)),(u=c[1])&&l.push(new zn(u,g,m,x,y)),(u=c[2])&&l.push(new zn(u,d,y,g,f)),(u=c[3])&&l.push(new zn(u,g,y,x,f))}r.push(i)}for(;i=r.pop();)t(i.node,i.x0,i.y0,i.x1,i.y1);return this}function SS(t){return t[0]}function CS(t){return arguments.length?(this._x=t,this):this._x}function ES(t){return t[1]}function NS(t){return arguments.length?(this._y=t,this):this._y}function Nh(t,l,r){var i=new Ah(l??SS,r??ES,NaN,NaN,NaN,NaN);return t==null?i:i.addAll(t)}function Ah(t,l,r,i,c,u){this._x=t,this._y=l,this._x0=r,this._y0=i,this._x1=c,this._y1=u,this._root=void 0}function m0(t){for(var l={data:t.data},r=l;t=t.next;)r=r.next={data:t.data};return l}var Mn=Nh.prototype=Ah.prototype;Mn.copy=function(){var t=new Ah(this._x,this._y,this._x0,this._y0,this._x1,this._y1),l=this._root,r,i;if(!l)return t;if(!l.length)return t._root=m0(l),t;for(r=[{source:l,target:t._root=new Array(4)}];l=r.pop();)for(var c=0;c<4;++c)(i=l.source[c])&&(i.length?r.push({source:i,target:l.target[c]=new Array(4)}):l.target[c]=m0(i));return t};Mn.add=fS;Mn.addAll=hS;Mn.cover=mS;Mn.data=xS;Mn.extent=pS;Mn.find=yS;Mn.remove=gS;Mn.removeAll=bS;Mn.root=vS;Mn.size=wS;Mn.visit=kS;Mn.visitAfter=jS;Mn.x=CS;Mn.y=NS;function va(t){return function(){return t}}function Ir(t){return(t()-.5)*1e-6}function AS(t){return t.x+t.vx}function DS(t){return t.y+t.vy}function TS(t){var l,r,i,c=1,u=1;typeof t!="function"&&(t=va(t==null?1:+t));function d(){for(var f,g=l.length,y,b,v,S,j,E,C=0;C<u;++C)for(y=Nh(l,AS,DS).visitAfter(m),f=0;f<g;++f)b=l[f],j=r[b.index],E=j*j,v=b.x+b.vx,S=b.y+b.vy,y.visit(A);function A(M,B,$,_,V){var G=M.data,Y=M.r,T=j+Y;if(G){if(G.index>b.index){var U=v-G.x-G.vx,O=S-G.y-G.vy,J=U*U+O*O;J<T*T&&(U===0&&(U=Ir(i),J+=U*U),O===0&&(O=Ir(i),J+=O*O),J=(T-(J=Math.sqrt(J)))/J*c,b.vx+=(U*=J)*(T=(Y*=Y)/(E+Y)),b.vy+=(O*=J)*T,G.vx-=U*(T=1-T),G.vy-=O*T)}return}return B>v+T||_<v-T||$>S+T||V<S-T}}function m(f){if(f.data)return f.r=r[f.data.index];for(var g=f.r=0;g<4;++g)f[g]&&f[g].r>f.r&&(f.r=f[g].r)}function x(){if(l){var f,g=l.length,y;for(r=new Array(g),f=0;f<g;++f)y=l[f],r[y.index]=+t(y,f,l)}}return d.initialize=function(f,g){l=f,i=g,x()},d.iterations=function(f){return arguments.length?(u=+f,d):u},d.strength=function(f){return arguments.length?(c=+f,d):c},d.radius=function(f){return arguments.length?(t=typeof f=="function"?f:va(+f),x(),d):t},d}function zS(t){return t.index}function x0(t,l){var r=t.get(l);if(!r)throw new Error("node not found: "+l);return r}function MS(t){var l=zS,r=y,i,c=va(30),u,d,m,x,f,g=1;t==null&&(t=[]);function y(E){return 1/Math.min(m[E.source.index],m[E.target.index])}function b(E){for(var C=0,A=t.length;C<g;++C)for(var M=0,B,$,_,V,G,Y,T;M<A;++M)B=t[M],$=B.source,_=B.target,V=_.x+_.vx-$.x-$.vx||Ir(f),G=_.y+_.vy-$.y-$.vy||Ir(f),Y=Math.sqrt(V*V+G*G),Y=(Y-u[M])/Y*E*i[M],V*=Y,G*=Y,_.vx-=V*(T=x[M]),_.vy-=G*T,$.vx+=V*(T=1-T),$.vy+=G*T}function v(){if(d){var E,C=d.length,A=t.length,M=new Map(d.map(($,_)=>[l($,_,d),$])),B;for(E=0,m=new Array(C);E<A;++E)B=t[E],B.index=E,typeof B.source!="object"&&(B.source=x0(M,B.source)),typeof B.target!="object"&&(B.target=x0(M,B.target)),m[B.source.index]=(m[B.source.index]||0)+1,m[B.target.index]=(m[B.target.index]||0)+1;for(E=0,x=new Array(A);E<A;++E)B=t[E],x[E]=m[B.source.index]/(m[B.source.index]+m[B.target.index]);i=new Array(A),S(),u=new Array(A),j()}}function S(){if(d)for(var E=0,C=t.length;E<C;++E)i[E]=+r(t[E],E,t)}function j(){if(d)for(var E=0,C=t.length;E<C;++E)u[E]=+c(t[E],E,t)}return b.initialize=function(E,C){d=E,f=C,v()},b.links=function(E){return arguments.length?(t=E,v(),b):t},b.id=function(E){return arguments.length?(l=E,b):l},b.iterations=function(E){return arguments.length?(g=+E,b):g},b.strength=function(E){return arguments.length?(r=typeof E=="function"?E:va(+E),S(),b):r},b.distance=function(E){return arguments.length?(c=typeof E=="function"?E:va(+E),j(),b):c},b}var FS={value:()=>{}};function cg(){for(var t=0,l=arguments.length,r={},i;t<l;++t){if(!(i=arguments[t]+"")||i in r||/[\s.]/.test(i))throw new Error("illegal type: "+i);r[i]=[]}return new Sc(r)}function Sc(t){this._=t}function RS(t,l){return t.trim().split(/^|\s+/).map(function(r){var i="",c=r.indexOf(".");if(c>=0&&(i=r.slice(c+1),r=r.slice(0,c)),r&&!l.hasOwnProperty(r))throw new Error("unknown type: "+r);return{type:r,name:i}})}Sc.prototype=cg.prototype={constructor:Sc,on:function(t,l){var r=this._,i=RS(t+"",r),c,u=-1,d=i.length;if(arguments.length<2){for(;++u<d;)if((c=(t=i[u]).type)&&(c=_S(r[c],t.name)))return c;return}if(l!=null&&typeof l!="function")throw new Error("invalid callback: "+l);for(;++u<d;)if(c=(t=i[u]).type)r[c]=p0(r[c],t.name,l);else if(l==null)for(c in r)r[c]=p0(r[c],t.name,null);return this},copy:function(){var t={},l=this._;for(var r in l)t[r]=l[r].slice();return new Sc(t)},call:function(t,l){if((c=arguments.length-2)>0)for(var r=new Array(c),i=0,c,u;i<c;++i)r[i]=arguments[i+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(u=this._[t],i=0,c=u.length;i<c;++i)u[i].value.apply(l,r)},apply:function(t,l,r){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var i=this._[t],c=0,u=i.length;c<u;++c)i[c].value.apply(l,r)}};function _S(t,l){for(var r=0,i=t.length,c;r<i;++r)if((c=t[r]).name===l)return c.value}function p0(t,l,r){for(var i=0,c=t.length;i<c;++i)if(t[i].name===l){t[i]=FS,t=t.slice(0,i).concat(t.slice(i+1));break}return r!=null&&t.push({name:l,value:r}),t}var yi=0,Cs=0,ws=0,ug=1e3,Rc,Es,_c=0,ka=0,qc=0,Os=typeof performance=="object"&&performance.now?performance:Date,dg=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function fg(){return ka||(dg(OS),ka=Os.now()+qc)}function OS(){ka=0}function Zf(){this._call=this._time=this._next=null}Zf.prototype=hg.prototype={constructor:Zf,restart:function(t,l,r){if(typeof t!="function")throw new TypeError("callback is not a function");r=(r==null?fg():+r)+(l==null?0:+l),!this._next&&Es!==this&&(Es?Es._next=this:Rc=this,Es=this),this._call=t,this._time=r,Jf()},stop:function(){this._call&&(this._call=null,this._time=1/0,Jf())}};function hg(t,l,r){var i=new Zf;return i.restart(t,l,r),i}function BS(){fg(),++yi;for(var t=Rc,l;t;)(l=ka-t._time)>=0&&t._call.call(void 0,l),t=t._next;--yi}function y0(){ka=(_c=Os.now())+qc,yi=Cs=0;try{BS()}finally{yi=0,$S(),ka=0}}function LS(){var t=Os.now(),l=t-_c;l>ug&&(qc-=l,_c=t)}function $S(){for(var t,l=Rc,r,i=1/0;l;)l._call?(i>l._time&&(i=l._time),t=l,l=l._next):(r=l._next,l._next=null,l=t?t._next=r:Rc=r);Es=t,Jf(i)}function Jf(t){if(!yi){Cs&&(Cs=clearTimeout(Cs));var l=t-ka;l>24?(t<1/0&&(Cs=setTimeout(y0,t-Os.now()-qc)),ws&&(ws=clearInterval(ws))):(ws||(_c=Os.now(),ws=setInterval(LS,ug)),yi=1,dg(y0))}}const HS=1664525,US=1013904223,g0=4294967296;function IS(){let t=1;return()=>(t=(HS*t+US)%g0)/g0}function YS(t){return t.x}function qS(t){return t.y}var XS=10,VS=Math.PI*(3-Math.sqrt(5));function GS(t){var l,r=1,i=.001,c=1-Math.pow(i,1/300),u=0,d=.6,m=new Map,x=hg(y),f=cg("tick","end"),g=IS();t==null&&(t=[]);function y(){b(),f.call("tick",l),r<i&&(x.stop(),f.call("end",l))}function b(j){var E,C=t.length,A;j===void 0&&(j=1);for(var M=0;M<j;++M)for(r+=(u-r)*c,m.forEach(function(B){B(r)}),E=0;E<C;++E)A=t[E],A.fx==null?A.x+=A.vx*=d:(A.x=A.fx,A.vx=0),A.fy==null?A.y+=A.vy*=d:(A.y=A.fy,A.vy=0);return l}function v(){for(var j=0,E=t.length,C;j<E;++j){if(C=t[j],C.index=j,C.fx!=null&&(C.x=C.fx),C.fy!=null&&(C.y=C.fy),isNaN(C.x)||isNaN(C.y)){var A=XS*Math.sqrt(.5+j),M=j*VS;C.x=A*Math.cos(M),C.y=A*Math.sin(M)}(isNaN(C.vx)||isNaN(C.vy))&&(C.vx=C.vy=0)}}function S(j){return j.initialize&&j.initialize(t,g),j}return v(),l={tick:b,restart:function(){return x.restart(y),l},stop:function(){return x.stop(),l},nodes:function(j){return arguments.length?(t=j,v(),m.forEach(S),l):t},alpha:function(j){return arguments.length?(r=+j,l):r},alphaMin:function(j){return arguments.length?(i=+j,l):i},alphaDecay:function(j){return arguments.length?(c=+j,l):+c},alphaTarget:function(j){return arguments.length?(u=+j,l):u},velocityDecay:function(j){return arguments.length?(d=1-j,l):1-d},randomSource:function(j){return arguments.length?(g=j,m.forEach(S),l):g},force:function(j,E){return arguments.length>1?(E==null?m.delete(j):m.set(j,S(E)),l):m.get(j)},find:function(j,E,C){var A=0,M=t.length,B,$,_,V,G;for(C==null?C=1/0:C*=C,A=0;A<M;++A)V=t[A],B=j-V.x,$=E-V.y,_=B*B+$*$,_<C&&(G=V,C=_);return G},on:function(j,E){return arguments.length>1?(f.on(j,E),l):f.on(j)}}}function KS(){var t,l,r,i,c=va(-30),u,d=1,m=1/0,x=.81;function f(v){var S,j=t.length,E=Nh(t,YS,qS).visitAfter(y);for(i=v,S=0;S<j;++S)l=t[S],E.visit(b)}function g(){if(t){var v,S=t.length,j;for(u=new Array(S),v=0;v<S;++v)j=t[v],u[j.index]=+c(j,v,t)}}function y(v){var S=0,j,E,C=0,A,M,B;if(v.length){for(A=M=B=0;B<4;++B)(j=v[B])&&(E=Math.abs(j.value))&&(S+=j.value,C+=E,A+=E*j.x,M+=E*j.y);v.x=A/C,v.y=M/C}else{j=v,j.x=j.data.x,j.y=j.data.y;do S+=u[j.data.index];while(j=j.next)}v.value=S}function b(v,S,j,E){if(!v.value)return!0;var C=v.x-l.x,A=v.y-l.y,M=E-S,B=C*C+A*A;if(M*M/x<B)return B<m&&(C===0&&(C=Ir(r),B+=C*C),A===0&&(A=Ir(r),B+=A*A),B<d&&(B=Math.sqrt(d*B)),l.vx+=C*v.value*i/B,l.vy+=A*v.value*i/B),!0;if(v.length||B>=m)return;(v.data!==l||v.next)&&(C===0&&(C=Ir(r),B+=C*C),A===0&&(A=Ir(r),B+=A*A),B<d&&(B=Math.sqrt(d*B)));do v.data!==l&&(M=u[v.data.index]*i/B,l.vx+=C*M,l.vy+=A*M);while(v=v.next)}return f.initialize=function(v,S){t=v,r=S,g()},f.strength=function(v){return arguments.length?(c=typeof v=="function"?v:va(+v),g(),f):c},f.distanceMin=function(v){return arguments.length?(d=v*v,f):Math.sqrt(d)},f.distanceMax=function(v){return arguments.length?(m=v*v,f):Math.sqrt(m)},f.theta=function(v){return arguments.length?(x=v*v,f):Math.sqrt(x)},f}const Bs={tech:{bg:"rgba(59,130,246,0.15)",border:"#3b82f6",text:"#60a5fa"},market:{bg:"rgba(245,158,11,0.15)",border:"#f59e0b",text:"#fbbf24"},strategy:{bg:"rgba(139,92,246,0.15)",border:"#8b5cf6",text:"#a78bfa"},financial:{bg:"rgba(34,197,94,0.15)",border:"#22c55e",text:"#4ade80"},process:{bg:"rgba(236,72,153,0.15)",border:"#ec4899",text:"#f472b6"},competitor:{bg:"rgba(239,68,68,0.15)",border:"#ef4444",text:"#f87171"},domain:{bg:"rgba(14,165,233,0.15)",border:"#0ea5e9",text:"#38bdf8"},general:{bg:"rgba(148,163,184,0.12)",border:"#64748b",text:"#94a3b8"}};function WS(t){return Bs[t]??Bs.general}function QS({docs:t,onNodeClick:l,selectedDocId:r}){var U;const i=k.useRef(null),c=k.useRef(null),[u,d]=k.useState({width:600,height:400}),[m,x]=k.useState({nodes:[],links:[]}),[f,g]=k.useState(null),[y,b]=k.useState(null),[v,S]=k.useState({x:0,y:0}),[j,E]=k.useState({x:0,y:0,w:600,h:400}),C=k.useRef(!1),A=k.useRef({x:0,y:0,vx:0,vy:0}),M=k.useRef(null),B=k.useRef(null);k.useEffect(()=>{const O=i.current;if(!O)return;const J=new ResizeObserver(ne=>{const{width:K,height:I}=ne[0].contentRect;K>0&&I>0&&(d({width:K,height:I}),E(W=>({...W,w:K,h:I})))});return J.observe(O),()=>J.disconnect()},[]),k.useEffect(()=>{if(t.length===0)return;const O=new Set(t.map(ge=>ge.id)),J=t.map(ge=>({id:ge.id,title:ge.title,category:ge.category,akb_type:ge.akb_type})),ne=(ge,Ae)=>{if(!Ae.startsWith(".")&&!Ae.startsWith("/"))return Ae;const De=ge.split("/");De.pop();const He=Ae.split("/");for(const ye of He)ye===".."?De.pop():ye!=="."&&ye!==""&&De.push(ye);return De.join("/")},K=[];for(const ge of t)for(const Ae of ge.links){const De=ne(ge.id,Ae.href);O.has(De)&&De!==ge.id&&(K.some(He=>He.source===ge.id&&He.target===De||He.source===De&&He.target===ge.id)||K.push({source:ge.id,target:De,label:Ae.text}))}const{width:I,height:W}=u,me=J.length,Se=me>100?-600:me>50?-500:-400,D=me>100?180:me>50?160:140,F=me>100?60:50,Q=Math.max(I,me*12),z=Math.max(W,me*10),ce=GS(J).force("link",MS(K).id(ge=>ge.id).distance(D)).force("charge",KS().strength(Se)).force("center",dS(Q/2,z/2)).force("collide",TS(F));B.current=ce,ce.on("tick",()=>{x({nodes:[...J],links:[...K]})}),ce.alpha(1).restart();const Ee=me>100?300:150;for(let ge=0;ge<Ee;ge++)ce.tick();if(ce.stop(),x({nodes:[...J],links:[...K]}),J.length>0){let ge=1/0,Ae=1/0,De=-1/0,He=-1/0;for(const We of J){const de=We.x??0,fe=We.y??0;de<ge&&(ge=de),fe<Ae&&(Ae=fe),de>De&&(De=de),fe>He&&(He=fe)}const ye=100;E({x:ge-ye,y:Ae-ye,w:Math.max(I,De-ge+ye*2),h:Math.max(W,He-Ae+ye*2)})}return()=>{ce.stop()}},[t,u]);const $=O=>{if(typeof O=="string"){const J=m.nodes.find(ne=>ne.id===O);return{x:(J==null?void 0:J.x)??0,y:(J==null?void 0:J.y)??0}}return{x:O.x??0,y:O.y??0}},_=k.useCallback(O=>{O.preventDefault();const J=O.deltaY>0?1.1:.9;E(ne=>{const K=Math.max(200,Math.min(u.width*3,ne.w*J)),I=Math.max(150,Math.min(u.height*3,ne.h*J)),W=(K-ne.w)/2,me=(I-ne.h)/2;return{x:ne.x-W,y:ne.y-me,w:K,h:I}})},[u]),V=k.useCallback(O=>{O.button===0&&(C.current=!0,A.current={x:O.clientX,y:O.clientY,vx:j.x,vy:j.y})},[j]),G=k.useCallback(O=>{var J;if(M.current){const ne=c.current;if(!ne)return;const K=ne.getBoundingClientRect(),I=j.w/K.width,W=j.h/K.height,me=j.x+(O.clientX-K.left)*I,Se=j.y+(O.clientY-K.top)*W;M.current.fx=me,M.current.fy=Se,(J=B.current)==null||J.alpha(.3).restart();return}if(C.current){const ne=(O.clientX-A.current.x)*(j.w/u.width),K=(O.clientY-A.current.y)*(j.h/u.height);E(I=>({...I,x:A.current.vx-ne,y:A.current.vy-K}))}},[j,u]),Y=k.useCallback(()=>{C.current=!1,M.current&&(M.current.fx=null,M.current.fy=null,M.current=null)},[]),T=k.useCallback((O,J)=>{var ne;O.stopPropagation(),M.current=J,(ne=B.current)==null||ne.alpha(.3).restart()},[]);return s.jsxs("div",{ref:i,className:"relative flex-1 overflow-hidden",style:{background:"#1e1e2e"},children:[s.jsxs("svg",{ref:c,width:u.width,height:u.height,viewBox:`${j.x} ${j.y} ${j.w} ${j.h}`,style:{display:"block",cursor:C.current?"grabbing":"grab"},onWheel:_,onMouseDown:V,onMouseMove:G,onMouseUp:Y,onMouseLeave:Y,children:[s.jsx("defs",{children:s.jsx("pattern",{id:"grid",width:"20",height:"20",patternUnits:"userSpaceOnUse",children:s.jsx("circle",{cx:"0",cy:"0",r:"0.5",fill:"rgba(255,255,255,0.06)"})})}),s.jsx("rect",{x:j.x-100,y:j.y-100,width:j.w+200,height:j.h+200,fill:"url(#grid)",pointerEvents:"none"}),m.links.map((O,J)=>{const ne=$(O.source),K=$(O.target),I=y===J,W=(ne.x+K.x)/2,me=(ne.y+K.y)/2;return s.jsxs("g",{children:[s.jsx("line",{x1:ne.x,y1:ne.y,x2:K.x,y2:K.y,stroke:"transparent",strokeWidth:12,style:{cursor:"default"},onMouseEnter:()=>b(J),onMouseLeave:()=>b(null)}),s.jsx("line",{x1:ne.x,y1:ne.y,x2:K.x,y2:K.y,stroke:I?"rgba(148,163,184,0.7)":"rgba(148,163,184,0.3)",strokeWidth:I?2:1.5,strokeDasharray:"4 3",pointerEvents:"none"}),I&&O.label&&s.jsx("text",{x:W,y:me-6,textAnchor:"middle",fill:"#e2e8f0",fontSize:9,fontFamily:"monospace",style:{pointerEvents:"none"},children:s.jsx("tspan",{style:{filter:"drop-shadow(0 0 2px rgba(0,0,0,0.8))"},children:O.label.length>30?O.label.slice(0,28)+"..":O.label})})]},J)}),m.nodes.map(O=>{const J=Bs[O.category]??Bs.general,ne=O.akb_type==="hub",K=ne?24:16,I=(f==null?void 0:f.id)===O.id,W=r===O.id,me=I?1.2:W?1.15:1;return s.jsxs("g",{transform:`translate(${O.x??0}, ${O.y??0}) scale(${me})`,style:{cursor:"pointer",transition:"transform 0.15s ease"},onClick:Se=>{Se.stopPropagation();const D=t.find(F=>F.id===O.id);D&&l(D)},onMouseDown:Se=>T(Se,O),onMouseEnter:Se=>{var F;g(O);const D=(F=i.current)==null?void 0:F.getBoundingClientRect();D&&S({x:Se.clientX-D.left,y:Se.clientY-D.top})},onMouseLeave:()=>g(null),children:[W&&s.jsx("rect",{x:-K/2-4,y:-K/2-4,width:K+8,height:K+8,fill:"none",stroke:"#22c55e",strokeWidth:2,rx:ne?5:2,opacity:.6}),s.jsx("rect",{x:-K/2,y:-K/2,width:K,height:K,fill:J.border,rx:ne?4:2,opacity:I?1:.9}),s.jsx("rect",{x:-K/2+3,y:-K/2+3,width:Math.max(0,K-6),height:Math.max(0,K-6),fill:J.bg,rx:ne?3:1}),s.jsx("text",{y:K/2+14,textAnchor:"middle",fill:W?"#e2e8f0":"#94a3b8",fontSize:11,fontFamily:"monospace",fontWeight:W?"bold":"normal",style:{pointerEvents:"none"},children:O.title.length>24?O.title.slice(0,22)+"..":O.title})]},O.id)})]}),f&&!M.current&&s.jsxs("div",{className:"absolute z-10 pointer-events-none p-2.5 rounded text-xs max-w-[240px]",style:{left:Math.min(v.x+16,u.width-250),top:Math.max(v.y-30,8),background:"var(--hud-bg)",border:"1px solid var(--terminal-border)",color:"var(--terminal-text)",boxShadow:"0 4px 12px rgba(0,0,0,0.4)"},children:[s.jsx("div",{className:"font-bold mb-1",children:f.title}),s.jsxs("div",{className:"text-[10px] opacity-60 mb-1",children:[f.akb_type.toUpperCase()," / ",f.category]}),((U=t.find(O=>O.id===f.id))==null?void 0:U.tldr)&&s.jsx("div",{className:"text-[10px] opacity-80 mb-1",children:t.find(O=>O.id===f.id).tldr}),s.jsx("div",{className:"text-[10px] text-green-400",children:"Click to open | Drag to move"})]}),t.length===0&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center text-xs",style:{color:"var(--terminal-text-muted)"},children:"No knowledge documents found"})]})}function ZS({doc:t,allDocs:l,onOpen:r,onNavigateDoc:i}){const[c,u]=k.useState(!1),d=WS(t.category),m=t.akb_type==="hub",x=new Set(l.map(f=>f.id));return s.jsxs("div",{className:"mb-2 rounded-lg overflow-hidden",style:{background:m?"rgba(22,163,106,0.08)":"var(--hud-bg-alt)",border:`2px solid ${m?"rgba(22,163,106,0.4)":"var(--terminal-border)"}`},children:[s.jsxs("div",{className:"p-3 cursor-pointer hover:bg-white/5",onClick:()=>u(!c),children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("span",{className:"shrink-0 text-sm",children:m?"🗂":t.format==="html"?"🌐":"📄"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-1 flex-wrap",children:[s.jsx("span",{className:"font-semibold text-xs truncate",style:{color:"var(--terminal-text)"},children:t.title}),s.jsx("span",{className:"w-2 h-2 rounded-full shrink-0",style:{background:t.status==="active"?"#16a34a":t.status==="draft"?"#f59e0b":"#94a3b8"},title:t.status})]}),s.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:t.tags.slice(0,4).map(f=>s.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-medium",style:{background:d.bg,color:d.text,border:`1px solid ${d.border}`},children:f},f))})]}),s.jsx("span",{className:"text-xs shrink-0",style:{color:"var(--terminal-text-muted)"},children:c?"▲":"▼"})]}),!c&&t.tldr&&s.jsx("div",{className:"mt-1.5 text-[10px] line-clamp-2 ml-6",style:{color:"var(--terminal-text-secondary)"},children:t.tldr})]}),c&&s.jsxs("div",{className:"px-3 pb-3",style:{borderTop:"1px solid var(--terminal-border)"},children:[t.tldr&&s.jsx("div",{className:"mt-2 text-[11px] leading-relaxed italic",style:{color:"var(--terminal-text-secondary)"},children:t.tldr}),t.links.length>0&&s.jsxs("div",{className:"mt-2",children:[s.jsx("div",{className:"text-[9px] font-bold uppercase mb-1",style:{color:"var(--terminal-text-muted)"},children:"Cross-links"}),s.jsx("div",{className:"flex flex-wrap gap-1",children:t.links.slice(0,5).map((f,g)=>{const y=f.href.replace(/^.*knowledge\//,"").replace(/^\.\.\/.*$/,"").replace(/^\.\//,""),b=x.has(y);return s.jsxs("span",{className:`px-1.5 py-0.5 text-[9px] rounded ${b?"cursor-pointer hover:opacity-70":""}`,style:{background:b?"rgba(22,163,106,0.15)":"rgba(148,163,184,0.1)",color:b?"#4ade80":"var(--terminal-text-muted)",border:`1px solid ${b?"rgba(22,163,106,0.3)":"var(--terminal-border)"}`},onClick:v=>{b&&(v.stopPropagation(),i(y))},children:["🔗"," ",f.text]},g)})})]}),s.jsxs("button",{className:"mt-2 text-[10px] font-semibold cursor-pointer hover:opacity-70",style:{color:"var(--active-green)"},onClick:f=>{f.stopPropagation(),r(t)},children:["Open full ","→"]})]})]})}function JS({docId:t,onBack:l,onDocUpdated:r,onDelete:i,onNavigateDoc:c,allDocs:u}){const[d,m]=k.useState(null),[x,f]=k.useState(!0),[g,y]=k.useState(!1),[b,v]=k.useState(""),[S,j]=k.useState(!1),E=new Set(u.map($=>$.id)),C=k.useCallback($=>{const _=$.split("#")[0];if(!_.match(/\.(md|html)$/))return null;const V=t.includes("/")?t.replace(/\/[^/]+$/,""):"";let G;if(_.startsWith("./"))G=V?`${V}/${_.slice(2)}`:_.slice(2);else if(_.startsWith("../")){const U=V.split("/").filter(Boolean);let O=_;for(;O.startsWith("../");)U.length>0&&U.pop(),O=O.slice(3);G=U.length>0?`${U.join("/")}/${O}`:O}else G=_;if(E.has(G))return G;const Y=G.split("/").pop()??"",T=u.find(U=>U.id===Y||U.id.endsWith("/"+Y));return T?T.id:null},[t,E,u]),A=k.useCallback($=>{const V=$.target.closest("a");if(!V)return;const G=V.getAttribute("href");if(!G||G.startsWith("http://")||G.startsWith("https://")||!G.match(/\.(md|html)(#.*)?$/))return;$.preventDefault(),$.stopPropagation();const Y=C(G);Y&&c(Y)},[C,c]);k.useEffect(()=>{f(!0),Ne.getKnowledgeDoc(t).then($=>{m($),v($.content)}).catch(console.error).finally(()=>f(!1))},[t]);const M=async()=>{if(d){j(!0);try{await Ne.updateKnowledgeDoc(t,b),m({...d,content:b}),y(!1),r()}catch($){console.error("Save failed:",$)}finally{j(!1)}}},B=async()=>{if(confirm(`Delete "${d==null?void 0:d.title}"?`))try{await Ne.deleteKnowledgeDoc(t),i(t)}catch($){console.error("Delete failed:",$)}};return x?s.jsx("div",{className:"flex-1 flex items-center justify-center text-xs",style:{color:"var(--terminal-text-muted)"},children:"Loading..."}):d?s.jsxs("div",{className:"flex-1 overflow-y-auto flex flex-col",children:[s.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 shrink-0",style:{borderBottom:"1px solid var(--terminal-border)"},children:[s.jsxs("button",{onClick:l,className:"text-xs font-semibold cursor-pointer hover:opacity-70",style:{color:"var(--active-green)"},children:["←"," Back"]}),s.jsx("div",{className:"flex-1"}),g?s.jsxs(s.Fragment,{children:[s.jsx("button",{onClick:()=>{y(!1),v(d.content)},className:"px-2.5 py-1 text-[10px] rounded cursor-pointer",style:{background:"var(--hud-bg-alt)",color:"var(--terminal-text-secondary)",border:"1px solid var(--terminal-border)"},children:"Cancel"}),s.jsx("button",{onClick:M,disabled:S,className:"px-2.5 py-1 text-[10px] rounded cursor-pointer font-semibold text-white",style:{background:S?"#86efac":"#16a34a"},children:S?"Saving...":"Save"})]}):s.jsxs(s.Fragment,{children:[s.jsx("button",{onClick:()=>y(!0),className:"px-2.5 py-1 text-[10px] rounded cursor-pointer font-semibold",style:{background:"rgba(59,130,246,0.15)",color:"#60a5fa",border:"1px solid rgba(59,130,246,0.3)"},children:"Edit"}),s.jsx("button",{onClick:B,className:"px-2.5 py-1 text-[10px] rounded cursor-pointer font-semibold",style:{background:"rgba(239,68,68,0.15)",color:"#f87171",border:"1px solid rgba(239,68,68,0.3)"},children:"Delete"})]})]}),s.jsxs("div",{className:"flex-1 overflow-y-auto p-5",children:[s.jsx("h2",{className:"text-sm font-bold mb-1",style:{color:"var(--terminal-text)"},children:d.title}),d.tldr&&!g&&s.jsx("div",{className:"mb-3 text-xs italic",style:{color:"var(--terminal-text-secondary)"},children:d.tldr}),d.format==="html"?g?s.jsx("textarea",{className:"w-full h-full min-h-[400px] p-3 text-xs leading-relaxed rounded border resize-y",style:{fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',background:"var(--hud-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},value:b,onChange:$=>v($.target.value),spellCheck:!1}):s.jsx("iframe",{srcDoc:d.content,sandbox:"allow-same-origin",className:"w-full flex-1 min-h-[400px] rounded",style:{border:"1px solid var(--terminal-border)",background:"var(--hud-bg-alt)"},title:d.title}):g?s.jsx("textarea",{className:"w-full h-full min-h-[400px] p-3 text-xs leading-relaxed rounded border resize-y",style:{fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',background:"#1e1e2e",color:"#e2e8f0",border:"1px solid #334155"},value:b,onChange:$=>v($.target.value),spellCheck:!1}):s.jsx("div",{className:"text-xs leading-relaxed",style:{color:"var(--terminal-text-secondary)"},onClick:A,children:s.jsx(Is,{content:d.content})})]})]}):s.jsx("div",{className:"flex-1 flex items-center justify-center text-xs",style:{color:"var(--terminal-text-muted)"},children:"Failed to load document"})}function PS({onCreated:t,onCancel:l}){const[r,i]=k.useState(""),[c,u]=k.useState(""),[d,m]=k.useState(""),[x,f]=k.useState(!1),[g,y]=k.useState("");k.useEffect(()=>{if(!r){u("");return}const v=r.toLowerCase().replace(/[^a-z0-9가-힣\s-]/g,"").replace(/\s+/g,"-").slice(0,60);u(v)},[r]);const b=async()=>{if(!r.trim()||!c.trim()){y("Title and filename are required");return}f(!0),y("");try{const v=await Ne.createKnowledgeDoc({filename:c,title:r,category:d||void 0});t(v.id)}catch(v){y(v instanceof Error?v.message:"Failed to create")}finally{f(!1)}};return s.jsxs("div",{className:"flex-1 overflow-y-auto p-5",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[s.jsxs("button",{onClick:l,className:"text-xs font-semibold cursor-pointer hover:opacity-70",style:{color:"var(--active-green)"},children:["←"," Cancel"]}),s.jsx("h2",{className:"text-sm font-bold",style:{color:"var(--terminal-text)"},children:"New Document"})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-[10px] font-semibold mb-1",style:{color:"var(--terminal-text-muted)"},children:"TITLE"}),s.jsx("input",{type:"text",value:r,onChange:v=>i(v.target.value),placeholder:"Document title...",className:"w-full px-3 py-2 text-xs rounded focus:outline-none",style:{background:"var(--hud-bg)",border:"1px solid var(--terminal-border)",color:"var(--terminal-text)"}})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-[10px] font-semibold mb-1",style:{color:"var(--terminal-text-muted)"},children:"FILENAME"}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("input",{type:"text",value:c,onChange:v=>u(v.target.value),className:"flex-1 px-3 py-2 text-xs rounded focus:outline-none font-mono",style:{background:"var(--hud-bg)",border:"1px solid var(--terminal-border)",color:"var(--terminal-text)"}}),s.jsx("span",{className:"text-[10px]",style:{color:"var(--terminal-text-muted)"},children:".md"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-[10px] font-semibold mb-1",style:{color:"var(--terminal-text-muted)"},children:"CATEGORY (optional)"}),s.jsx("input",{type:"text",value:d,onChange:v=>m(v.target.value),placeholder:"e.g., tech, market, strategy",className:"w-full px-3 py-2 text-xs rounded focus:outline-none",style:{background:"var(--hud-bg)",border:"1px solid var(--terminal-border)",color:"var(--terminal-text)"}})]}),g&&s.jsx("div",{className:"text-[10px] px-3 py-1.5 rounded",style:{background:"rgba(239,68,68,0.15)",color:"#f87171"},children:g}),s.jsx("button",{onClick:b,disabled:x||!r.trim(),className:"w-full py-2 text-xs font-semibold rounded cursor-pointer text-white",style:{background:x?"#86efac":"#16a34a"},children:x?"Creating...":"Create Document"})]})]})}const eC=500,b0=360,v0=700;function Dh(t){const[l,r]=k.useState(eC),[i,c]=k.useState(!1),u=k.useRef(0),d=k.useRef(0),m=t>0,x=m?t:0,f=m?Math.max(b0,window.innerWidth-t-100):v0,g=Math.min(l,f),y=k.useCallback(b=>{b.preventDefault(),u.current=b.clientX,d.current=g,c(!0);const v=j=>{const E=u.current-j.clientX,C=Math.min(v0,Math.max(b0,d.current+E));r(C)},S=()=>{c(!1),document.removeEventListener("mousemove",v),document.removeEventListener("mouseup",S)};document.addEventListener("mousemove",v),document.addEventListener("mouseup",S)},[g]);return{panelRight:x,panelWidth:g,isResizing:i,handleResizeStart:y}}function tC({docs:t,onClose:l,onRefresh:r,terminalWidth:i=0,initialDocId:c}){const[u,d]=k.useState("list"),[m,x]=k.useState("all"),[f,g]=k.useState(c??null),[y,b]=k.useState(""),[v,S]=k.useState(!1),[j,E]=k.useState(null),{panelRight:C,panelWidth:A,isResizing:M,handleResizeStart:B}=Dh(i),$=["all",...Array.from(new Set(t.map(U=>U.category))).sort()],_=t.filter(U=>{if(m!=="all"&&U.category!==m)return!1;if(y){const O=y.toLowerCase();return U.title.toLowerCase().includes(O)||(U.tldr??"").toLowerCase().includes(O)||U.tags.some(J=>J.toLowerCase().includes(O))}return!0}),V=U=>{S(!1),r(),g(U)},G=U=>{g(null),r()},Y=U=>{E(U.id)},T=j?t.find(U=>U.id===j):null;return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"dimmer fixed top-0 left-0 bottom-0 bg-black/30 z-40 open",style:{right:C},onClick:l}),s.jsxs("div",{className:`side-panel open fixed top-0 h-full z-50 flex flex-col border-l-[3px] shadow-[-4px_0_20px_rgba(0,0,0,0.4)] ${M?"resizing":""}`,style:{right:C,width:A,background:"var(--terminal-bg)",borderLeftColor:"#16a34a"},children:[s.jsx("div",{className:`absolute top-0 -left-[5px] w-[10px] h-full cursor-col-resize z-[60] transition-colors ${M?"bg-white/10":"hover:bg-white/5"}`,onMouseDown:B}),s.jsxs("div",{className:"p-5 text-white relative",style:{background:"#16a34a"},children:[s.jsx("button",{onClick:l,className:"absolute top-3 right-3 w-7 h-7 rounded-full bg-white/20 text-white flex items-center justify-center text-lg hover:bg-white/30 cursor-pointer",children:"×"}),s.jsxs("div",{className:"text-lg font-bold",children:["📚"," Knowledge Base"]}),s.jsxs("div",{className:"text-xs opacity-80 mt-0.5",children:[t.length," documents"]})]}),s.jsxs("div",{className:"flex",style:{borderBottom:"1px solid var(--terminal-border)"},children:[s.jsx(w0,{label:"List",active:u==="list",onClick:()=>{d("list"),E(null)}}),s.jsx(w0,{label:"Graph",active:u==="graph",onClick:()=>d("graph")})]}),u==="list"&&!f&&!v&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 shrink-0",style:{borderBottom:"1px solid var(--terminal-border)"},children:[s.jsx("input",{type:"text",value:y,onChange:U=>b(U.target.value),placeholder:"Search docs...",className:"flex-1 px-2.5 py-1.5 text-[11px] rounded focus:outline-none",style:{background:"var(--hud-bg)",border:"1px solid var(--terminal-border)",color:"var(--terminal-text)"}}),s.jsx("button",{onClick:()=>S(!0),className:"px-2.5 py-1.5 text-[10px] font-semibold rounded cursor-pointer text-white shrink-0",style:{background:"#16a34a"},children:"+ New"})]}),s.jsx("div",{className:"flex overflow-x-auto shrink-0",style:{borderBottom:"1px solid var(--terminal-border)",scrollbarWidth:"none"},children:$.map(U=>s.jsx("button",{onClick:()=>x(U),className:"px-3 py-1.5 text-[10px] font-medium cursor-pointer whitespace-nowrap",style:{color:m===U?"#4ade80":"var(--terminal-text-muted)",borderBottom:m===U?"2px solid #4ade80":"2px solid transparent"},children:U==="all"?`All (${t.length})`:`${U} (${t.filter(O=>O.category===U).length})`},U))}),s.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:_.length===0?s.jsx("div",{className:"text-center text-xs py-8",style:{color:"var(--terminal-text-muted)"},children:y?"No matching documents":"No documents in this category"}):_.map(U=>s.jsx(ZS,{doc:U,allDocs:t,onOpen:O=>g(O.id),onNavigateDoc:O=>g(O)},U.id))})]}),u==="list"&&f&&!v&&s.jsx(JS,{docId:f,onBack:()=>g(null),onDocUpdated:r,onDelete:G,onNavigateDoc:U=>g(U),allDocs:t}),u==="list"&&v&&s.jsx(PS,{onCreated:V,onCancel:()=>S(!1)}),u==="graph"&&s.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[s.jsx(QS,{docs:t,onNodeClick:Y,selectedDocId:j}),T&&s.jsxs("div",{className:"shrink-0 overflow-y-auto p-3",style:{width:200,background:"var(--hud-bg-alt)",borderLeft:"1px solid var(--terminal-border)"},children:[s.jsx("div",{className:"text-[10px] font-bold uppercase mb-1",style:{color:"var(--terminal-text-muted)"},children:"Selected"}),s.jsx("div",{className:"text-xs font-bold mb-1",style:{color:"var(--terminal-text)"},children:T.title}),s.jsx("div",{className:"w-2 h-2 rounded-full mb-2",style:{background:T.status==="active"?"#16a34a":T.status==="draft"?"#f59e0b":"#94a3b8"}}),T.tldr&&s.jsx("div",{className:"text-[10px] mb-2 leading-relaxed",style:{color:"var(--terminal-text-secondary)"},children:T.tldr}),T.links.length>0&&s.jsxs("div",{className:"mb-2",children:[s.jsx("div",{className:"text-[9px] font-bold mb-1",style:{color:"var(--terminal-text-muted)"},children:"Links"}),T.links.slice(0,5).map((U,O)=>s.jsxs("div",{className:"text-[9px] mb-0.5 truncate",style:{color:"var(--terminal-text-secondary)"},children:["🔗"," ",U.text]},O))]}),s.jsx("button",{className:"w-full py-1.5 text-[10px] font-semibold rounded cursor-pointer text-white",style:{background:"#16a34a"},onClick:()=>{d("list"),g(T.id),E(null)},children:"Open Document"})]})]}),s.jsx("div",{className:"shrink-0 p-2",style:{borderTop:"1px solid var(--terminal-border)"},children:s.jsx("div",{className:"flex flex-wrap gap-2",children:Object.entries(Bs).map(([U,O])=>s.jsxs("div",{className:"flex items-center gap-1 text-[9px]",children:[s.jsx("div",{className:"w-2 h-2",style:{background:O.border}}),s.jsx("span",{style:{color:"var(--terminal-text-muted)"},children:U})]},U))})})]})]})]})}function w0({label:t,active:l,onClick:r}){return s.jsx("button",{onClick:r,className:"px-4 py-2.5 text-sm font-medium cursor-pointer",style:{color:l?"#4ade80":"var(--terminal-text-muted)",borderBottom:l?"2px solid #4ade80":"2px solid transparent"},children:t})}function nC({standups:t,waves:l,decisions:r,mode:i,onClose:c,terminalWidth:u=0}){const[d,m]=k.useState(i==="decisions"?"decisions":"standups"),{panelRight:x,panelWidth:f,isResizing:g,handleResizeStart:y}=Dh(u);return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"dimmer fixed top-0 left-0 bottom-0 bg-black/30 z-40 open",style:{right:x},onClick:c}),s.jsxs("div",{className:`side-panel open fixed top-0 h-full z-50 flex flex-col border-l-[3px] shadow-[-4px_0_20px_rgba(0,0,0,0.4)] ${g?"resizing":""}`,style:{right:x,width:f,background:"var(--terminal-bg)",borderLeftColor:"var(--desk-wood)"},children:[s.jsx("div",{className:`absolute top-0 -left-[5px] w-[10px] h-full cursor-col-resize z-[60] transition-colors ${g?"bg-white/10":"hover:bg-white/5"}`,onMouseDown:y}),s.jsxs("div",{className:"p-5 bg-[var(--desk-wood)] text-white relative",children:[s.jsx("button",{onClick:c,className:"absolute top-3 right-3 w-7 h-7 rounded-full bg-white/20 text-white flex items-center justify-center text-lg hover:bg-white/30 cursor-pointer",children:"×"}),s.jsx("div",{className:"text-lg font-bold",children:i==="bulletin"?"📌 Bulletin Board":"📜 Decision Log"})]}),s.jsx("div",{className:"flex",style:{borderBottom:"1px solid var(--terminal-border)"},children:i==="bulletin"?s.jsxs(s.Fragment,{children:[s.jsx(vf,{label:`Standups (${t.length})`,active:d==="standups",onClick:()=>m("standups")}),s.jsx(vf,{label:`Waves (${l.length})`,active:d==="waves",onClick:()=>m("waves")})]}):s.jsx(vf,{label:`Decisions (${r.length})`,active:d==="decisions",onClick:()=>m("decisions")})}),s.jsxs("div",{className:"flex-1 overflow-y-auto p-5",children:[d==="standups"&&t.map((b,v)=>s.jsx(wf,{title:`Standup ${b.date}`,content:b.content},v)),d==="waves"&&l.map((b,v)=>s.jsx(wf,{title:`Wave ${b.id}`,subtitle:b.timestamp,content:b.content},v)),d==="decisions"&&r.map((b,v)=>s.jsx(wf,{title:`#${b.id} ${b.title}`,subtitle:b.date,content:b.content},v))]})]})]})}function vf({label:t,active:l,onClick:r}){return s.jsx("button",{onClick:r,className:"px-4 py-2.5 text-sm font-medium cursor-pointer",style:{color:l?"var(--accent)":"var(--terminal-text-muted)",borderBottom:l?"2px solid var(--accent)":"2px solid transparent"},children:t})}function lC(t){return t.replace(/^#{1,6}\s+/gm,"").replace(/\*\*([^*]+)\*\*/g,"$1").replace(/\*([^*]+)\*/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/```[\s\S]*?```/g,"").replace(/^\s*[-*+]\s+/gm,"• ").replace(/^\s*\d+\.\s+/gm,"").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/^>\s+/gm,"").replace(/^---+$/gm,"").replace(/\|[^|]*\|/g,"").replace(/\n{2,}/g," · ").replace(/\n/g," ").trim()}function wf({title:t,subtitle:l,content:r}){const[i,c]=k.useState(!1),u=r.length>100,d=lC(r).slice(0,160);return s.jsxs("div",{className:"mb-3 rounded-lg overflow-hidden",style:{background:"var(--hud-bg-alt)",border:"1px solid var(--terminal-border)"},children:[s.jsxs("div",{className:"p-3 cursor-pointer hover:bg-white/5",onClick:()=>c(!i),children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("div",{className:"font-medium text-sm",style:{color:"var(--terminal-text)"},children:t}),s.jsx("span",{className:"text-xs shrink-0 ml-2",style:{color:"var(--terminal-text-muted)"},children:i?"▲":"▼"})]}),l&&s.jsx("div",{className:"text-xs mt-0.5",style:{color:"var(--terminal-text-muted)"},children:l})]}),i&&s.jsx("div",{className:"px-3 pb-3 text-xs leading-relaxed pt-2",style:{borderTop:"1px solid var(--terminal-border)",color:"var(--terminal-text-secondary)"},children:s.jsx(Is,{content:r})}),!i&&u&&s.jsx("div",{className:"px-3 pb-2 text-xs line-clamp-2 leading-relaxed",style:{color:"var(--terminal-text-muted)"},children:d})]})}function rC({projectId:t,onClose:l,terminalWidth:r=0}){const[i,c]=k.useState(null),{panelRight:u,panelWidth:d,isResizing:m,handleResizeStart:x}=Dh(r);if(k.useEffect(()=>{Ne.getProject(t).then(c).catch(console.error)},[t]),!i)return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"dimmer fixed top-0 left-0 bottom-0 bg-black/30 z-40 open",style:{right:u},onClick:l}),s.jsx("div",{className:"side-panel open fixed top-0 h-full z-50 flex items-center justify-center border-l-[3px] border-[var(--meeting-blue)]",style:{right:u,width:d,background:"var(--terminal-bg)"},children:s.jsx("div",{className:"text-sm",style:{color:"var(--terminal-text-muted)"},children:"Loading project..."})})]});const f=i.tasks.filter(b=>b.status==="done").length,g=i.tasks.length,y=g>0?Math.round(f/g*100):0;return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"dimmer fixed top-0 left-0 bottom-0 bg-black/30 z-40 open",style:{right:u},onClick:l}),s.jsxs("div",{className:`side-panel open fixed top-0 h-full z-50 flex flex-col border-l-[3px] border-[var(--meeting-blue)] shadow-[-4px_0_20px_rgba(0,0,0,0.4)] ${m?"resizing":""}`,style:{right:u,width:d,background:"var(--terminal-bg)"},children:[s.jsx("div",{className:`absolute top-0 -left-[5px] w-[10px] h-full cursor-col-resize z-[60] transition-colors ${m?"bg-white/10":"hover:bg-white/5"}`,onMouseDown:x}),s.jsxs("div",{className:"p-5 bg-[var(--meeting-blue)] text-white relative",children:[s.jsx("div",{className:"text-sm opacity-70",children:"Meeting Room"}),s.jsx("button",{onClick:l,className:"absolute top-3 right-3 z-10 w-7 h-7 rounded-full bg-white/20 text-white flex items-center justify-center text-lg hover:bg-white/30 cursor-pointer",children:"×"}),s.jsx("div",{className:"text-xl font-bold mt-1",children:i.name}),s.jsxs("div",{className:"flex items-center gap-3 mt-3 text-sm",children:[s.jsxs("span",{children:["Tasks: ",g]}),s.jsxs("span",{children:["Done: ",f]}),s.jsxs("span",{children:["Progress: ",y,"%"]})]}),s.jsx("div",{className:"mt-2 h-1.5 bg-white/20 rounded-full overflow-hidden",children:s.jsx("div",{className:"h-full bg-white rounded-full transition-all",style:{width:`${y}%`}})})]}),s.jsxs("div",{className:"flex-1 overflow-y-auto p-5",children:[i.prd&&s.jsxs("div",{className:"mb-5",children:[s.jsx("div",{className:"text-[11px] font-bold uppercase tracking-wider mb-2",style:{color:"var(--terminal-text-muted)"},children:"PRD"}),s.jsx("div",{className:"rounded-lg p-4 text-xs leading-relaxed max-h-60 overflow-y-auto",style:{background:"var(--hud-bg-alt)",border:"1px solid var(--terminal-border)",color:"var(--terminal-text-secondary)"},children:s.jsx(Is,{content:i.prd})})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"text-[11px] font-bold uppercase tracking-wider mb-2",style:{color:"var(--terminal-text-muted)"},children:["Tasks (",g,")"]}),s.jsx("div",{className:"space-y-2",children:i.tasks.map(b=>s.jsxs("div",{className:"rounded-lg p-3",style:{background:"var(--hud-bg-alt)",border:"1px solid var(--terminal-border)"},children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm font-medium",style:{color:"var(--terminal-text)"},children:b.title}),s.jsx(aC,{status:b.status})]}),s.jsx("div",{className:"text-xs mt-1",style:{color:"var(--terminal-text-muted)"},children:b.role}),b.description&&s.jsx("div",{className:"text-xs mt-1.5 line-clamp-2",style:{color:"var(--terminal-text-secondary)"},children:b.description})]},b.id))})]})]})]})]})}function aC({status:t}){const l={done:{bg:"rgba(34,197,94,0.15)",color:"#4ade80"},"in-progress":{bg:"rgba(59,130,246,0.15)",color:"#60a5fa"},todo:{bg:"rgba(148,163,184,0.15)",color:"var(--terminal-text-muted)"}},r=l[t]??l.todo;return s.jsx("span",{className:"text-[10px] font-semibold px-2 py-0.5 rounded-full",style:{background:r.bg,color:r.color},children:t})}const iC={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C"};function sC({roleId:t,roleName:l,mode:r="assign",onClose:i,onExecutionStart:c}){const[u,d]=k.useState(""),m=k.useRef(null);k.useEffect(()=>{var y;(y=m.current)==null||y.focus()},[]);const x=()=>{u.trim()&&(c(t,u.trim()),i())},f=y=>{y.key==="Enter"&&(y.metaKey||y.ctrlKey)&&x(),y.key==="Escape"&&i()},g=iC[t]??"#666";return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 bg-black/40 z-[60] backdrop-blur-sm",onClick:i}),s.jsxs("div",{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[520px] z-[61] bg-[var(--wall)] rounded-2xl shadow-2xl overflow-hidden",children:[s.jsxs("div",{className:"p-5 text-white",style:{background:`linear-gradient(135deg, ${g}, ${g}cc)`},children:[s.jsx("div",{className:"text-lg font-bold",children:r==="ask"?"Ask":"Assign Task"}),s.jsx("div",{className:"text-sm opacity-80 mt-0.5",children:r==="ask"?`to ${l}`:`to ${l} (${t})`})]}),s.jsxs("div",{className:"p-5",children:[s.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-2",children:"Task Description"}),s.jsx("textarea",{ref:m,value:u,onChange:y=>d(y.target.value),onKeyDown:f,placeholder:r==="ask"?"What would you like to ask?":"Describe the task...",className:"w-full h-32 p-3 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 placeholder-white/25 resize-none focus:outline-none focus:border-white/25 transition-colors"}),s.jsx("div",{className:"text-[10px] text-white/30 mt-1",children:"Cmd+Enter to submit"})]}),s.jsxs("div",{className:"flex justify-end gap-3 px-5 pb-5",children:[s.jsx("button",{onClick:i,className:"px-4 py-2 text-sm rounded-lg border border-white/15 text-white/60 hover:bg-white/5 cursor-pointer",children:"Cancel"}),s.jsx("button",{onClick:x,disabled:!u.trim(),className:"px-5 py-2 text-sm text-white rounded-lg font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:g},children:r==="ask"?"Ask":"Assign"})]})]})]})}const k0={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C"};function mg({event:t,isThinkingCollapsed:l,onToggleThinking:r,onNavigateToJob:i,onOpenKnowledgeDoc:c,compact:u}){var m;const d=k0[t.roleId]??"#888";switch(t.type){case"text":{const x=t.data.text??"",f=u?x.slice(0,300):x;return/[#*|`\[\]_~>-]/.test(f)?s.jsx("div",{className:"text-green-300/90 leading-relaxed event-markdown",children:s.jsx(bh,{remarkPlugins:[jh],children:f})}):s.jsx("div",{className:"text-green-300/90 whitespace-pre-wrap leading-relaxed",children:f})}case"thinking":{const x=t.data.text??"";return s.jsxs("div",{className:"group",children:[s.jsxs("button",{onClick:r,className:"text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text-secondary)] text-[10px] cursor-pointer flex items-center gap-1",children:[s.jsx("span",{children:l?"▶":"▼"}),s.jsx("span",{className:"italic",children:"thinking..."})]}),!l&&s.jsxs("div",{className:`ml-3 text-[var(--terminal-text-muted)] italic whitespace-pre-wrap opacity-60 text-[11px] overflow-y-auto ${u?"max-h-[60px]":"max-h-[120px]"}`,children:[x.slice(0,u?200:500),x.length>(u?200:500)?"...":""]})]})}case"tool:start":{const x=String(t.data.name??""),f=t.data.input,g=typeof(f==null?void 0:f.command)=="string"?f.command.slice(0,80):"",y=typeof(f==null?void 0:f.file_path)=="string"?String(f.file_path):typeof(f==null?void 0:f.path)=="string"?String(f.path):"",b=y?y.split("/").pop()??"":"",v=/^(write_file|Write|edit_file|Edit)$/i.test(x),S=(m=y.match(/(?:^|\/)knowledge\/(.+\.md)$/))==null?void 0:m[1],j=v&&S&&c;return s.jsxs("div",{className:"flex items-center gap-2 py-0.5",children:[s.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${j?"text-green-400/80 bg-green-400/10":"text-blue-400/80 bg-blue-400/10"}`,children:j?v&&x.toLowerCase().includes("edit")?"Edit":"Write":x}),j?s.jsx("button",{onClick:()=>c(S),className:"text-[10px] text-green-400 hover:text-green-300 underline underline-offset-2 cursor-pointer truncate",style:{maxWidth:u?200:400},children:b}):s.jsxs(s.Fragment,{children:[g&&s.jsx("span",{className:`text-[var(--terminal-text-muted)] text-[10px] truncate ${u?"max-w-[200px]":"max-w-[400px]"}`,children:g}),b&&s.jsx("span",{className:`text-[var(--terminal-text-muted)] text-[10px] truncate ${u?"max-w-[200px]":"max-w-[400px]"}`,children:b})]})]})}case"dispatch:start":{const x=t.data.targetRoleId??t.data.roleId??"",f=t.data.task??"",g=t.data.childJobId,y=k0[x]??"#888";return s.jsx("div",{className:"my-1 p-2 rounded-lg border cursor-pointer hover:opacity-90 transition-opacity",style:{borderColor:`${y}44`,background:`${y}11`},onClick:()=>g&&(i==null?void 0:i(g)),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{style:{color:y},className:"font-bold text-[11px]",children:["→"," ",x.toUpperCase()]}),s.jsx("span",{className:"text-[var(--terminal-text-secondary)] text-[10px] truncate flex-1",children:f.slice(0,u?60:100)}),g&&i&&s.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-white/10 text-[var(--terminal-text-muted)]",children:["View ","→"]})]})})}case"dispatch:done":return s.jsx("div",{className:"text-[var(--terminal-text-muted)] text-[10px] pl-3 border-l-2 border-[var(--terminal-border)] my-0.5",children:"Dispatch completed"});case"turn:complete":return s.jsx("div",{className:"border-t border-[var(--terminal-border)] my-2 relative",children:s.jsxs("span",{className:"absolute -top-2 left-2 bg-[var(--terminal-bg)] px-2 text-[9px] text-[var(--terminal-text-muted)]",children:["Turn ",t.data.turn]})});case"stderr":return s.jsxs("div",{className:"text-red-400/80 text-[11px]",children:["⚠"," ",t.data.message]});case"job:start":return s.jsxs("div",{className:"text-[var(--terminal-text-muted)] text-[10px] pb-1",children:[s.jsx("span",{style:{color:d},className:"font-bold",children:t.roleId.toUpperCase()})," ","started: ",(t.data.task??"").slice(0,u?50:80)]});case"job:done":{const x=t.data.turns??0,f=t.data.toolCalls??0;return s.jsx("div",{className:"mt-2 p-2 rounded-lg bg-green-900/20 border border-green-800/30",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"}),s.jsx("span",{className:"text-green-300 font-bold text-[11px]",children:"Complete"}),s.jsxs("span",{className:"text-[var(--terminal-text-muted)] text-[10px]",children:[x," turns · ",f," tools"]})]})})}case"job:error":return s.jsx("div",{className:"mt-2 p-2 rounded-lg bg-red-900/20 border border-red-800/30",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"w-2 h-2 rounded-full bg-red-400"}),s.jsx("span",{className:"text-red-300 font-bold text-[11px]",children:"Error"}),s.jsx("span",{className:"text-red-200/70 text-[10px]",children:t.data.message})]})});case"job:awaiting_input":{const x=t.data.question??"";return s.jsxs("div",{className:"mt-2 p-2 rounded-lg border",style:{background:"#F59E0B11",borderColor:"#F59E0B33"},children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"w-2 h-2 rounded-full",style:{background:"#F59E0B",animation:"wave-pulse 1.5s ease-in-out infinite"}}),s.jsx("span",{className:"font-bold text-[11px]",style:{color:"#F59E0B"},children:"Awaiting Reply"})]}),x&&s.jsx("div",{className:"mt-1 text-[11px] text-[var(--terminal-text)] whitespace-pre-wrap",children:x})]})}case"job:reply":return s.jsx("div",{className:"mt-1 p-2 rounded-lg bg-blue-900/20 border border-blue-800/30",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-blue-300 font-bold text-[11px]",children:"CEO replied:"}),s.jsx("span",{className:"text-blue-200/80 text-[11px]",children:t.data.response??""})]})});case"import:scan":case"import:process":case"import:created":return s.jsxs("div",{className:"text-cyan-300/70 text-[11px]",children:["[",t.type,"] ",JSON.stringify(t.data)]});default:return null}}function oC({jobId:t,title:l,color:r,variant:i,style:c,onClose:u,onMinimize:d,onDone:m,onNavigateToJob:x,onOpenKnowledgeDoc:f}){const{events:g,status:y,textOutput:b,childJobIds:v}=K0(t),[S,j]=k.useState(0),[E,C]=k.useState(new Set),A=k.useRef(null),M=k.useRef(Date.now()),B=k.useRef(!1);k.useEffect(()=>{const U=setInterval(()=>{j(Math.floor((Date.now()-M.current)/1e3))},1e3);return()=>clearInterval(U)},[]),k.useEffect(()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)},[g]),k.useEffect(()=>{(y==="done"||y==="error")&&!B.current&&(B.current=!0,m==null||m())},[y,m]);const $=U=>{C(O=>{const J=new Set(O);return J.has(U)?J.delete(U):J.add(U),J})},_={idle:"Waiting",connecting:"Connecting...",streaming:"Working",done:"Complete",error:"Error"}[y],V={idle:"#888",connecting:"#888",streaming:r,done:"#2E7D32",error:"#C62828"}[y],G=U=>`${Math.floor(U/60)}:${String(U%60).padStart(2,"0")}`,Y=y==="done"||y==="error",T=s.jsxs("div",{className:i==="modal"?"fixed top-[5%] left-1/2 -translate-x-1/2 w-[720px] max-w-[95vw] h-[85vh] z-[61] bg-[var(--terminal-bg)] rounded-2xl shadow-2xl overflow-hidden flex flex-col":"bg-[var(--terminal-bg)] rounded-xl border border-[var(--terminal-border)] overflow-hidden flex flex-col max-h-[400px]",style:c,children:[s.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-[var(--terminal-border)] shrink-0",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-3 h-3 rounded-full animate-pulse",style:{background:V}}),s.jsx("div",{children:s.jsx("span",{className:"text-[var(--terminal-text)] font-bold text-sm",children:l})})]}),s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsx("span",{className:"text-[var(--terminal-text-muted)] text-xs font-mono",children:G(S)}),s.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full font-semibold",style:{background:`${V}22`,color:V},children:_}),d&&i==="modal"&&s.jsx("button",{onClick:d,title:"Minimize",className:"text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text)] text-sm cursor-pointer px-1",children:"–"}),Y&&s.jsx("button",{onClick:u,className:"text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text)] text-lg cursor-pointer",children:"×"})]})]}),s.jsxs("div",{ref:A,className:"flex-1 overflow-y-auto p-4 space-y-1 text-xs font-mono",children:[g.length===0&&y==="connecting"&&s.jsx("div",{className:"text-[var(--terminal-text-muted)]",children:"Connecting to activity stream..."}),g.map(U=>s.jsx(mg,{event:U,isThinkingCollapsed:E.has(U.seq),onToggleThinking:()=>$(U.seq),onNavigateToJob:x,onOpenKnowledgeDoc:f},U.seq)),y==="streaming"&&s.jsx("span",{className:"inline-block w-2 h-4 bg-green-400 animate-pulse ml-0.5"})]}),s.jsxs("div",{className:"px-5 py-3 border-t border-[var(--terminal-border)] flex items-center justify-between shrink-0",children:[s.jsxs("div",{className:"text-[10px] text-[var(--terminal-text-muted)]",children:[g.length>0&&`${g.length} events`,b.length>0&&` · ${b.length} chars`,v.length>0&&` · ${v.length} dispatches`]}),Y&&s.jsx("button",{onClick:u,className:"px-4 py-1.5 text-xs text-white rounded-lg font-semibold cursor-pointer",style:{background:r},children:"Close"})]})]});return i==="modal"?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 bg-black/40 z-[60] backdrop-blur-sm",onClick:Y?u:void 0}),T]}):T}const kf={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C","data-analyst":"#0277BD"};function cC({orgNodes:t,rootId:l}){const r=t[l];if(!r)return null;const c=r.children.map(m=>t[m]).filter(Boolean),u=[];for(const m of c)for(const x of m.children){const f=t[x];f&&u.push({node:f,parentId:m.id})}const d=c.length+u.length;return s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-2",children:"Propagation Preview"}),s.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-lg p-4",children:[s.jsx("div",{className:"flex justify-center mb-2",children:s.jsx("span",{className:"px-3 py-1 text-[10px] font-bold rounded border-2 border-white/20 bg-white/5 text-white/30 uppercase",children:"CEO"})}),c.length>0&&s.jsx("div",{className:"flex justify-center mb-1",children:s.jsx("div",{className:"w-px h-3 bg-white/15"})}),c.length>1&&s.jsx("div",{className:"flex justify-center mb-1",children:s.jsx("div",{className:"h-px bg-white/15",style:{width:`${Math.min(c.length*80,320)}px`}})}),s.jsx("div",{className:"flex justify-center gap-3 mb-2 flex-wrap",children:c.map(m=>s.jsxs("div",{className:"flex flex-col items-center",children:[s.jsx("span",{className:"px-2.5 py-1 text-[10px] font-bold rounded border-2 uppercase",style:{borderColor:kf[m.id]??"#888",color:kf[m.id]??"#888",background:`${kf[m.id]??"#888"}22`},children:m.id}),s.jsx("span",{className:"text-[8px] text-white/30 mt-0.5",children:"direct"})]},m.id))}),u.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex justify-center mb-1",children:s.jsx("div",{className:"w-px h-2 bg-white/10"})}),s.jsx("div",{className:"flex justify-center gap-2 flex-wrap",children:u.map(({node:m})=>s.jsx("span",{className:"px-2 py-0.5 text-[9px] font-semibold rounded border border-white/15 text-white/40 uppercase",children:m.id},m.id))}),s.jsx("div",{className:"text-center text-[8px] text-white/30 mt-1",children:"via re-dispatch"})]})]}),s.jsxs("div",{className:"text-[10px] text-gray-400 mt-1.5",children:[d," role",d!==1?"s":""," will receive this wave"]})]})}function uC({cLevelRoles:t,orgNodes:l,rootId:r,onClose:i,onDispatch:c}){const[u,d]=k.useState(""),m=k.useRef(null);k.useEffect(()=>{var y;(y=m.current)==null||y.focus()},[]);const x=()=>{!u.trim()||t.length===0||(c(u.trim()),i())},f=y=>{y.key==="Enter"&&(y.metaKey||y.ctrlKey)&&x(),y.key==="Escape"&&i()},g=r&&Object.keys(l).length>0;return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 bg-black/40 z-[60] backdrop-blur-sm",onClick:i}),s.jsxs("div",{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[560px] z-[61] bg-[var(--wall)] rounded-2xl shadow-2xl overflow-hidden",children:[s.jsxs("div",{className:"p-5 text-white",style:{background:"linear-gradient(135deg, #B71C1C, #D32F2F)"},children:[s.jsx("div",{className:"text-lg font-bold",children:"CEO Wave"}),s.jsx("div",{className:"text-sm opacity-80 mt-0.5",children:"Broadcast a directive to all C-Level reports"})]}),s.jsxs("div",{className:"p-5 space-y-4",children:[g&&s.jsx(cC,{orgNodes:l,rootId:r}),!g&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-2",children:"Dispatching to"}),s.jsx("div",{className:"flex gap-2 flex-wrap",children:t.length>0?t.map(y=>s.jsxs("span",{className:"px-3 py-1.5 text-xs font-semibold rounded-lg border-2 border-red-200 bg-red-50 text-red-800",children:[y.id.toUpperCase()," · ",y.name]},y.id)):s.jsx("span",{className:"text-xs text-gray-400 italic",children:"No C-Level roles found"})}),s.jsx("div",{className:"text-[10px] text-gray-400 mt-1",children:"Each C-Level receives the directive and delegates to their reports"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-2",children:"Directive"}),s.jsx("textarea",{ref:m,value:u,onChange:y=>d(y.target.value),onKeyDown:f,placeholder:"e.g. Report current status across all departments",className:"w-full h-28 p-3 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 placeholder-white/25 resize-none focus:outline-none focus:border-white/25 transition-colors"}),s.jsx("div",{className:"text-[10px] text-gray-400 mt-1",children:"Cmd+Enter to dispatch"})]})]}),s.jsxs("div",{className:"flex justify-end gap-3 px-5 pb-5",children:[s.jsx("button",{onClick:i,className:"px-4 py-2 text-sm rounded-lg border border-white/15 text-white/60 hover:bg-white/5 cursor-pointer",children:"Cancel"}),s.jsxs("button",{onClick:x,disabled:!u.trim()||t.length===0,className:"px-5 py-2 text-sm text-white rounded-lg font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#B71C1C"},children:["Dispatch to ",t.length," Role",t.length!==1?"s":""]})]})]})]})}function dC(t,l,r){const[i,c]=k.useState(new Map),[u,d]=k.useState(null),m=k.useRef(new Map),x=k.useRef(i);x.current=i,k.useEffect(()=>{if(!r||Object.keys(l).length===0)return;const b=new Map,v=j=>{const E=l[j];E&&(b.set(j,{jobId:null,roleId:j,roleName:E.name,children:E.children,status:"waiting",events:[],streamStatus:"idle"}),E.children.forEach(v))},S=l[r];S&&(b.set(r,{jobId:null,roleId:r,roleName:"CEO",children:S.children,status:"not-dispatched",events:[],streamStatus:"idle"}),S.children.forEach(v));for(const j of t){const E=b.get(j.roleId);E&&(E.jobId=j.jobId,E.status="running",E.streamStatus="connecting")}c(b),t.length>0&&d(t[0].roleId)},[t,l,r]);const f=k.useCallback((b,v)=>{const S=m.current.get(b);S&&S.controller.abort();const j=new AbortController,E={controller:j,lastSeq:-1};m.current.set(b,E);const A=`/api/jobs/${b}/stream?from=0`;fetch(A,{signal:j.signal}).then(async M=>{if(!M.ok||!M.body){c(V=>{const G=new Map(V),Y=G.get(v);return Y&&G.set(v,{...Y,streamStatus:"error"}),G});return}c(V=>{const G=new Map(V),Y=G.get(v);return Y&&G.set(v,{...Y,streamStatus:"streaming",status:"running"}),G});const B=M.body.getReader(),$=new TextDecoder;let _="";for(;;){const{done:V,value:G}=await B.read();if(V)break;_+=$.decode(G,{stream:!0});const Y=_.split(`
81
- `);_=Y.pop()??"";let T="";for(const U of Y)if(U.startsWith("event: "))T=U.slice(7).trim();else if(U.startsWith("data: ")){try{const O=JSON.parse(U.slice(6));if(T==="activity"){const J=O;J.seq>E.lastSeq&&(E.lastSeq=J.seq),c(ne=>{const K=new Map(ne),I=K.get(v);if(!I||I.events.some(me=>me.seq===J.seq))return ne;const W={...I,events:[...I.events,J]};if(J.type==="dispatch:start"&&J.data.childJobId){const me=J.data.childJobId,Se=J.data.targetRoleId??J.data.roleId;if(Se){const D=K.get(Se);D&&(K.set(Se,{...D,jobId:me,status:"running",streamStatus:"connecting"}),setTimeout(()=>f(me,Se),0))}}return J.type==="job:done"?(W.status="done",W.streamStatus="done"):J.type==="job:error"?(W.status="error",W.streamStatus="error"):J.type==="job:awaiting_input"?(W.status="awaiting_input",W.streamStatus="done"):J.type==="job:reply"&&(W.status="running",W.streamStatus="streaming"),K.set(v,W),K})}else if(T==="stream:end"){const J=O.reason;J!=="replied"&&c(ne=>{const K=new Map(ne),I=K.get(v);if(!I)return ne;const W=J==="error"?"error":J==="awaiting_input"?"awaiting_input":"done";return K.set(v,{...I,status:I.status==="running"?W:I.status,streamStatus:W==="error"?"error":"done"}),K})}}catch{}T=""}}}).catch(M=>{M.name!=="AbortError"&&c(B=>{const $=new Map(B),_=$.get(v);return _&&$.set(v,{..._,streamStatus:"error"}),$})})},[]);k.useEffect(()=>{if(t.length!==0){for(const b of t)f(b.jobId,b.roleId);return()=>{for(const[,b]of m.current)b.controller.abort();m.current.clear()}}},[t,f]);const g=(()=>{let b=0,v=0,S=0,j=0;for(const[E,C]of i)E!==r&&(j++,C.status==="done"?b++:C.status==="running"?v++:C.status==="awaiting_input"&&S++);return{done:b,total:j,running:v,awaitingInput:S}})(),y=g.total>0&&g.running===0&&g.awaitingInput===0&&Array.from(i.values()).every(b=>b.status!=="running"&&b.status!=="awaiting_input"&&b.streamStatus!=="streaming"&&b.streamStatus!=="connecting");return k.useEffect(()=>{y&&c(b=>{const v=new Map(b);let S=!1;for(const[j,E]of v)E.status==="waiting"&&(v.set(j,{...E,status:"not-dispatched"}),S=!0);return S?v:b})},[y]),{nodes:i,selectedRoleId:u,selectNode:d,progress:g,allDone:y,connectStream:f}}const j0={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C","data-analyst":"#0277BD"},ga=120,tr=44,S0=80;function fC(t,l){if(!t.get(l))return{layout:[],width:300,height:200};const i=[],c=[],u=[{id:l,depth:0,parentId:null}],d=new Set;for(;u.length>0;){const{id:g,depth:y,parentId:b}=u.shift();if(d.has(g))continue;for(d.add(g);c.length<=y;)c.push([]);c[y].push(g),i.push({roleId:g,x:0,y:y*S0+20,parentId:b});const v=t.get(g);if(v)for(const S of v.children)t.has(S)&&!d.has(S)&&u.push({id:S,depth:y+1,parentId:g})}const m=Math.max(...c.map(g=>g.length))*(ga+16),x=Math.max(m,280);for(const g of c){const y=g.length*(ga+16)-16,b=(x-y)/2;g.forEach((v,S)=>{const j=i.find(E=>E.roleId===v);j&&(j.x=b+S*(ga+16))})}const f=c.length*S0+40;return{layout:i,width:x,height:f}}function hC({nodes:t,rootId:l,selectedRoleId:r,onSelectNode:i}){const{layout:c,width:u,height:d}=fC(t,l),m=f=>{const g=c.find(y=>y.roleId===f);return g?{cx:g.x+ga/2,cy:g.y+tr/2}:{cx:0,cy:0}},x=f=>{switch(f.status){case"running":return j0[f.roleId]??"#FBBF24";case"awaiting_input":return"#F59E0B";case"done":return"#2E7D32";case"error":return"#C62828";case"not-dispatched":return"#666";default:return"#888"}};return s.jsxs("svg",{viewBox:`0 0 ${u} ${d}`,width:Math.max(u,280),height:d,className:"block",style:{minWidth:u},children:[s.jsx("defs",{children:s.jsxs("filter",{id:"glow",children:[s.jsx("feGaussianBlur",{stdDeviation:"2",result:"blur"}),s.jsxs("feMerge",{children:[s.jsx("feMergeNode",{in:"blur"}),s.jsx("feMergeNode",{in:"SourceGraphic"})]})]})}),c.filter(f=>f.parentId).map(f=>{const g=m(f.parentId),y=m(f.roleId),b=t.get(f.roleId),v=t.get(f.parentId);let S="rgba(180,200,240,0.15)",j="4 4",E="";return(b==null?void 0:b.status)==="done"||(v==null?void 0:v.status)==="done"?(S="#2E7D3266",j=""):(b==null?void 0:b.status)==="awaiting_input"?(S="#F59E0B",j="6 4",E="wave-edge-flow"):(b==null?void 0:b.status)==="running"&&(S=j0[f.roleId]??"#FBBF24",j="6 4",E="wave-edge-flow"),s.jsx("line",{x1:g.cx,y1:g.cy+tr/2-4,x2:y.cx,y2:y.cy-tr/2+4,stroke:S,strokeWidth:1.5,strokeDasharray:j,className:E},`${f.parentId}-${f.roleId}`)}),c.map(f=>{const g=t.get(f.roleId);if(!g)return null;const y=x(g),b=r===f.roleId,v=f.roleId===l,S=v?.4:g.status==="not-dispatched"?.35:1;return s.jsxs("g",{transform:`translate(${f.x}, ${f.y})`,style:{cursor:v?"default":"pointer",opacity:S},onClick:()=>!v&&i(f.roleId),children:[s.jsx("rect",{x:0,y:0,width:ga,height:tr,rx:8,ry:8,fill:"var(--terminal-bg-deeper, #181825)",stroke:b?"#fff":y,strokeWidth:b?2:1.5,strokeDasharray:g.status==="not-dispatched"?"4 3":""}),s.jsx("circle",{cx:14,cy:tr/2,r:4,fill:y,filter:g.status==="running"||g.status==="awaiting_input"?"url(#glow)":void 0,children:(g.status==="running"||g.status==="awaiting_input")&&s.jsx("animate",{attributeName:"opacity",values:"1;0.4;1",dur:"1.5s",repeatCount:"indefinite"})}),s.jsx("text",{x:26,y:tr/2-4,fill:"var(--terminal-text, #fff)",fontSize:10,fontWeight:700,fontFamily:"var(--pixel-font)",children:g.roleId.toUpperCase()}),s.jsx("text",{x:26,y:tr/2+10,fill:"var(--terminal-text-muted, #888)",fontSize:8,fontFamily:"var(--pixel-font)",children:g.status==="running"?"Working...":g.status==="awaiting_input"?"Awaiting Reply":g.status==="done"?"Complete":g.status==="error"?"Error":g.status==="waiting"?"Waiting":""}),g.status==="done"&&s.jsx("text",{x:ga-18,y:tr/2+4,fontSize:14,fill:"#2E7D32",children:"✓"}),g.status==="error"&&s.jsx("text",{x:ga-18,y:tr/2+4,fontSize:14,fill:"#C62828",children:"✗"})]},f.roleId)})]})}const mC={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C","data-analyst":"#0277BD"};function xC({directive:t,rootJobs:l,orgNodes:r,rootRoleId:i,onClose:c,onMinimize:u,onDone:d,onOpenKnowledgeDoc:m,onSave:x}){const{nodes:f,selectedRoleId:g,selectNode:y,progress:b,allDone:v,connectStream:S}=dC(l,r,i),[j,E]=k.useState(0),[C,A]=k.useState(new Set),[M,B]=k.useState(""),[$,_]=k.useState(!1),[V,G]=k.useState(!1),Y=k.useRef(null),T=k.useRef(Date.now()),U=k.useRef(!1),O=k.useCallback(async()=>{if(x){G(!0);try{const D=l.map(F=>F.jobId);await x(D)}catch(D){console.error("Save failed:",D)}finally{G(!1),c()}}},[x,l,c]),J=k.useCallback(async()=>{if(!g||!M.trim())return;const D=f.get(g);if(!(!(D!=null&&D.jobId)||D.status!=="awaiting_input")){_(!0);try{const{jobId:F}=await Ne.replyToJob(D.jobId,M.trim());B(""),S(F,g)}catch(F){console.error("Reply failed:",F)}finally{_(!1)}}},[g,M,f,S]),ne=k.useCallback(async D=>{const F=f.get(D);if(F!=null&&F.jobId)try{await Ne.abortJob(F.jobId)}catch(Q){console.error("Abort failed:",Q)}},[f]),K=k.useCallback(async()=>{for(const[,D]of f)if((D.status==="running"||D.status==="awaiting_input")&&D.jobId)try{await Ne.abortJob(D.jobId)}catch{}},[f]);k.useEffect(()=>{const D=setInterval(()=>{E(Math.floor((Date.now()-T.current)/1e3))},1e3);return()=>clearInterval(D)},[]),k.useEffect(()=>{Y.current&&(Y.current.scrollTop=Y.current.scrollHeight)},[g,f]),k.useEffect(()=>{v&&!U.current&&(U.current=!0,d==null||d())},[v,d]);const I=D=>`${Math.floor(D/60)}:${String(D%60).padStart(2,"0")}`,W=g?f.get(g):null,me=g?mC[g]??"#888":"#888",Se=D=>{A(F=>{const Q=new Set(F);return Q.has(D)?Q.delete(D):Q.add(D),Q})};return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 bg-black/40 z-[60] backdrop-blur-sm"}),s.jsxs("div",{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[960px] max-w-[95vw] h-[85vh] z-[61] bg-[var(--terminal-bg)] rounded-2xl shadow-2xl overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-[var(--terminal-border)] shrink-0",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-3 h-3 rounded-full",style:{background:v?"#2E7D32":"#B71C1C",animation:v?void 0:"wave-pulse 2s ease-in-out infinite"}}),s.jsx("div",{children:s.jsx("span",{className:"text-[var(--terminal-text)] font-bold text-sm",children:v?"WAVE COMPLETE":"WAVE COMMAND CENTER"})})]}),s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsx("span",{className:"text-[var(--terminal-text-muted)] text-xs font-mono",children:I(j)}),b.awaitingInput>0&&s.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full font-semibold",style:{background:"#F59E0B22",color:"#F59E0B"},children:[b.awaitingInput," awaiting reply"]}),s.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full font-semibold",style:{background:v?"#2E7D3222":"#B71C1C22",color:v?"#2E7D32":"#B71C1C"},children:[b.done,"/",b.total," done"]}),!v&&(b.running>0||b.awaitingInput>0)&&s.jsx("button",{onClick:K,className:"text-xs px-2 py-0.5 rounded font-semibold cursor-pointer",style:{background:"#C6282822",color:"#C62828",border:"1px solid #C6282844"},title:"Stop all running jobs",children:"Stop All"}),s.jsx("button",{onClick:u,title:"Minimize",className:"text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text)] text-sm cursor-pointer px-1",children:"–"}),s.jsx("button",{onClick:c,className:"text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text)] text-lg cursor-pointer",title:v?"Dismiss wave":"Close (jobs keep running)",children:"×"})]})]}),s.jsx("div",{className:"px-5 py-2 border-b border-[var(--terminal-border)] shrink-0",children:s.jsxs("span",{className:"text-[var(--terminal-text-secondary)] text-xs italic",children:["“",t,"”"]})}),s.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[s.jsxs("div",{className:"shrink-0 border-b border-[var(--terminal-border)] flex flex-col",children:[s.jsxs("div",{className:"flex items-center gap-3 px-4 py-1.5",children:[s.jsx("span",{className:"text-[10px] font-bold text-[var(--terminal-text-secondary)] uppercase tracking-wider",children:"Org Propagation"}),s.jsx("div",{className:"flex gap-x-3 ml-auto",children:[{label:"running",color:"#FBBF24",dot:!0},{label:"awaiting",color:"#F59E0B",dot:!0},{label:"done",color:"#2E7D32",dot:!1},{label:"waiting",color:"#888",dot:!1},{label:"error",color:"#C62828",dot:!1}].map(D=>s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"w-2 h-2 rounded-full inline-block",style:{background:D.color,animation:D.dot?"wave-pulse 1.5s ease-in-out infinite":void 0}}),s.jsx("span",{className:"text-[8px] text-[var(--terminal-text-muted)]",children:D.label})]},D.label))})]}),s.jsx("div",{className:"overflow-x-auto overflow-y-auto px-3 pb-2",style:{maxHeight:"35vh"},children:s.jsx(hC,{nodes:f,rootId:i,selectedRoleId:g,onSelectNode:y})})]}),s.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[W&&s.jsxs("div",{className:"px-4 py-2 border-b border-[var(--terminal-border)] shrink-0 flex items-center gap-2",children:[s.jsx("div",{className:"w-2 h-2 rounded-full",style:{background:me}}),s.jsx("span",{className:"text-[var(--terminal-text)] font-bold text-xs",children:W.roleId.toUpperCase()}),s.jsx("span",{className:"text-[var(--terminal-text-muted)] text-xs",children:W.roleName}),s.jsx("span",{className:"ml-auto text-[10px] px-2 py-0.5 rounded-full font-semibold",style:{background:W.status==="awaiting_input"?"#F59E0B22":`${me}22`,color:W.status==="awaiting_input"?"#F59E0B":me},children:W.status==="running"?"Working":W.status==="done"?"Complete":W.status==="error"?"Error":W.status==="waiting"?"Waiting":W.status==="awaiting_input"?"Awaiting Reply":"Not dispatched"}),(W.status==="running"||W.status==="awaiting_input")&&W.jobId&&s.jsx("button",{onClick:()=>ne(W.roleId),className:"text-[10px] px-2 py-0.5 rounded font-semibold cursor-pointer ml-1",style:{background:"#C6282822",color:"#C62828",border:"1px solid #C6282844"},title:"Force stop this job",children:"Stop"})]}),s.jsxs("div",{ref:Y,className:"flex-1 overflow-y-auto p-4 space-y-1 text-xs font-mono",children:[W&&W.events.length===0&&s.jsx("div",{className:"text-[var(--terminal-text-muted)]",children:W.status==="waiting"?"Waiting for dispatch...":W.status==="running"?"Connecting to activity stream...":W.status==="not-dispatched"?"This role was not dispatched in this wave.":""}),W==null?void 0:W.events.map(D=>s.jsx(mg,{event:D,isThinkingCollapsed:C.has(D.seq),onToggleThinking:()=>Se(D.seq),onNavigateToJob:F=>{for(const[,Q]of f)if(Q.jobId===F){y(Q.roleId);return}},onOpenKnowledgeDoc:m},D.seq)),(W==null?void 0:W.status)==="running"&&s.jsx("span",{className:"inline-block w-2 h-4 bg-green-400 animate-pulse ml-0.5"})]}),(W==null?void 0:W.status)==="awaiting_input"&&s.jsxs("div",{className:"px-4 py-3 border-t border-[var(--terminal-border)] shrink-0",style:{background:"#F59E0B0A"},children:[s.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[s.jsx("span",{className:"w-2 h-2 rounded-full inline-block",style:{background:"#F59E0B",animation:"wave-pulse 1.5s ease-in-out infinite"}}),s.jsxs("span",{className:"text-[11px] font-semibold",style:{color:"#F59E0B"},children:[W.roleName," is waiting for your response"]})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{type:"text",value:M,onChange:D=>B(D.target.value),onKeyDown:D=>{D.key==="Enter"&&!D.shiftKey&&(D.preventDefault(),J())},placeholder:"Type your response...",disabled:$,className:"flex-1 px-3 py-1.5 text-xs rounded border bg-[var(--terminal-bg)] text-[var(--terminal-text)] border-[var(--terminal-border)] outline-none focus:border-[#F59E0B]",autoFocus:!0}),s.jsx("button",{onClick:J,disabled:$||!M.trim(),className:"px-4 py-1.5 text-xs rounded font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#F59E0B",color:"#000"},children:$?"...":"Reply"})]})]}),!W&&s.jsx("div",{className:"flex-1 flex items-center justify-center text-[var(--terminal-text-muted)] text-xs",children:"Click a node in the org tree to view activity"}),s.jsxs("div",{className:"px-4 py-2 border-t border-[var(--terminal-border)] flex items-center justify-between shrink-0",children:[s.jsx("div",{className:"text-[10px] text-[var(--terminal-text-muted)]",children:W&&W.events.length>0&&`${W.events.length} events`}),v&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("button",{onClick:c,className:"px-4 py-1.5 text-xs rounded-lg font-semibold cursor-pointer",style:{background:"rgba(255,255,255,0.08)",color:"var(--terminal-text-muted)"},children:"Dismiss"}),x&&s.jsx("button",{onClick:O,disabled:V,className:"px-4 py-1.5 text-xs text-white rounded-lg font-semibold cursor-pointer disabled:opacity-50",style:{background:"#2E7D32"},children:V?"Saving...":"Save Wave"})]})]})]})]})]})]})}const pC={cto:{skinColor:"#F5CBA7",hairColor:"#2C1810",shirtColor:"#1565C0",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"short",outfitStyle:"tshirt",accessory:"glasses"},cbo:{skinColor:"#FDEBD0",hairColor:"#1A0A00",shirtColor:"#E65100",pantsColor:"#37474F",shoeColor:"#1A1A1A",hairStyle:"slicked",outfitStyle:"suit",accessory:"lapels"},pm:{skinColor:"#FDEBD0",hairColor:"#6D4C41",shirtColor:"#2E7D32",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"bun",outfitStyle:"tshirt",accessory:"blush"},engineer:{skinColor:"#F5CBA7",hairColor:"#1A1A1A",shirtColor:"#4A148C",pantsColor:"#37474F",shoeColor:"#7B1FA2",hairStyle:"messy",outfitStyle:"hoodie",accessory:"headphones"},designer:{skinColor:"#FDEBD0",hairColor:"#AD1457",shirtColor:"#AD1457",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"bob",outfitStyle:"tshirt",accessory:"beret"},qa:{skinColor:"#F5CBA7",hairColor:"#4E342E",shirtColor:"#00695C",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"short",outfitStyle:"tshirt",accessory:"badge"},"data-analyst":{skinColor:"#F5CBA7",hairColor:"#3E2723",shirtColor:"#0277BD",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"curly",outfitStyle:"vest",accessory:"none"}};function Th(t){return pC[t]??{skinColor:"#B0BEC5",hairColor:"#78909C",shirtColor:"#607D8B",pantsColor:"#455A64",shoeColor:"#37474F"}}const xg=["#FDEBD0","#F5CBA7","#D4A07A","#C68642","#8D5524","#5C3A1E","#F3D1C7","#E8BEAC","#B07D62","#704214"],pg=["#1A0A00","#2C1810","#4E342E","#6D4C41","#8D6E63","#D4A574","#F5E6CA","#FFD700","#B71C1C","#AD1457","#4A148C","#1A237E","#004D40","#1A1A1A","#78909C","#E0E0E0"],yg=["#1565C0","#E65100","#2E7D32","#4A148C","#AD1457","#00695C","#D32F2F","#F57F17","#1B5E20","#283593","#4E342E","#37474F","#880E4F","#00838F","#6A1B9A","#FF6F00"],gg=["#37474F","#1A237E","#3E2723","#263238","#1B5E20","#455A64","#212121","#4E342E","#0D47A1","#311B92"],bg=["#212121","#1A1A1A","#37474F","#4E342E","#7B1FA2","#D32F2F","#1565C0","#F57F17","#2E7D32","#FFFFFF"],Yr={default:{name:"MIDNIGHT",icon:"🌃",vars:{"--floor-light":"#0d1117","--floor-dark":"#0a0e14","--hud-bg":"#0d1117","--hud-bg-alt":"#161b22","--pixel-border":"#30363d","--terminal-bg":"#0d1117","--terminal-border":"#21262d","--terminal-border-hover":"#388bfd","--terminal-text":"#e6edf3","--terminal-text-secondary":"#8b949e","--terminal-text-muted":"#484f58","--accent":"#388bfd","--active-green":"#3fb950","--idle-amber":"#d29922"}},light:{name:"DAYLIGHT",icon:"☀️",vars:{"--floor-light":"#f6f8fa","--floor-dark":"#eaeef2","--hud-bg":"#24292f","--hud-bg-alt":"#32383f","--pixel-border":"#d0d7de","--terminal-bg":"#ffffff","--terminal-border":"#d0d7de","--terminal-border-hover":"#0969da","--terminal-text":"#1f2328","--terminal-text-secondary":"#656d76","--terminal-text-muted":"#8c959f","--accent":"#0969da","--active-green":"#1a7f37","--idle-amber":"#9a6700"}},retro:{name:"RETRO",icon:"🎮",vars:{"--floor-light":"#1a1410","--floor-dark":"#140f0a","--hud-bg":"#1a1410","--hud-bg-alt":"#2a2018","--pixel-border":"#5c4a32","--terminal-bg":"#1a1410","--terminal-border":"#3a2e20","--terminal-border-hover":"#d4a44e","--terminal-text":"#e8d5b0","--terminal-text-secondary":"#a08860","--terminal-text-muted":"#6b5840","--accent":"#d4a44e","--active-green":"#8bba4a","--idle-amber":"#e8a030"}},cyberpunk:{name:"NEON",icon:"🌌",vars:{"--floor-light":"#0a0014","--floor-dark":"#06000e","--hud-bg":"#0a0014","--hud-bg-alt":"#14002a","--pixel-border":"#4a1a80","--terminal-bg":"#0a0014","--terminal-border":"#2a0a50","--terminal-border-hover":"#e040fb","--terminal-text":"#e0d0ff","--terminal-text-secondary":"#9070c0","--terminal-text-muted":"#5a3a80","--accent":"#e040fb","--active-green":"#00ff88","--idle-amber":"#ffab00"}},forest:{name:"FOREST",icon:"🌲",vars:{"--floor-light":"#0a1410","--floor-dark":"#060e0a","--hud-bg":"#0a1410","--hud-bg-alt":"#142a1e","--pixel-border":"#2a5a3a","--terminal-bg":"#0a1410","--terminal-border":"#1a3a26","--terminal-border-hover":"#4ade80","--terminal-text":"#d0f0d8","--terminal-text-secondary":"#70a880","--terminal-text-muted":"#3a6848","--accent":"#4ade80","--active-green":"#86efac","--idle-amber":"#fcd34d"}},ocean:{name:"OCEAN",icon:"🌊",vars:{"--floor-light":"#0a1420","--floor-dark":"#060e18","--hud-bg":"#0a1420","--hud-bg-alt":"#142a40","--pixel-border":"#1e4a6a","--terminal-bg":"#0a1420","--terminal-border":"#163050","--terminal-border-hover":"#38bdf8","--terminal-text":"#d0e8f8","--terminal-text-secondary":"#6090b0","--terminal-text-muted":"#305070","--accent":"#38bdf8","--active-green":"#34d399","--idle-amber":"#fbbf24"}}};function yC({color:t,selected:l,onClick:r}){return s.jsx("button",{onClick:r,className:"customize-swatch",style:{background:t,outline:l?"2px solid #fff":"2px solid transparent",boxShadow:l?`0 0 0 1px ${t}, 0 0 6px ${t}88`:"none"}})}function ks({label:t,presets:l,value:r,onChange:i}){return s.jsxs("div",{className:"customize-row",children:[s.jsxs("div",{className:"customize-row-header",children:[s.jsx("span",{className:"customize-row-label",children:t}),s.jsx("div",{className:"customize-row-current",style:{background:r}})]}),s.jsx("div",{className:"customize-swatches",children:l.map(c=>s.jsx(yC,{color:c,selected:c===r,onClick:()=>i(c)},c))})]})}function jf({label:t,items:l,value:r,onChange:i,lockInfo:c}){return s.jsxs("div",{className:"customize-row",children:[s.jsx("div",{className:"customize-row-header",children:s.jsx("span",{className:"customize-row-label",children:t})}),s.jsx("div",{className:"customize-swatches",style:{gap:4},children:l.map(u=>{const d=c?c.getLockLevel(u.id):1,m=u.id===r,x=c?d>c.roleLevel&&!m:!1,f=c?m&&d>c.roleLevel:!1;return s.jsxs("button",{onClick:()=>{x||i(u.id===r?void 0:u.id)},className:"customize-swatch",style:{width:"auto",height:"auto",padding:x?"2px 6px 10px 6px":"2px 6px",fontSize:9,fontFamily:"var(--font-pixel, monospace)",background:m?"rgba(255,255,255,0.15)":x?"rgba(255,255,255,0.02)":"rgba(255,255,255,0.04)",outline:m?f?"2px solid #F59E0B":"2px solid #fff":"2px solid transparent",color:x?"rgba(255,255,255,0.25)":m?"#fff":"rgba(255,255,255,0.5)",borderRadius:4,cursor:x?"not-allowed":"pointer",opacity:x?.35:1,position:"relative"},children:[u.name,x&&s.jsxs("span",{style:{position:"absolute",bottom:1,left:"50%",transform:"translateX(-50%)",fontSize:8,color:"rgba(255,255,255,0.5)",whiteSpace:"nowrap"},children:["🔒"," Lv.",d]}),f&&s.jsxs("span",{style:{position:"absolute",bottom:-8,left:"50%",transform:"translateX(-50%)",fontSize:7,color:"#F59E0B",whiteSpace:"nowrap"},children:["⚠"," Lv.",d]})]},u.id)})})]})}function Sf({label:t,active:l,onClick:r}){return s.jsx("button",{onClick:r,style:{flex:1,padding:"6px 0",fontSize:10,fontFamily:"var(--font-pixel, monospace)",fontWeight:"bold",letterSpacing:1,background:l?"rgba(255,255,255,0.08)":"transparent",color:l?"#fff":"rgba(255,255,255,0.35)",border:"none",borderBottom:l?"2px solid #3B82F6":"2px solid transparent",cursor:"pointer",transition:"all 0.15s"},children:t})}function Lr(t){return t[Math.floor(Math.random()*t.length)]}function hi(t){var c,u,d;const l=ng(),r=lg(),i=rg().filter(m=>!t||ig(m.id,t));return{skinColor:Lr(xg),hairColor:Lr(pg),shirtColor:Lr(yg),pantsColor:Lr(gg),shoeColor:Lr(bg),hairStyle:(c=Lr(l))==null?void 0:c.id,outfitStyle:(u=Lr(r))==null?void 0:u.id,accessory:(d=Lr(i))==null?void 0:d.id}}function vg({roleId:t,appearance:l,onChange:r,onRandomize:i,onReset:c,label:u,roleLevel:d}){const[m,x]=k.useState("look"),f=k.useCallback((E,C)=>{r({...l,[E]:C})},[l,r]),g=k.useRef(null),y=k.useCallback(E=>{var M;const C=(M=E.target.files)==null?void 0:M[0];if(!C)return;const A=new Image;A.onload=()=>{const B=Hj(A);r({...B,hairStyle:l.hairStyle,outfitStyle:l.outfitStyle,accessory:l.accessory}),URL.revokeObjectURL(A.src)},A.src=URL.createObjectURL(C),E.target.value=""},[l.hairStyle,l.outfitStyle,l.accessory,r]),b=ng(),v=lg(),S=rg(),j=d!==void 0?S.filter(E=>ig(E.id,d)).length:S.length;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"customize-preview",children:[s.jsx("div",{className:"customize-preview-bg",children:s.jsx(_s,{roleId:t,appearance:l,scale:12})}),u&&s.jsx("div",{className:"customize-preview-name",children:u}),s.jsxs("div",{className:"customize-preview-actions",children:[s.jsx("button",{className:"customize-btn customize-btn--random",onClick:i,children:"RANDOM"}),s.jsx("button",{className:"customize-btn customize-btn--reset",onClick:c,children:"RESET"}),s.jsx("button",{className:"customize-btn",onClick:()=>{var E;return(E=g.current)==null?void 0:E.click()},style:{fontSize:9,opacity:.7},children:"PHOTO"}),s.jsx("input",{ref:g,type:"file",accept:"image/*",onChange:y,style:{display:"none"}})]})]}),s.jsxs("div",{className:"customize-colors",children:[s.jsxs("div",{style:{display:"flex",borderBottom:"1px solid rgba(255,255,255,0.06)",marginBottom:4},children:[s.jsx(Sf,{label:"LOOK",active:m==="look",onClick:()=>x("look")}),s.jsx(Sf,{label:"OUTFIT",active:m==="outfit",onClick:()=>x("outfit")}),s.jsx(Sf,{label:"ACCESSORY",active:m==="accessory",onClick:()=>x("accessory")})]}),m==="look"&&s.jsxs(s.Fragment,{children:[s.jsx(ks,{label:"SKIN",presets:xg,value:l.skinColor,onChange:E=>f("skinColor",E)}),s.jsx(ks,{label:"HAIR COLOR",presets:pg,value:l.hairColor,onChange:E=>f("hairColor",E)}),s.jsx(jf,{label:"HAIR STYLE",items:b,value:l.hairStyle,onChange:E=>f("hairStyle",E)})]}),m==="outfit"&&s.jsxs(s.Fragment,{children:[s.jsx(jf,{label:"STYLE",items:v,value:l.outfitStyle,onChange:E=>f("outfitStyle",E)}),s.jsx(ks,{label:"TOP",presets:yg,value:l.shirtColor,onChange:E=>f("shirtColor",E)}),s.jsx(ks,{label:"PANTS",presets:gg,value:l.pantsColor,onChange:E=>f("pantsColor",E)}),s.jsx(ks,{label:"SHOES",presets:bg,value:l.shoeColor,onChange:E=>f("shoeColor",E)})]}),m==="accessory"&&s.jsxs(s.Fragment,{children:[d!==void 0&&s.jsxs("div",{style:{padding:"4px 8px",marginBottom:4,background:"rgba(255,255,255,0.04)",borderRadius:4,fontSize:9,fontFamily:"var(--font-pixel, monospace)",color:"rgba(255,255,255,0.5)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s.jsxs("span",{children:["Lv.",d]}),s.jsxs("span",{children:[j,"/",S.length," unlocked"]})]}),s.jsx(jf,{label:"ACCESSORY",items:S,value:l.accessory,onChange:E=>f("accessory",E),lockInfo:d!==void 0?{roleLevel:d,getLockLevel:ag}:void 0}),s.jsx("div",{style:{marginTop:12,padding:"8px 10px",background:"rgba(255,255,255,0.03)",borderRadius:6,border:"1px dashed rgba(255,255,255,0.08)",color:"rgba(255,255,255,0.25)",fontSize:9,fontFamily:"var(--font-pixel, monospace)",textAlign:"center"},children:d!==void 0&&d<10?"Level up to unlock more accessories":"More accessories coming soon"})]})]})]})}const gC=[{value:"c-level",label:"C-Level"},{value:"team-lead",label:"Team Lead"},{value:"member",label:"Member"}];function Pf(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,24)}function Cf(t){switch(t){case"c-level":return{authority:{autonomous:["Strategic decisions within domain","Task delegation to reports"],needsApproval:["Budget over $5K","External commitments"]},knowledge:{reads:["company/","operations/","projects/"],writes:["operations/","knowledge/"]},reports:{daily:"standup",weekly:"summary"}};case"team-lead":return{authority:{autonomous:["Task planning","Sprint management"],needsApproval:["Architecture changes","New tool adoption"]},knowledge:{reads:["projects/","architecture/"],writes:["projects/"]},reports:{daily:"standup",weekly:"summary"}};default:return{authority:{autonomous:["Implementation within assigned tasks"],needsApproval:["Design changes","New dependencies"]},knowledge:{reads:["projects/"],writes:[]},reports:{daily:"standup",weekly:""}}}}const js=4;function bC(t,l,r){const i=t.trim();if(!i||i.startsWith("#"))return null;const c=i.split(",").map(y=>y.trim()),u=c[0];if(!u)return null;const d=Pf(u),m=(c[1]||"member").toLowerCase(),x=m==="c-level"?"c-level":m==="team-lead"?"team-lead":"member",f=c[2]||"ceo";let g;return l.has(d)?g="ID already exists":r.has(d)&&(g="Duplicate ID in batch"),r.add(d),{name:u,id:d,level:x,reportsTo:f,error:g}}function vC({existingRoles:t,onClose:l,onHire:r}){const[i,c]=k.useState("single"),[u,d]=k.useState(""),[m,x]=k.useState(null),[f,g]=k.useState(!1),[y,b]=k.useState(""),[v,S]=k.useState("input"),[j,E]=k.useState(""),[C,A]=k.useState(""),[M,B]=k.useState("ceo"),[$,_]=k.useState(1),[V,G]=k.useState(""),[Y,T]=k.useState(""),[U,O]=k.useState(!1),[J,ne]=k.useState("member"),[K,I]=k.useState("ceo"),[W,me]=k.useState(""),[Se,D]=k.useState(hi),[F,Q]=k.useState(!1),[z,ce]=k.useState(""),[Ee,ge]=k.useState([]),[Ae,De]=k.useState(new Set),[He,ye]=k.useState(""),[We,de]=k.useState("input"),[fe,be]=k.useState({done:0,total:0}),Ce=k.useRef(null),ze=k.useRef(null),_e=k.useRef(null);k.useEffect(()=>{Ne.getSkills().then(q=>ge(q.filter(Te=>Te.installed))).catch(()=>{})},[]),k.useEffect(()=>{var q,Te,$e;i==="single"?($===1&&((q=Ce.current)==null||q.focus()),$===2&&((Te=ze.current)==null||Te.focus())):We==="input"&&(($e=_e.current)==null||$e.focus())},[$,i,We]);const Me=k.useMemo(()=>new Set(t.map(q=>q.id)),[t]),ve=k.useMemo(()=>{const q=He.split(`
81
+ `);_=Y.pop()??"";let T="";for(const U of Y)if(U.startsWith("event: "))T=U.slice(7).trim();else if(U.startsWith("data: ")){try{const O=JSON.parse(U.slice(6));if(T==="activity"){const J=O;J.seq>E.lastSeq&&(E.lastSeq=J.seq),c(ne=>{const K=new Map(ne),I=K.get(v);if(!I||I.events.some(me=>me.seq===J.seq))return ne;const W={...I,events:[...I.events,J]};if(J.type==="dispatch:start"&&J.data.childJobId){const me=J.data.childJobId,Se=J.data.targetRoleId??J.data.roleId;if(Se){const D=K.get(Se);D&&(K.set(Se,{...D,jobId:me,status:"running",streamStatus:"connecting"}),setTimeout(()=>f(me,Se),0))}}return J.type==="job:done"?(W.status="done",W.streamStatus="done"):J.type==="job:error"?(W.status="error",W.streamStatus="error"):J.type==="job:awaiting_input"?(W.status="awaiting_input",W.streamStatus="done"):J.type==="job:reply"&&(W.status="running",W.streamStatus="streaming"),K.set(v,W),K})}else if(T==="stream:end"){const J=O.reason;J!=="replied"&&c(ne=>{const K=new Map(ne),I=K.get(v);if(!I)return ne;const W=J==="error"?"error":J==="awaiting_input"?"awaiting_input":"done";return K.set(v,{...I,status:I.status==="running"?W:I.status,streamStatus:W==="error"?"error":"done"}),K})}}catch{}T=""}}}).catch(M=>{M.name!=="AbortError"&&c(B=>{const $=new Map(B),_=$.get(v);return _&&$.set(v,{..._,streamStatus:"error"}),$})})},[]);k.useEffect(()=>{if(t.length!==0){for(const b of t)f(b.jobId,b.roleId);return()=>{for(const[,b]of m.current)b.controller.abort();m.current.clear()}}},[t,f]);const g=(()=>{let b=0,v=0,S=0,j=0;for(const[E,C]of i)E!==r&&(j++,C.status==="done"?b++:C.status==="running"?v++:C.status==="awaiting_input"&&S++);return{done:b,total:j,running:v,awaitingInput:S}})(),y=g.total>0&&g.running===0&&g.awaitingInput===0&&Array.from(i.values()).every(b=>b.status!=="running"&&b.status!=="awaiting_input"&&b.streamStatus!=="streaming"&&b.streamStatus!=="connecting");return k.useEffect(()=>{y&&c(b=>{const v=new Map(b);let S=!1;for(const[j,E]of v)E.status==="waiting"&&(v.set(j,{...E,status:"not-dispatched"}),S=!0);return S?v:b})},[y]),{nodes:i,selectedRoleId:u,selectNode:d,progress:g,allDone:y,connectStream:f}}const j0={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C","data-analyst":"#0277BD"},ga=120,tr=44,S0=80;function fC(t,l){if(!t.get(l))return{layout:[],width:300,height:200};const i=[],c=[],u=[{id:l,depth:0,parentId:null}],d=new Set;for(;u.length>0;){const{id:g,depth:y,parentId:b}=u.shift();if(d.has(g))continue;for(d.add(g);c.length<=y;)c.push([]);c[y].push(g),i.push({roleId:g,x:0,y:y*S0+20,parentId:b});const v=t.get(g);if(v)for(const S of v.children)t.has(S)&&!d.has(S)&&u.push({id:S,depth:y+1,parentId:g})}const m=Math.max(...c.map(g=>g.length))*(ga+16),x=Math.max(m,280);for(const g of c){const y=g.length*(ga+16)-16,b=(x-y)/2;g.forEach((v,S)=>{const j=i.find(E=>E.roleId===v);j&&(j.x=b+S*(ga+16))})}const f=c.length*S0+40;return{layout:i,width:x,height:f}}function hC({nodes:t,rootId:l,selectedRoleId:r,onSelectNode:i}){const{layout:c,width:u,height:d}=fC(t,l),m=f=>{const g=c.find(y=>y.roleId===f);return g?{cx:g.x+ga/2,cy:g.y+tr/2}:{cx:0,cy:0}},x=f=>{switch(f.status){case"running":return j0[f.roleId]??"#FBBF24";case"awaiting_input":return"#F59E0B";case"done":return"#2E7D32";case"error":return"#C62828";case"not-dispatched":return"#666";default:return"#888"}};return s.jsxs("svg",{viewBox:`0 0 ${u} ${d}`,width:Math.max(u,280),height:d,className:"block",style:{minWidth:u},children:[s.jsx("defs",{children:s.jsxs("filter",{id:"glow",children:[s.jsx("feGaussianBlur",{stdDeviation:"2",result:"blur"}),s.jsxs("feMerge",{children:[s.jsx("feMergeNode",{in:"blur"}),s.jsx("feMergeNode",{in:"SourceGraphic"})]})]})}),c.filter(f=>f.parentId).map(f=>{const g=m(f.parentId),y=m(f.roleId),b=t.get(f.roleId),v=t.get(f.parentId);let S="rgba(180,200,240,0.15)",j="4 4",E="";return(b==null?void 0:b.status)==="done"||(v==null?void 0:v.status)==="done"?(S="#2E7D3266",j=""):(b==null?void 0:b.status)==="awaiting_input"?(S="#F59E0B",j="6 4",E="wave-edge-flow"):(b==null?void 0:b.status)==="running"&&(S=j0[f.roleId]??"#FBBF24",j="6 4",E="wave-edge-flow"),s.jsx("line",{x1:g.cx,y1:g.cy+tr/2-4,x2:y.cx,y2:y.cy-tr/2+4,stroke:S,strokeWidth:1.5,strokeDasharray:j,className:E},`${f.parentId}-${f.roleId}`)}),c.map(f=>{const g=t.get(f.roleId);if(!g)return null;const y=x(g),b=r===f.roleId,v=f.roleId===l,S=v?.4:g.status==="not-dispatched"?.35:1;return s.jsxs("g",{transform:`translate(${f.x}, ${f.y})`,style:{cursor:v?"default":"pointer",opacity:S},onClick:()=>!v&&i(f.roleId),children:[s.jsx("rect",{x:0,y:0,width:ga,height:tr,rx:8,ry:8,fill:"var(--terminal-bg-deeper, #181825)",stroke:b?"#fff":y,strokeWidth:b?2:1.5,strokeDasharray:g.status==="not-dispatched"?"4 3":""}),s.jsx("circle",{cx:14,cy:tr/2,r:4,fill:y,filter:g.status==="running"||g.status==="awaiting_input"?"url(#glow)":void 0,children:(g.status==="running"||g.status==="awaiting_input")&&s.jsx("animate",{attributeName:"opacity",values:"1;0.4;1",dur:"1.5s",repeatCount:"indefinite"})}),s.jsx("text",{x:26,y:tr/2-4,fill:"var(--terminal-text, #fff)",fontSize:10,fontWeight:700,fontFamily:"var(--pixel-font)",children:g.roleId.toUpperCase()}),s.jsx("text",{x:26,y:tr/2+10,fill:"var(--terminal-text-muted, #888)",fontSize:8,fontFamily:"var(--pixel-font)",children:g.status==="running"?"Working...":g.status==="awaiting_input"?"Awaiting Reply":g.status==="done"?"Complete":g.status==="error"?"Error":g.status==="waiting"?"Waiting":""}),g.status==="done"&&s.jsx("text",{x:ga-18,y:tr/2+4,fontSize:14,fill:"#2E7D32",children:"✓"}),g.status==="error"&&s.jsx("text",{x:ga-18,y:tr/2+4,fontSize:14,fill:"#C62828",children:"✗"})]},f.roleId)})]})}const mC={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C","data-analyst":"#0277BD"};function xC({directive:t,rootJobs:l,orgNodes:r,rootRoleId:i,onClose:c,onMinimize:u,onDone:d,onOpenKnowledgeDoc:m,onSave:x}){const{nodes:f,selectedRoleId:g,selectNode:y,progress:b,allDone:v,connectStream:S}=dC(l,r,i),[j,E]=k.useState(0),[C,A]=k.useState(new Set),[M,B]=k.useState(""),[$,_]=k.useState(!1),[V,G]=k.useState(!1),Y=k.useRef(null),T=k.useRef(Date.now()),U=k.useRef(!1),O=k.useCallback(async()=>{if(x){G(!0);try{const D=l.map(F=>F.jobId);await x(D)}catch(D){console.error("Save failed:",D)}finally{G(!1),c()}}},[x,l,c]),J=k.useCallback(async()=>{if(!g||!M.trim())return;const D=f.get(g);if(!(!(D!=null&&D.jobId)||D.status!=="awaiting_input")){_(!0);try{const{jobId:F}=await Ne.replyToJob(D.jobId,M.trim());B(""),S(F,g)}catch(F){console.error("Reply failed:",F)}finally{_(!1)}}},[g,M,f,S]),ne=k.useCallback(async D=>{const F=f.get(D);if(F!=null&&F.jobId)try{await Ne.abortJob(F.jobId)}catch(Q){console.error("Abort failed:",Q)}},[f]),K=k.useCallback(async()=>{for(const[,D]of f)if((D.status==="running"||D.status==="awaiting_input")&&D.jobId)try{await Ne.abortJob(D.jobId)}catch{}},[f]);k.useEffect(()=>{const D=setInterval(()=>{E(Math.floor((Date.now()-T.current)/1e3))},1e3);return()=>clearInterval(D)},[]),k.useEffect(()=>{Y.current&&(Y.current.scrollTop=Y.current.scrollHeight)},[g,f]),k.useEffect(()=>{v&&!U.current&&(U.current=!0,d==null||d())},[v,d]);const I=D=>`${Math.floor(D/60)}:${String(D%60).padStart(2,"0")}`,W=g?f.get(g):null,me=g?mC[g]??"#888":"#888",Se=D=>{A(F=>{const Q=new Set(F);return Q.has(D)?Q.delete(D):Q.add(D),Q})};return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 bg-black/40 z-[60] backdrop-blur-sm pointer-events-none"}),s.jsxs("div",{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[960px] max-w-[95vw] h-[85vh] z-[61] bg-[var(--terminal-bg)] rounded-2xl shadow-2xl overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-[var(--terminal-border)] shrink-0",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-3 h-3 rounded-full",style:{background:v?"#2E7D32":"#B71C1C",animation:v?void 0:"wave-pulse 2s ease-in-out infinite"}}),s.jsx("div",{children:s.jsx("span",{className:"text-[var(--terminal-text)] font-bold text-sm",children:v?"WAVE COMPLETE":"WAVE COMMAND CENTER"})})]}),s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsx("span",{className:"text-[var(--terminal-text-muted)] text-xs font-mono",children:I(j)}),b.awaitingInput>0&&s.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full font-semibold",style:{background:"#F59E0B22",color:"#F59E0B"},children:[b.awaitingInput," awaiting reply"]}),s.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full font-semibold",style:{background:v?"#2E7D3222":"#B71C1C22",color:v?"#2E7D32":"#B71C1C"},children:[b.done,"/",b.total," done"]}),!v&&(b.running>0||b.awaitingInput>0)&&s.jsx("button",{onClick:K,className:"text-xs px-2 py-0.5 rounded font-semibold cursor-pointer",style:{background:"#C6282822",color:"#C62828",border:"1px solid #C6282844"},title:"Stop all running jobs",children:"Stop All"}),s.jsx("button",{onClick:u,title:"Minimize",className:"text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text)] text-sm cursor-pointer px-1",children:"–"}),s.jsx("button",{onClick:c,className:"text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text)] text-lg cursor-pointer",title:v?"Dismiss wave":"Close (jobs keep running)",children:"×"})]})]}),s.jsx("div",{className:"px-5 py-2 border-b border-[var(--terminal-border)] shrink-0",children:s.jsxs("span",{className:"text-[var(--terminal-text-secondary)] text-xs italic",children:["“",t,"”"]})}),s.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[s.jsxs("div",{className:"shrink-0 border-b border-[var(--terminal-border)] flex flex-col",children:[s.jsxs("div",{className:"flex items-center gap-3 px-4 py-1.5",children:[s.jsx("span",{className:"text-[10px] font-bold text-[var(--terminal-text-secondary)] uppercase tracking-wider",children:"Org Propagation"}),s.jsx("div",{className:"flex gap-x-3 ml-auto",children:[{label:"running",color:"#FBBF24",dot:!0},{label:"awaiting",color:"#F59E0B",dot:!0},{label:"done",color:"#2E7D32",dot:!1},{label:"waiting",color:"#888",dot:!1},{label:"error",color:"#C62828",dot:!1}].map(D=>s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"w-2 h-2 rounded-full inline-block",style:{background:D.color,animation:D.dot?"wave-pulse 1.5s ease-in-out infinite":void 0}}),s.jsx("span",{className:"text-[8px] text-[var(--terminal-text-muted)]",children:D.label})]},D.label))})]}),s.jsx("div",{className:"overflow-x-auto overflow-y-auto px-3 pb-2",style:{maxHeight:"35vh"},children:s.jsx(hC,{nodes:f,rootId:i,selectedRoleId:g,onSelectNode:y})})]}),s.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[W&&s.jsxs("div",{className:"px-4 py-2 border-b border-[var(--terminal-border)] shrink-0 flex items-center gap-2",children:[s.jsx("div",{className:"w-2 h-2 rounded-full",style:{background:me}}),s.jsx("span",{className:"text-[var(--terminal-text)] font-bold text-xs",children:W.roleId.toUpperCase()}),s.jsx("span",{className:"text-[var(--terminal-text-muted)] text-xs",children:W.roleName}),s.jsx("span",{className:"ml-auto text-[10px] px-2 py-0.5 rounded-full font-semibold",style:{background:W.status==="awaiting_input"?"#F59E0B22":`${me}22`,color:W.status==="awaiting_input"?"#F59E0B":me},children:W.status==="running"?"Working":W.status==="done"?"Complete":W.status==="error"?"Error":W.status==="waiting"?"Waiting":W.status==="awaiting_input"?"Awaiting Reply":"Not dispatched"}),(W.status==="running"||W.status==="awaiting_input")&&W.jobId&&s.jsx("button",{onClick:()=>ne(W.roleId),className:"text-[10px] px-2 py-0.5 rounded font-semibold cursor-pointer ml-1",style:{background:"#C6282822",color:"#C62828",border:"1px solid #C6282844"},title:"Force stop this job",children:"Stop"})]}),s.jsxs("div",{ref:Y,className:"flex-1 overflow-y-auto p-4 space-y-1 text-xs font-mono select-text",children:[W&&W.events.length===0&&s.jsx("div",{className:"text-[var(--terminal-text-muted)]",children:W.status==="waiting"?"Waiting for dispatch...":W.status==="running"?"Connecting to activity stream...":W.status==="not-dispatched"?"This role was not dispatched in this wave.":""}),W==null?void 0:W.events.map(D=>s.jsx(mg,{event:D,isThinkingCollapsed:C.has(D.seq),onToggleThinking:()=>Se(D.seq),onNavigateToJob:F=>{for(const[,Q]of f)if(Q.jobId===F){y(Q.roleId);return}},onOpenKnowledgeDoc:m},D.seq)),(W==null?void 0:W.status)==="running"&&s.jsx("span",{className:"inline-block w-2 h-4 bg-green-400 animate-pulse ml-0.5"})]}),(W==null?void 0:W.status)==="awaiting_input"&&s.jsxs("div",{className:"px-4 py-3 border-t border-[var(--terminal-border)] shrink-0",style:{background:"#F59E0B0A"},children:[s.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[s.jsx("span",{className:"w-2 h-2 rounded-full inline-block",style:{background:"#F59E0B",animation:"wave-pulse 1.5s ease-in-out infinite"}}),s.jsxs("span",{className:"text-[11px] font-semibold",style:{color:"#F59E0B"},children:[W.roleName," is waiting for your response"]})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{type:"text",value:M,onChange:D=>B(D.target.value),onKeyDown:D=>{D.key==="Enter"&&!D.shiftKey&&(D.preventDefault(),J())},placeholder:"Type your response...",disabled:$,className:"flex-1 px-3 py-1.5 text-xs rounded border bg-[var(--terminal-bg)] text-[var(--terminal-text)] border-[var(--terminal-border)] outline-none focus:border-[#F59E0B]",autoFocus:!0}),s.jsx("button",{onClick:J,disabled:$||!M.trim(),className:"px-4 py-1.5 text-xs rounded font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#F59E0B",color:"#000"},children:$?"...":"Reply"})]})]}),!W&&s.jsx("div",{className:"flex-1 flex items-center justify-center text-[var(--terminal-text-muted)] text-xs",children:"Click a node in the org tree to view activity"}),s.jsxs("div",{className:"px-4 py-2 border-t border-[var(--terminal-border)] flex items-center justify-between shrink-0",children:[s.jsx("div",{className:"text-[10px] text-[var(--terminal-text-muted)]",children:W&&W.events.length>0&&`${W.events.length} events`}),v&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("button",{onClick:c,className:"px-4 py-1.5 text-xs rounded-lg font-semibold cursor-pointer",style:{background:"rgba(255,255,255,0.08)",color:"var(--terminal-text-muted)"},children:"Dismiss"}),x&&s.jsx("button",{onClick:O,disabled:V,className:"px-4 py-1.5 text-xs text-white rounded-lg font-semibold cursor-pointer disabled:opacity-50",style:{background:"#2E7D32"},children:V?"Saving...":"Save Wave"})]})]})]})]})]})]})}const pC={cto:{skinColor:"#F5CBA7",hairColor:"#2C1810",shirtColor:"#1565C0",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"short",outfitStyle:"tshirt",accessory:"glasses"},cbo:{skinColor:"#FDEBD0",hairColor:"#1A0A00",shirtColor:"#E65100",pantsColor:"#37474F",shoeColor:"#1A1A1A",hairStyle:"slicked",outfitStyle:"suit",accessory:"lapels"},pm:{skinColor:"#FDEBD0",hairColor:"#6D4C41",shirtColor:"#2E7D32",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"bun",outfitStyle:"tshirt",accessory:"blush"},engineer:{skinColor:"#F5CBA7",hairColor:"#1A1A1A",shirtColor:"#4A148C",pantsColor:"#37474F",shoeColor:"#7B1FA2",hairStyle:"messy",outfitStyle:"hoodie",accessory:"headphones"},designer:{skinColor:"#FDEBD0",hairColor:"#AD1457",shirtColor:"#AD1457",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"bob",outfitStyle:"tshirt",accessory:"beret"},qa:{skinColor:"#F5CBA7",hairColor:"#4E342E",shirtColor:"#00695C",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"short",outfitStyle:"tshirt",accessory:"badge"},"data-analyst":{skinColor:"#F5CBA7",hairColor:"#3E2723",shirtColor:"#0277BD",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"curly",outfitStyle:"vest",accessory:"none"}};function Th(t){return pC[t]??{skinColor:"#B0BEC5",hairColor:"#78909C",shirtColor:"#607D8B",pantsColor:"#455A64",shoeColor:"#37474F"}}const xg=["#FDEBD0","#F5CBA7","#D4A07A","#C68642","#8D5524","#5C3A1E","#F3D1C7","#E8BEAC","#B07D62","#704214"],pg=["#1A0A00","#2C1810","#4E342E","#6D4C41","#8D6E63","#D4A574","#F5E6CA","#FFD700","#B71C1C","#AD1457","#4A148C","#1A237E","#004D40","#1A1A1A","#78909C","#E0E0E0"],yg=["#1565C0","#E65100","#2E7D32","#4A148C","#AD1457","#00695C","#D32F2F","#F57F17","#1B5E20","#283593","#4E342E","#37474F","#880E4F","#00838F","#6A1B9A","#FF6F00"],gg=["#37474F","#1A237E","#3E2723","#263238","#1B5E20","#455A64","#212121","#4E342E","#0D47A1","#311B92"],bg=["#212121","#1A1A1A","#37474F","#4E342E","#7B1FA2","#D32F2F","#1565C0","#F57F17","#2E7D32","#FFFFFF"],Yr={default:{name:"MIDNIGHT",icon:"🌃",vars:{"--floor-light":"#0d1117","--floor-dark":"#0a0e14","--hud-bg":"#0d1117","--hud-bg-alt":"#161b22","--pixel-border":"#30363d","--terminal-bg":"#0d1117","--terminal-border":"#21262d","--terminal-border-hover":"#388bfd","--terminal-text":"#e6edf3","--terminal-text-secondary":"#8b949e","--terminal-text-muted":"#484f58","--accent":"#388bfd","--active-green":"#3fb950","--idle-amber":"#d29922"}},light:{name:"DAYLIGHT",icon:"☀️",vars:{"--floor-light":"#f6f8fa","--floor-dark":"#eaeef2","--hud-bg":"#24292f","--hud-bg-alt":"#32383f","--pixel-border":"#d0d7de","--terminal-bg":"#ffffff","--terminal-border":"#d0d7de","--terminal-border-hover":"#0969da","--terminal-text":"#1f2328","--terminal-text-secondary":"#656d76","--terminal-text-muted":"#8c959f","--accent":"#0969da","--active-green":"#1a7f37","--idle-amber":"#9a6700"}},retro:{name:"RETRO",icon:"🎮",vars:{"--floor-light":"#1a1410","--floor-dark":"#140f0a","--hud-bg":"#1a1410","--hud-bg-alt":"#2a2018","--pixel-border":"#5c4a32","--terminal-bg":"#1a1410","--terminal-border":"#3a2e20","--terminal-border-hover":"#d4a44e","--terminal-text":"#e8d5b0","--terminal-text-secondary":"#a08860","--terminal-text-muted":"#6b5840","--accent":"#d4a44e","--active-green":"#8bba4a","--idle-amber":"#e8a030"}},cyberpunk:{name:"NEON",icon:"🌌",vars:{"--floor-light":"#0a0014","--floor-dark":"#06000e","--hud-bg":"#0a0014","--hud-bg-alt":"#14002a","--pixel-border":"#4a1a80","--terminal-bg":"#0a0014","--terminal-border":"#2a0a50","--terminal-border-hover":"#e040fb","--terminal-text":"#e0d0ff","--terminal-text-secondary":"#9070c0","--terminal-text-muted":"#5a3a80","--accent":"#e040fb","--active-green":"#00ff88","--idle-amber":"#ffab00"}},forest:{name:"FOREST",icon:"🌲",vars:{"--floor-light":"#0a1410","--floor-dark":"#060e0a","--hud-bg":"#0a1410","--hud-bg-alt":"#142a1e","--pixel-border":"#2a5a3a","--terminal-bg":"#0a1410","--terminal-border":"#1a3a26","--terminal-border-hover":"#4ade80","--terminal-text":"#d0f0d8","--terminal-text-secondary":"#70a880","--terminal-text-muted":"#3a6848","--accent":"#4ade80","--active-green":"#86efac","--idle-amber":"#fcd34d"}},ocean:{name:"OCEAN",icon:"🌊",vars:{"--floor-light":"#0a1420","--floor-dark":"#060e18","--hud-bg":"#0a1420","--hud-bg-alt":"#142a40","--pixel-border":"#1e4a6a","--terminal-bg":"#0a1420","--terminal-border":"#163050","--terminal-border-hover":"#38bdf8","--terminal-text":"#d0e8f8","--terminal-text-secondary":"#6090b0","--terminal-text-muted":"#305070","--accent":"#38bdf8","--active-green":"#34d399","--idle-amber":"#fbbf24"}}};function yC({color:t,selected:l,onClick:r}){return s.jsx("button",{onClick:r,className:"customize-swatch",style:{background:t,outline:l?"2px solid #fff":"2px solid transparent",boxShadow:l?`0 0 0 1px ${t}, 0 0 6px ${t}88`:"none"}})}function ks({label:t,presets:l,value:r,onChange:i}){return s.jsxs("div",{className:"customize-row",children:[s.jsxs("div",{className:"customize-row-header",children:[s.jsx("span",{className:"customize-row-label",children:t}),s.jsx("div",{className:"customize-row-current",style:{background:r}})]}),s.jsx("div",{className:"customize-swatches",children:l.map(c=>s.jsx(yC,{color:c,selected:c===r,onClick:()=>i(c)},c))})]})}function jf({label:t,items:l,value:r,onChange:i,lockInfo:c}){return s.jsxs("div",{className:"customize-row",children:[s.jsx("div",{className:"customize-row-header",children:s.jsx("span",{className:"customize-row-label",children:t})}),s.jsx("div",{className:"customize-swatches",style:{gap:4},children:l.map(u=>{const d=c?c.getLockLevel(u.id):1,m=u.id===r,x=c?d>c.roleLevel&&!m:!1,f=c?m&&d>c.roleLevel:!1;return s.jsxs("button",{onClick:()=>{x||i(u.id===r?void 0:u.id)},className:"customize-swatch",style:{width:"auto",height:"auto",padding:x?"2px 6px 10px 6px":"2px 6px",fontSize:9,fontFamily:"var(--font-pixel, monospace)",background:m?"rgba(255,255,255,0.15)":x?"rgba(255,255,255,0.02)":"rgba(255,255,255,0.04)",outline:m?f?"2px solid #F59E0B":"2px solid #fff":"2px solid transparent",color:x?"rgba(255,255,255,0.25)":m?"#fff":"rgba(255,255,255,0.5)",borderRadius:4,cursor:x?"not-allowed":"pointer",opacity:x?.35:1,position:"relative"},children:[u.name,x&&s.jsxs("span",{style:{position:"absolute",bottom:1,left:"50%",transform:"translateX(-50%)",fontSize:8,color:"rgba(255,255,255,0.5)",whiteSpace:"nowrap"},children:["🔒"," Lv.",d]}),f&&s.jsxs("span",{style:{position:"absolute",bottom:-8,left:"50%",transform:"translateX(-50%)",fontSize:7,color:"#F59E0B",whiteSpace:"nowrap"},children:["⚠"," Lv.",d]})]},u.id)})})]})}function Sf({label:t,active:l,onClick:r}){return s.jsx("button",{onClick:r,style:{flex:1,padding:"6px 0",fontSize:10,fontFamily:"var(--font-pixel, monospace)",fontWeight:"bold",letterSpacing:1,background:l?"rgba(255,255,255,0.08)":"transparent",color:l?"#fff":"rgba(255,255,255,0.35)",border:"none",borderBottom:l?"2px solid #3B82F6":"2px solid transparent",cursor:"pointer",transition:"all 0.15s"},children:t})}function Lr(t){return t[Math.floor(Math.random()*t.length)]}function hi(t){var c,u,d;const l=ng(),r=lg(),i=rg().filter(m=>!t||ig(m.id,t));return{skinColor:Lr(xg),hairColor:Lr(pg),shirtColor:Lr(yg),pantsColor:Lr(gg),shoeColor:Lr(bg),hairStyle:(c=Lr(l))==null?void 0:c.id,outfitStyle:(u=Lr(r))==null?void 0:u.id,accessory:(d=Lr(i))==null?void 0:d.id}}function vg({roleId:t,appearance:l,onChange:r,onRandomize:i,onReset:c,label:u,roleLevel:d}){const[m,x]=k.useState("look"),f=k.useCallback((E,C)=>{r({...l,[E]:C})},[l,r]),g=k.useRef(null),y=k.useCallback(E=>{var M;const C=(M=E.target.files)==null?void 0:M[0];if(!C)return;const A=new Image;A.onload=()=>{const B=Hj(A);r({...B,hairStyle:l.hairStyle,outfitStyle:l.outfitStyle,accessory:l.accessory}),URL.revokeObjectURL(A.src)},A.src=URL.createObjectURL(C),E.target.value=""},[l.hairStyle,l.outfitStyle,l.accessory,r]),b=ng(),v=lg(),S=rg(),j=d!==void 0?S.filter(E=>ig(E.id,d)).length:S.length;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"customize-preview",children:[s.jsx("div",{className:"customize-preview-bg",children:s.jsx(_s,{roleId:t,appearance:l,scale:12})}),u&&s.jsx("div",{className:"customize-preview-name",children:u}),s.jsxs("div",{className:"customize-preview-actions",children:[s.jsx("button",{className:"customize-btn customize-btn--random",onClick:i,children:"RANDOM"}),s.jsx("button",{className:"customize-btn customize-btn--reset",onClick:c,children:"RESET"}),s.jsx("button",{className:"customize-btn",onClick:()=>{var E;return(E=g.current)==null?void 0:E.click()},style:{fontSize:9,opacity:.7},children:"PHOTO"}),s.jsx("input",{ref:g,type:"file",accept:"image/*",onChange:y,style:{display:"none"}})]})]}),s.jsxs("div",{className:"customize-colors",children:[s.jsxs("div",{style:{display:"flex",borderBottom:"1px solid rgba(255,255,255,0.06)",marginBottom:4},children:[s.jsx(Sf,{label:"LOOK",active:m==="look",onClick:()=>x("look")}),s.jsx(Sf,{label:"OUTFIT",active:m==="outfit",onClick:()=>x("outfit")}),s.jsx(Sf,{label:"ACCESSORY",active:m==="accessory",onClick:()=>x("accessory")})]}),m==="look"&&s.jsxs(s.Fragment,{children:[s.jsx(ks,{label:"SKIN",presets:xg,value:l.skinColor,onChange:E=>f("skinColor",E)}),s.jsx(ks,{label:"HAIR COLOR",presets:pg,value:l.hairColor,onChange:E=>f("hairColor",E)}),s.jsx(jf,{label:"HAIR STYLE",items:b,value:l.hairStyle,onChange:E=>f("hairStyle",E)})]}),m==="outfit"&&s.jsxs(s.Fragment,{children:[s.jsx(jf,{label:"STYLE",items:v,value:l.outfitStyle,onChange:E=>f("outfitStyle",E)}),s.jsx(ks,{label:"TOP",presets:yg,value:l.shirtColor,onChange:E=>f("shirtColor",E)}),s.jsx(ks,{label:"PANTS",presets:gg,value:l.pantsColor,onChange:E=>f("pantsColor",E)}),s.jsx(ks,{label:"SHOES",presets:bg,value:l.shoeColor,onChange:E=>f("shoeColor",E)})]}),m==="accessory"&&s.jsxs(s.Fragment,{children:[d!==void 0&&s.jsxs("div",{style:{padding:"4px 8px",marginBottom:4,background:"rgba(255,255,255,0.04)",borderRadius:4,fontSize:9,fontFamily:"var(--font-pixel, monospace)",color:"rgba(255,255,255,0.5)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s.jsxs("span",{children:["Lv.",d]}),s.jsxs("span",{children:[j,"/",S.length," unlocked"]})]}),s.jsx(jf,{label:"ACCESSORY",items:S,value:l.accessory,onChange:E=>f("accessory",E),lockInfo:d!==void 0?{roleLevel:d,getLockLevel:ag}:void 0}),s.jsx("div",{style:{marginTop:12,padding:"8px 10px",background:"rgba(255,255,255,0.03)",borderRadius:6,border:"1px dashed rgba(255,255,255,0.08)",color:"rgba(255,255,255,0.25)",fontSize:9,fontFamily:"var(--font-pixel, monospace)",textAlign:"center"},children:d!==void 0&&d<10?"Level up to unlock more accessories":"More accessories coming soon"})]})]})]})}const gC=[{value:"c-level",label:"C-Level"},{value:"team-lead",label:"Team Lead"},{value:"member",label:"Member"}];function Pf(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,24)}function Cf(t){switch(t){case"c-level":return{authority:{autonomous:["Strategic decisions within domain","Task delegation to reports"],needsApproval:["Budget over $5K","External commitments"]},knowledge:{reads:["company/","operations/","projects/"],writes:["operations/","knowledge/"]},reports:{daily:"standup",weekly:"summary"}};case"team-lead":return{authority:{autonomous:["Task planning","Sprint management"],needsApproval:["Architecture changes","New tool adoption"]},knowledge:{reads:["projects/","architecture/"],writes:["projects/"]},reports:{daily:"standup",weekly:"summary"}};default:return{authority:{autonomous:["Implementation within assigned tasks"],needsApproval:["Design changes","New dependencies"]},knowledge:{reads:["projects/"],writes:[]},reports:{daily:"standup",weekly:""}}}}const js=4;function bC(t,l,r){const i=t.trim();if(!i||i.startsWith("#"))return null;const c=i.split(",").map(y=>y.trim()),u=c[0];if(!u)return null;const d=Pf(u),m=(c[1]||"member").toLowerCase(),x=m==="c-level"?"c-level":m==="team-lead"?"team-lead":"member",f=c[2]||"ceo";let g;return l.has(d)?g="ID already exists":r.has(d)&&(g="Duplicate ID in batch"),r.add(d),{name:u,id:d,level:x,reportsTo:f,error:g}}function vC({existingRoles:t,onClose:l,onHire:r}){const[i,c]=k.useState("single"),[u,d]=k.useState(""),[m,x]=k.useState(null),[f,g]=k.useState(!1),[y,b]=k.useState(""),[v,S]=k.useState("input"),[j,E]=k.useState(""),[C,A]=k.useState(""),[M,B]=k.useState("ceo"),[$,_]=k.useState(1),[V,G]=k.useState(""),[Y,T]=k.useState(""),[U,O]=k.useState(!1),[J,ne]=k.useState("member"),[K,I]=k.useState("ceo"),[W,me]=k.useState(""),[Se,D]=k.useState(hi),[F,Q]=k.useState(!1),[z,ce]=k.useState(""),[Ee,ge]=k.useState([]),[Ae,De]=k.useState(new Set),[He,ye]=k.useState(""),[We,de]=k.useState("input"),[fe,be]=k.useState({done:0,total:0}),Ce=k.useRef(null),ze=k.useRef(null),_e=k.useRef(null);k.useEffect(()=>{Ne.getSkills().then(q=>ge(q.filter(Te=>Te.installed))).catch(()=>{})},[]),k.useEffect(()=>{var q,Te,$e;i==="single"?($===1&&((q=Ce.current)==null||q.focus()),$===2&&((Te=ze.current)==null||Te.focus())):We==="input"&&(($e=_e.current)==null||$e.focus())},[$,i,We]);const Me=k.useMemo(()=>new Set(t.map(q=>q.id)),[t]),ve=k.useMemo(()=>{const q=He.split(`
82
82
  `),Te=new Set;return q.map($e=>bC($e,Me,Te)).filter($e=>$e!==null)},[He,Me]),Oe=ve.length>0&&ve.every(q=>!q.error),Je=q=>{G(q),U||T(Pf(q))},jt=V.trim().length>0&&Y.trim().length>0&&!t.some(q=>q.id===Y),$t=W.trim().length>0,yt=async()=>{Q(!0),ce("");const q=Cf(J);try{await r({id:Y,name:V.trim(),level:J,reportsTo:K,persona:W.trim(),...q,skills:Ae.size>0?[...Ae]:void 0},Se),l()}catch(Te){ce(Te instanceof Error?Te.message:"Failed to create role"),Q(!1)}},Xt=q=>q===1?jt:q===2?$t:!0,re=async()=>{Q(!0),ce(""),be({done:0,total:ve.length});try{for(let q=0;q<ve.length;q++){const Te=ve[q],$e=Cf(Te.level),Ke=hi(),mt=`${Te.name}. A ${Te.level} role reporting to ${Te.reportsTo}.`;await r({id:Te.id,name:Te.name,level:Te.level,reportsTo:Te.reportsTo,persona:mt,...$e},Ke),be({done:q+1,total:ve.length})}l()}catch(q){ce(q instanceof Error?q.message:"Failed to create roles"),Q(!1)}},he=async()=>{g(!0),b("");try{const q=u.replace(/^tycono:/,"").trim();if(!q){b("Please enter a character ID"),g(!1);return}const Te=await xi.getCharacter(q);x(Te),E(Te.name||""),A(Pf(Te.name||q)),S("review")}catch{b("Character not found. Check the ID and try again.")}finally{g(!1)}},Fe=async()=>{if(!m)return;Q(!0),ce("");const q=m,Te=q.level==="c-level"||q.level==="team-lead"?q.level:"member",$e=Cf(Te),Ke=q.skills!=null&&typeof q.skills=="object"&&!Array.isArray(q.skills)&&"primary"in q.skills;try{await r({id:C,name:j.trim(),level:Te,reportsTo:M,persona:q.persona||`${j}. Imported from Tycono Store.`,authority:q.authority||$e.authority,knowledge:$e.knowledge,reports:$e.reports,source:{id:`tycono/${q.id}`,sync:"manual",forked_at:"1.0.0",upstream_version:"1.0.0"},skillContent:Ke?q.skills:void 0},q.appearance?q.appearance:hi()),l()}catch(mt){ce(mt instanceof Error?mt.message:"Failed to hire"),Q(!1)}},Ye=q=>{q.key==="Escape"&&l(),q.key==="Enter"&&(q.metaKey||q.ctrlKey)&&(i==="single"?$<js&&Xt($)?_($+1):$===js&&yt():i==="bulk"?We==="input"&&Oe?de("review"):We==="review"&&re():i==="store"&&(v==="input"&&u.trim()?he():v==="review"&&Fe()))},xe=t.some(q=>q.id===Y)&&Y.length>0;return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 bg-black/40 z-[60] backdrop-blur-sm",onClick:l}),s.jsxs("div",{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[560px] max-h-[90vh] z-[61] bg-[var(--wall)] rounded-2xl shadow-2xl overflow-hidden flex flex-col",onKeyDown:Ye,children:[s.jsxs("div",{className:"p-5 text-white",style:{background:"linear-gradient(135deg, #2E7D32, #43A047)"},children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("div",{className:"text-lg font-bold",children:"Hire New Role"}),s.jsxs("div",{className:"flex bg-black/20 rounded-lg p-0.5",children:[s.jsx("button",{onClick:()=>{c("single"),ce("")},className:`px-3 py-1 text-xs font-semibold rounded-md cursor-pointer transition-colors ${i==="single"?"bg-white/20 text-white":"text-white/50 hover:text-white/70"}`,children:"Single"}),s.jsx("button",{onClick:()=>{c("bulk"),ce("")},className:`px-3 py-1 text-xs font-semibold rounded-md cursor-pointer transition-colors ${i==="bulk"?"bg-white/20 text-white":"text-white/50 hover:text-white/70"}`,children:"Bulk"}),s.jsx("button",{onClick:()=>{c("store"),ce("")},className:`px-3 py-1 text-xs font-semibold rounded-md cursor-pointer transition-colors ${i==="store"?"bg-white/20 text-white":"text-white/50 hover:text-white/70"}`,children:"Import"})]})]}),s.jsx("div",{className:"text-sm opacity-80 mt-0.5",children:i==="single"?`Step ${$} of ${js}`:i==="bulk"?We==="input"?"Enter roles, one per line":`Review ${ve.length} roles`:v==="input"?"Import from Tycono Store":"Review & customize"})]}),i==="single"&&s.jsx("div",{className:"flex gap-1 px-5 pt-4",children:Array.from({length:js},(q,Te)=>Te+1).map(q=>s.jsx("div",{className:"flex-1 h-1 rounded-full transition-colors",style:{background:q<=$?"#2E7D32":"rgba(255,255,255,0.1)"}},q))}),s.jsx("div",{className:"p-5 min-h-[240px] overflow-y-auto flex-1",children:i==="store"?s.jsxs(s.Fragment,{children:[v==="input"&&s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-2",children:"Character ID"}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{value:u,onChange:q=>d(q.target.value),placeholder:"tycono:engineer",className:"flex-1 p-2.5 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 placeholder-white/25 font-mono focus:outline-none focus:border-white/25 transition-colors",onKeyDown:q=>{q.key==="Enter"&&u.trim()&&he()},autoFocus:!0}),s.jsx("button",{onClick:he,disabled:!u.trim()||f,className:"px-4 py-2 text-sm text-white rounded-lg font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#2E7D32"},children:f?"Fetching...":"Fetch"})]}),s.jsxs("div",{className:"text-[10px] text-gray-400 mt-1",children:["Copy a character ID from ",s.jsx("a",{href:"https://tycono.ai/store.html",target:"_blank",className:"text-green-400 hover:underline",children:"tycono.ai/store"})," and paste it here"]})]}),y&&s.jsx("div",{className:"text-xs text-red-400 bg-red-900/20 p-2 rounded-lg border border-red-800/30",children:y})]}),v==="review"&&m&&s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"bg-white/5 rounded-xl p-4 border border-white/10",children:[s.jsxs("div",{className:"flex gap-4",children:[m.appearance&&s.jsx("div",{className:"flex-shrink-0 rounded-lg overflow-hidden",style:{background:"#0d1117",padding:8},children:s.jsx(_s,{roleId:"store-preview",appearance:m.appearance,scale:4})}),s.jsxs("div",{className:"flex-1 space-y-2.5",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-[10px] text-white/30 uppercase tracking-wider mb-0.5",children:"Name"}),s.jsx("input",{value:j,onChange:q=>E(q.target.value),className:"w-full p-2 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 focus:outline-none focus:border-white/25 transition-colors"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-[10px] text-white/30 uppercase tracking-wider mb-0.5",children:"Role ID"}),s.jsx("input",{value:C,onChange:q=>A(q.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),className:"w-full p-2 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 font-mono focus:outline-none focus:border-white/25 transition-colors"}),t.some(q=>q.id===C)&&C.length>0&&s.jsx("div",{className:"text-xs text-red-500 mt-1",children:"ID already exists"})]}),s.jsxs("div",{className:"flex gap-3",children:[s.jsxs("div",{className:"flex-1",children:[s.jsx("label",{className:"block text-[10px] text-white/30 uppercase tracking-wider mb-0.5",children:"Level"}),s.jsx("div",{className:"text-sm text-white/70 p-2 rounded-lg bg-white/5 border border-white/10",children:m.level==="c-level"?"C-Level":m.level==="team-lead"?"Lead":"Member"})]}),s.jsxs("div",{className:"flex-1",children:[s.jsx("label",{className:"block text-[10px] text-white/30 uppercase tracking-wider mb-0.5",children:"Reports To"}),s.jsxs("select",{value:M,onChange:q=>B(q.target.value),className:"w-full p-2 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 focus:outline-none focus:border-white/25 transition-colors",children:[s.jsx("option",{value:"ceo",className:"bg-[var(--wall)] text-white",children:"CEO"}),t.map(q=>s.jsxs("option",{value:q.id,className:"bg-[var(--wall)] text-white",children:[q.name," (",q.id,")"]},q.id))]})]})]})]})]}),m.persona&&s.jsxs("div",{className:"pt-3 mt-3 border-t border-white/10",children:[s.jsx("div",{className:"text-[10px] text-white/30 uppercase tracking-wider mb-1",children:"Persona"}),s.jsx("div",{className:"text-xs text-white/60 leading-relaxed line-clamp-3",children:m.persona})]}),m.skills&&s.jsxs("div",{className:"pt-3 mt-3 border-t border-white/10",children:[s.jsx("div",{className:"text-[10px] text-white/30 uppercase tracking-wider mb-1",children:"Skills"}),s.jsx("div",{className:"flex flex-wrap gap-1.5",children:(()=>{var Ke,mt;const q=m.skills;if(q&&typeof q=="object"&&!Array.isArray(q)&&"primary"in q){const Qe=[];return(mt=(Ke=q.primary)==null?void 0:Ke.frontmatter)!=null&&mt.name&&Qe.push(q.primary.frontmatter.name),q.shared&&q.shared.forEach(It=>{var an;return Qe.push(((an=It.frontmatter)==null?void 0:an.name)||It.id)}),Qe.map(It=>s.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-mono bg-green-900/20 border border-green-800/30 text-green-400",children:It},It))}return(Array.isArray(q)?q:[]).map((Qe,It)=>s.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-mono bg-green-900/20 border border-green-800/30 text-green-400",children:typeof Qe=="string"?Qe:Qe.name},It))})()})]})]}),z&&s.jsx("div",{className:"text-xs text-red-400 bg-red-900/20 p-2 rounded-lg border border-red-800/30",children:z})]})]}):i==="single"?s.jsxs(s.Fragment,{children:[$===1&&s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-1",children:"Role Name"}),s.jsx("input",{ref:Ce,value:V,onChange:q=>Je(q.target.value),placeholder:"e.g. Data Analyst",className:"w-full p-2.5 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 placeholder-white/25 focus:outline-none focus:border-white/25 transition-colors"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-1",children:"Role ID (slug)"}),s.jsx("input",{value:Y,onChange:q=>{T(q.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),O(!0)},className:`w-full p-2.5 rounded-lg border bg-white/5 text-sm text-white/90 font-mono focus:outline-none transition-colors ${xe?"border-red-400":"border-white/10 focus:border-white/25"}`}),xe&&s.jsx("div",{className:"text-xs text-red-500 mt-1",children:"ID already exists"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-1",children:"Level"}),s.jsx("div",{className:"flex gap-2",children:gC.map(q=>s.jsx("button",{onClick:()=>ne(q.value),className:`flex-1 p-2 text-xs font-semibold rounded-lg border cursor-pointer transition-colors ${J===q.value?"border-green-600 bg-green-900/30 text-green-400":"border-white/10 text-white/50 hover:border-white/20"}`,children:q.label},q.value))})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-1",children:"Reports To"}),s.jsxs("select",{value:K,onChange:q=>I(q.target.value),className:"w-full p-2.5 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 focus:outline-none focus:border-white/25 transition-colors",children:[s.jsx("option",{value:"ceo",className:"bg-[var(--wall)] text-white",children:"CEO"}),t.map(q=>s.jsxs("option",{value:q.id,className:"bg-[var(--wall)] text-white",children:[q.name," (",q.id,")"]},q.id))]})]})]}),$===2&&s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-2",children:"Persona"}),s.jsx("textarea",{ref:ze,value:W,onChange:q=>me(q.target.value),placeholder:"Describe this role's personality, expertise, and working style...",className:"w-full h-32 p-3 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 placeholder-white/25 resize-none focus:outline-none focus:border-white/25 transition-colors"}),s.jsx("div",{className:"text-[10px] text-gray-400 mt-1",children:"This defines how the AI agent will behave in this role"})]}),Ee.length>0&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-2",children:"Skills"}),s.jsx("div",{className:"space-y-1.5 max-h-[120px] overflow-y-auto",children:Ee.map(q=>s.jsxs("label",{className:"flex items-center gap-2 p-2 rounded-lg border border-white/10 bg-white/5 cursor-pointer hover:border-white/20 transition-colors",children:[s.jsx("input",{type:"checkbox",checked:Ae.has(q.id),onChange:()=>De(Te=>{const $e=new Set(Te);return $e.has(q.id)?$e.delete(q.id):$e.add(q.id),$e}),className:"accent-green-600"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("div",{className:"text-xs font-semibold text-white/80",children:q.name}),s.jsx("div",{className:"text-[10px] text-white/40 truncate",children:q.description})]})]},q.id))})]})]}),$===3&&s.jsx("div",{className:"customize-body",style:{padding:0},children:s.jsx(vg,{roleId:"default",appearance:Se,onChange:D,onRandomize:()=>D(hi()),onReset:()=>D(hi()),label:s.jsxs("span",{children:[Y||"new-role"," — ",V||"New Role"]})})}),$===4&&s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{className:"text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-2",children:"Review"}),s.jsxs("div",{className:"bg-white/5 rounded-xl p-4 border border-white/10",children:[s.jsxs("div",{className:"flex gap-4",children:[s.jsx("div",{className:"flex-shrink-0 rounded-lg overflow-hidden",style:{background:"#0d1117",padding:8},children:s.jsx(_s,{roleId:"default",appearance:Se,scale:4})}),s.jsxs("div",{className:"flex-1 space-y-2.5",children:[s.jsx(Ss,{label:"Name",value:V}),s.jsx(Ss,{label:"ID",value:Y,mono:!0}),s.jsx(Ss,{label:"Level",value:J}),s.jsx(Ss,{label:"Reports To",value:K}),Ae.size>0&&s.jsx(Ss,{label:"Skills",value:[...Ae].join(", ")})]})]}),s.jsxs("div",{className:"pt-3 mt-3 border-t border-white/10",children:[s.jsx("div",{className:"text-[10px] text-white/30 uppercase tracking-wider mb-1",children:"Persona"}),s.jsx("div",{className:"text-xs text-white/60 leading-relaxed",children:W})]})]}),z&&s.jsx("div",{className:"text-xs text-red-400 bg-red-900/20 p-2 rounded-lg border border-red-800/30",children:z})]})]}):s.jsxs(s.Fragment,{children:[We==="input"&&s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-2",children:"Roles (one per line)"}),s.jsx("textarea",{ref:_e,value:He,onChange:q=>ye(q.target.value),placeholder:`Name, Level, ReportsTo
83
83
  e.g.
84
84
  Data Analyst
@@ -97,4 +97,4 @@ ${ae}`;Ei(oe.id,pe,"do")}catch(oe){Ht(`Failed to delegate: ${oe instanceof Error
97
97
  bg-[var(--terminal-bg)] text-[var(--terminal-text)]
98
98
  border border-[var(--terminal-border)]
99
99
  focus:border-[var(--terminal-border-hover)]
100
- placeholder:text-[var(--terminal-text-muted)]`,sn=we=>`p-4 rounded-lg border-2 cursor-pointer transition-all text-[var(--terminal-text)] ${we?"border-[var(--accent)] bg-[var(--accent)]/10":"border-[var(--terminal-border)] bg-[var(--hud-bg-alt)] hover:border-[var(--accent)]/50"}`;return s.jsx("div",{className:"h-full flex items-center justify-center",style:{background:"var(--floor-dark)"},onKeyDown:Fn,children:s.jsxs("div",{className:"w-full max-w-xl rounded-xl shadow-2xl overflow-hidden",style:{background:"var(--hud-bg)",border:"1px solid var(--terminal-border)"},children:[s.jsxs("div",{className:"px-6 py-5",style:{background:"var(--terminal-bg)",borderBottom:"1px solid var(--terminal-border)"},children:[s.jsx("div",{className:"text-lg font-bold",style:{color:"var(--terminal-text)",fontFamily:"var(--pixel-font)"},children:"tycono"}),s.jsx("div",{className:"text-xs mt-1",style:{color:"var(--terminal-text-secondary)"},children:"Build an AI company. Watch them work."}),s.jsx("div",{className:"flex gap-1.5 mt-4",children:Te.map((we,Wt)=>s.jsxs("div",{className:"flex-1",children:[s.jsx("div",{className:"h-1 rounded-full transition-colors",style:{background:Wt<=l?"var(--accent)":"var(--terminal-surface-light)"}}),s.jsx("div",{className:"text-[9px] mt-1 truncate",style:{color:Wt===l?"var(--terminal-text)":"var(--terminal-text-muted)"},children:xN[we]})]},we))})]}),s.jsxs("div",{className:"px-6 py-5 min-h-[280px]",children:[$e==="engine"&&s.jsxs("div",{className:"space-y-4",children:[s.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:"AI Engine Setup"}),f?s.jsx("div",{className:"text-sm",style:{color:"var(--terminal-text-secondary)"},children:"Detecting AI engine..."}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:sn(u==="claude-cli"),onClick:()=>(i==null?void 0:i.claudeCli)&&d("claude-cli"),style:{opacity:i!=null&&i.claudeCli?1:.4},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-lg",children:i!=null&&i.claudeCli?"✅":"❌"}),s.jsxs("div",{children:[s.jsx("div",{className:"font-medium text-sm",children:"Claude Code CLI"}),s.jsx("div",{className:"text-xs opacity-70",children:i!=null&&i.claudeCli?"Detected! Recommended — zero config needed.":"Not installed. Get it at claude.ai/download"})]})]})}),s.jsxs("div",{className:sn(u==="direct-api"),onClick:()=>d("direct-api"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-lg",children:i!=null&&i.apiKey?"✅":"🔑"}),s.jsxs("div",{className:"flex-1",children:[s.jsx("div",{className:"font-medium text-sm",children:"Anthropic API Key (BYOK)"}),s.jsx("div",{className:"text-xs opacity-70",children:i!=null&&i.apiKey?"API key found in environment.":"Enter your ANTHROPIC_API_KEY"})]})]}),u==="direct-api"&&!(i!=null&&i.apiKey)&&s.jsx("input",{type:"password",className:`${En} mt-3`,placeholder:"sk-ant-...",value:m,onChange:we=>x(we.target.value),autoFocus:!0})]})]})]}),$e==="company"&&s.jsxs("div",{className:"space-y-4",children:[s.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:"Company Info"}),s.jsxs("div",{children:[s.jsx("label",{className:"text-xs font-medium block mb-1",style:{color:"var(--terminal-text-secondary)"},children:"Company Name *"}),s.jsx("input",{ref:Y,className:En,placeholder:"e.g. Acme Corp",value:y,onChange:we=>b(we.target.value)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-xs font-medium block mb-1",style:{color:"var(--terminal-text-secondary)"},children:"Description"}),s.jsx("textarea",{className:`${En} resize-none`,rows:3,placeholder:"What does your AI company do?",value:v,onChange:we=>S(we.target.value)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-xs font-medium block mb-1",style:{color:"var(--terminal-text-secondary)"},children:"Location"}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{className:`${En} flex-1`,placeholder:"/path/to/your-company",value:C,onChange:we=>{A(we.target.value),_(!0)}}),s.jsx("button",{onClick:()=>G(!V),className:"px-3 py-2 rounded text-xs font-medium transition-colors shrink-0",style:{background:"var(--hud-bg-alt)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},title:"Browse folders",children:"📁"})]}),s.jsx("div",{className:"text-[10px] mt-1",style:{color:"var(--terminal-text-muted)"},children:"Where your AI company files will be created."}),V&&s.jsx(wc,{onSelect:we=>{A(we),_(!0),G(!1)},onClose:()=>G(!1)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-xs font-medium block mb-1",style:{color:"var(--terminal-text-secondary)"},children:"AI Response Language"}),s.jsxs("select",{className:En,value:j,onChange:we=>E(we.target.value),children:[s.jsx("option",{value:"auto",children:"Auto"}),s.jsx("option",{value:"en",children:"English"}),s.jsx("option",{value:"ko",children:"한국어"}),s.jsx("option",{value:"ja",children:"日本語"})]})]})]}),$e==="project"&&s.jsxs("div",{className:"space-y-4",children:[s.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:"Project Setup"}),s.jsxs("div",{className:sn(T==="fresh"),onClick:()=>{U("fresh"),K(null)},children:[s.jsxs("div",{className:"font-medium text-sm",children:["🌱"," Start Fresh"]}),s.jsx("div",{className:"text-xs opacity-70 mt-1",children:"Create a new AI company from scratch with clean directory structure."})]}),s.jsxs("div",{className:sn(T==="existing"),onClick:()=>U("existing"),children:[s.jsxs("div",{className:"font-medium text-sm",children:["📂"," Connect Existing Project"]}),s.jsx("div",{className:"text-xs opacity-70 mt-1",children:"Add AI company structure to an existing codebase or knowledge base."}),T==="existing"&&s.jsxs("div",{className:"mt-3",onClick:we=>we.stopPropagation(),children:[s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{className:`${En} flex-1`,placeholder:"/path/to/your/project",value:O,onChange:we=>{J(we.target.value),K(null)},autoFocus:!0}),s.jsx("button",{onClick:()=>Se(!me),className:"px-3 py-2 rounded text-xs font-medium transition-colors",style:{background:"var(--hud-bg-alt)",color:"var(--terminal-text)"},title:"Browse folders",children:"📁"}),s.jsx("button",{onClick:It,disabled:I||!O.trim(),className:"px-3 py-2 rounded text-xs font-medium transition-colors",style:{background:"var(--accent)",color:"#fff",opacity:I||!O.trim()?.5:1},children:I?"...":"Verify"})]}),ne===!0&&s.jsxs("div",{className:"text-xs mt-2",style:{color:"var(--active-green)"},children:["✅"," Path verified: ",O]}),ne===!1&&s.jsxs("div",{className:"text-xs mt-2",style:{color:"#EF4444"},children:["❌"," Invalid path"]}),me&&s.jsx(wc,{onSelect:we=>{J(we),K(!0),Se(!1)},onClose:()=>Se(!1)})]})]})]}),$e==="knowledge"&&s.jsxs("div",{className:"space-y-3",children:[s.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:"Knowledge Strategy"}),s.jsx("p",{className:"text-xs",style:{color:"var(--terminal-text-secondary)"},children:"How should AI handle your knowledge base?"}),s.jsxs("div",{className:sn(D==="skip"),onClick:()=>F("skip"),children:[s.jsxs("div",{className:"font-medium text-sm",children:["🌱"," Start Fresh"]}),s.jsx("div",{className:"text-xs opacity-70 mt-1",children:"Empty knowledge base. Add documents later from the office."})]}),s.jsxs("div",{className:sn(D==="import"),onClick:()=>F("import"),children:[s.jsxs("div",{className:"font-medium text-sm",children:["📚"," Import & Build"]}),s.jsx("div",{className:"text-xs opacity-70 mt-1",children:"Select folders with documents — AI reads, summarizes, and organizes them."}),D==="import"&&s.jsxs("div",{className:"mt-3 space-y-2",onClick:we=>we.stopPropagation(),children:[s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{className:`${En} flex-1`,placeholder:"/path/to/docs",value:ce,onChange:we=>Ee(we.target.value),onKeyDown:we=>{we.key==="Enter"&&(we.preventDefault(),Nt())},autoFocus:!0}),s.jsx("button",{onClick:()=>Ae(!ge),className:"px-3 py-2 rounded text-xs font-medium transition-colors",style:{background:"var(--hud-bg-alt)",color:"var(--terminal-text)"},title:"Browse folders",children:"📁"}),s.jsx("button",{onClick:Nt,disabled:!ce.trim(),className:"px-3 py-2 rounded text-xs font-medium",style:{background:"var(--accent)",color:"#fff",opacity:ce.trim()?1:.5},children:"Add"})]}),ge&&s.jsx(wc,{onSelect:we=>{Q.includes(we)||z([...Q,we]),Ae(!1)},onClose:()=>Ae(!1)}),Q.length>0&&s.jsx("div",{className:"space-y-1",children:Q.map((we,Wt)=>s.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},children:[s.jsx("span",{className:"flex-1 truncate",style:{fontFamily:"var(--pixel-font)"},children:we}),s.jsx("button",{onClick:()=>z(Q.filter((Sa,fl)=>fl!==Wt)),className:"opacity-50 hover:opacity-100",children:"✕"})]},Wt))}),Q.length===0&&s.jsx("div",{className:"text-[10px] text-center py-2",style:{color:"var(--terminal-text-muted)"},children:"Add at least one folder to import."})]})]}),s.jsxs("div",{className:sn(D==="existing-akb"),onClick:()=>F("existing-akb"),children:[s.jsxs("div",{className:"font-medium text-sm",children:["🔗"," Connect Existing AKB"]}),s.jsx("div",{className:"text-xs opacity-70 mt-1",children:"Connect a directory that already has CLAUDE.md and AKB structure."}),D==="existing-akb"&&s.jsxs("div",{className:"mt-3",onClick:we=>we.stopPropagation(),children:[s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{className:`${En} flex-1`,placeholder:"/path/to/your/akb",value:De,onChange:we=>{He(we.target.value),We(null)},autoFocus:!0}),s.jsx("button",{onClick:()=>Ce(!be),className:"px-3 py-2 rounded text-xs font-medium transition-colors",style:{background:"var(--hud-bg-alt)",color:"var(--terminal-text)"},title:"Browse folders",children:"📁"}),s.jsx("button",{onClick:an,disabled:de||!De.trim(),className:"px-3 py-2 rounded text-xs font-medium transition-colors",style:{background:"var(--accent)",color:"#fff",opacity:de||!De.trim()?.5:1},children:de?"...":"Verify"})]}),ye===!0&&s.jsxs("div",{className:"text-xs mt-2",style:{color:"var(--active-green)"},children:["✅"," Valid AKB found: ",De]}),ye===!1&&s.jsxs("div",{className:"text-xs mt-2",style:{color:"#EF4444"},children:["❌"," No valid AKB (CLAUDE.md required)"]}),be&&s.jsx(wc,{onSelect:we=>{He(we),We(null),Ce(!1)},onClose:()=>Ce(!1)})]})]})]}),$e==="team"&&s.jsxs("div",{className:"space-y-4",children:[s.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:"Team Template"}),s.jsx("p",{className:"text-xs",style:{color:"var(--terminal-text-secondary)"},children:"Choose a starting team. You can add or remove roles later."}),ze.map(we=>s.jsxs("div",{className:sn(Me===we.id),onClick:()=>ve(we.id),children:[s.jsx("div",{className:"font-medium text-sm capitalize",children:we.id}),s.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:we.roles.map(Wt=>s.jsx("span",{className:"px-2 py-0.5 rounded text-[10px]",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},children:Wt.name},Wt.id))})]},we.id)),s.jsxs("div",{className:sn(Me==="custom"),onClick:()=>ve("custom"),children:[s.jsx("div",{className:"font-medium text-sm",children:"Custom"}),s.jsx("div",{className:"text-xs opacity-70 mt-1",children:"Start with no pre-built roles. Hire them from the office."})]})]}),$e==="create"&&s.jsxs("div",{className:"space-y-4",children:[s.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:jt?D==="existing-akb"?"AKB Connected!":"Company Created!":"Review & Create"}),!jt&&!Oe&&!xe&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"rounded-lg p-4 space-y-2 text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:D==="existing-akb"?s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Mode:"})," Connect Existing AKB"]}),s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Path:"})," ",De]}),s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Engine:"})," ",u==="claude-cli"?"Claude Code CLI":"Direct API"]})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Company:"})," ",y]}),s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Location:"})," ",C||"(default)"]}),s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Engine:"})," ",u==="claude-cli"?"Claude Code CLI":"Direct API"]}),s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Project:"})," ",T==="fresh"?"Start Fresh":`Existing (${O})`]}),s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Knowledge:"})," ",D==="skip"?"Fresh (empty)":`Import ${Q.length} source(s)`]}),s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Team:"})," ",Me]}),D==="import"&&Q.length>0&&s.jsx("div",{className:"text-[10px] mt-1",style:{color:"var(--idle-amber)"},children:"Knowledge import will run in the background after entering the office."})]})}),yt&&s.jsx("div",{className:"text-xs p-3 rounded",style:{background:"rgba(220,38,38,0.15)",color:"#f87171"},children:yt})]}),(Oe||xe)&&s.jsxs("div",{className:"flex flex-col items-center py-8 gap-3",children:[s.jsx("div",{className:"w-8 h-8 border-2 rounded-full animate-spin",style:{borderColor:"var(--terminal-border)",borderTopColor:"var(--accent)"}}),s.jsx("div",{className:"text-sm",style:{color:"var(--terminal-text-secondary)"},children:xe?"Connecting to AKB...":"Scaffolding your company..."})]}),jt&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"text-center py-4 text-4xl",children:"🏢"}),Fe&&s.jsxs("div",{className:"rounded-lg p-3 text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:[s.jsx("span",{className:"opacity-50",children:"Location:"})," ",Fe]}),s.jsx("div",{className:"rounded-lg p-4 text-xs max-h-40 overflow-y-auto",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:re.map((we,Wt)=>s.jsxs("div",{className:"py-0.5",children:[s.jsx("span",{style:{color:"var(--active-green)"},children:"✓"})," ",we]},Wt))}),D==="import"&&Q.length>0&&s.jsx("div",{className:"text-xs p-3 rounded",style:{background:"var(--accent)",color:"#fff",opacity:.9},children:"Knowledge import will start in the background after entering the office."})]})]})]}),s.jsxs("div",{className:"px-6 py-4 flex justify-between items-center",style:{borderTop:"1px solid var(--terminal-border)"},children:[s.jsx("div",{children:l>0&&!jt&&s.jsx("button",{onClick:Qe,className:"px-4 py-2 rounded text-sm transition-colors",style:{color:"var(--terminal-text-secondary)",border:"1px solid var(--terminal-border)"},children:"Back"})}),s.jsxs("div",{className:"text-xs",style:{color:"var(--terminal-text-muted)"},children:[l+1," / ",Te.length]}),s.jsx("div",{children:jt?s.jsx("button",{onClick:ir,className:"px-5 py-2 rounded text-sm font-medium transition-colors",style:{background:"var(--active-green)",color:"#fff"},children:"Enter Office"}):s.jsx("button",{onClick:mt,disabled:!Ke()||Oe||xe,className:"px-5 py-2 rounded text-sm font-medium transition-colors",style:{background:Ke()?"var(--accent)":"var(--terminal-border)",color:"#fff",opacity:Ke()&&!Oe&&!xe?1:.5},children:$e==="create"?Oe||xe?xe?"Connecting...":"Creating...":D==="existing-akb"?"Connect AKB":"Create Company":"Next"})})]})]})})}function yN(){const[t,l]=k.useState(null),[r,i]=k.useState(!0),[c,u]=k.useState(null),d=k.useCallback(async()=>{i(!0),u(null);try{const m=await Ne.getStatus();l(m)}catch(m){u(m instanceof Error?m.message:"Failed to fetch status")}finally{i(!1)}},[]);return k.useEffect(()=>{d()},[d]),{initialized:(t==null?void 0:t.initialized)??!1,companyName:(t==null?void 0:t.companyName)??null,engine:(t==null?void 0:t.engine)??"none",companyRoot:(t==null?void 0:t.companyRoot)??"",loading:r,error:c,refetch:d}}const gN=k.lazy(()=>J2(()=>import("./preview-app-DcorIk-N.js"),[]));function _g(){return s.jsx("div",{className:"h-full flex items-center justify-center",style:{background:"var(--floor-dark)"},children:s.jsxs("div",{className:"text-center",children:[s.jsx("div",{className:"w-10 h-10 mx-auto border-2 rounded-full animate-spin",style:{borderColor:"var(--terminal-border)",borderTopColor:"var(--accent)"}}),s.jsx("div",{className:"mt-4 text-sm",style:{color:"var(--terminal-text-secondary)",fontFamily:"var(--pixel-font)"},children:"Loading..."})]})})}function bN(){var t;try{const l=localStorage.getItem("tycono-theme"),r=l&&l in Yr?l:"default",i=(t=Yr[r])==null?void 0:t.vars;if(!i)return;const c=document.documentElement;for(const[u,d]of Object.entries(i))c.style.setProperty(u,d)}catch{}}function vN(){const{initialized:t,loading:l,refetch:r}=yN(),[i,c]=k.useState(null);k.useEffect(()=>{bN()},[]);const u=d=>{d&&c(d),r()};return l?s.jsx(_g,{}):t?s.jsx(mN,{importJob:i,onImportDone:()=>c(null)}):s.jsx(pN,{onComplete:u})}function wN(){const t=new URLSearchParams(window.location.search).has("sprite-preview");return s.jsx(P2,{children:t?s.jsx(k.Suspense,{fallback:s.jsx(_g,{}),children:s.jsx(gN,{})}):s.jsx(vN,{})})}W2.createRoot(document.getElementById("root")).render(s.jsx(k.StrictMode,{children:s.jsx(wN,{})}));export{pg as H,gg as P,bg as S,SN as a,yg as b,xg as c,Wf as d,Tj as e,Dj as f,jN as g,zj as h,s as j,k as r};
100
+ placeholder:text-[var(--terminal-text-muted)]`,sn=we=>`p-4 rounded-lg border-2 cursor-pointer transition-all text-[var(--terminal-text)] ${we?"border-[var(--accent)] bg-[var(--accent)]/10":"border-[var(--terminal-border)] bg-[var(--hud-bg-alt)] hover:border-[var(--accent)]/50"}`;return s.jsx("div",{className:"h-full flex items-center justify-center",style:{background:"var(--floor-dark)"},onKeyDown:Fn,children:s.jsxs("div",{className:"w-full max-w-xl rounded-xl shadow-2xl overflow-hidden",style:{background:"var(--hud-bg)",border:"1px solid var(--terminal-border)"},children:[s.jsxs("div",{className:"px-6 py-5",style:{background:"var(--terminal-bg)",borderBottom:"1px solid var(--terminal-border)"},children:[s.jsx("div",{className:"text-lg font-bold",style:{color:"var(--terminal-text)",fontFamily:"var(--pixel-font)"},children:"tycono"}),s.jsx("div",{className:"text-xs mt-1",style:{color:"var(--terminal-text-secondary)"},children:"Build an AI company. Watch them work."}),s.jsx("div",{className:"flex gap-1.5 mt-4",children:Te.map((we,Wt)=>s.jsxs("div",{className:"flex-1",children:[s.jsx("div",{className:"h-1 rounded-full transition-colors",style:{background:Wt<=l?"var(--accent)":"var(--terminal-surface-light)"}}),s.jsx("div",{className:"text-[9px] mt-1 truncate",style:{color:Wt===l?"var(--terminal-text)":"var(--terminal-text-muted)"},children:xN[we]})]},we))})]}),s.jsxs("div",{className:"px-6 py-5 min-h-[280px]",children:[$e==="engine"&&s.jsxs("div",{className:"space-y-4",children:[s.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:"AI Engine Setup"}),f?s.jsx("div",{className:"text-sm",style:{color:"var(--terminal-text-secondary)"},children:"Detecting AI engine..."}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:sn(u==="claude-cli"),onClick:()=>(i==null?void 0:i.claudeCli)&&d("claude-cli"),style:{opacity:i!=null&&i.claudeCli?1:.4},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-lg",children:i!=null&&i.claudeCli?"✅":"❌"}),s.jsxs("div",{children:[s.jsx("div",{className:"font-medium text-sm",children:"Claude Code CLI"}),s.jsx("div",{className:"text-xs opacity-70",children:i!=null&&i.claudeCli?"Detected! Recommended — zero config needed.":"Not installed. Get it at claude.ai/download"})]})]})}),s.jsxs("div",{className:sn(u==="direct-api"),onClick:()=>d("direct-api"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-lg",children:i!=null&&i.apiKey?"✅":"🔑"}),s.jsxs("div",{className:"flex-1",children:[s.jsx("div",{className:"font-medium text-sm",children:"Anthropic API Key (BYOK)"}),s.jsx("div",{className:"text-xs opacity-70",children:i!=null&&i.apiKey?"API key found in environment.":"Enter your ANTHROPIC_API_KEY"})]})]}),u==="direct-api"&&!(i!=null&&i.apiKey)&&s.jsx("input",{type:"password",className:`${En} mt-3`,placeholder:"sk-ant-...",value:m,onChange:we=>x(we.target.value),autoFocus:!0})]})]})]}),$e==="company"&&s.jsxs("div",{className:"space-y-4",children:[s.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:"Company Info"}),s.jsxs("div",{children:[s.jsx("label",{className:"text-xs font-medium block mb-1",style:{color:"var(--terminal-text-secondary)"},children:"Company Name *"}),s.jsx("input",{ref:Y,className:En,placeholder:"e.g. Acme Corp",value:y,onChange:we=>b(we.target.value)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-xs font-medium block mb-1",style:{color:"var(--terminal-text-secondary)"},children:"Description"}),s.jsx("textarea",{className:`${En} resize-none`,rows:3,placeholder:"What does your AI company do?",value:v,onChange:we=>S(we.target.value)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-xs font-medium block mb-1",style:{color:"var(--terminal-text-secondary)"},children:"Location"}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{className:`${En} flex-1`,placeholder:"/path/to/your-company",value:C,onChange:we=>{A(we.target.value),_(!0)}}),s.jsx("button",{onClick:()=>G(!V),className:"px-3 py-2 rounded text-xs font-medium transition-colors shrink-0",style:{background:"var(--hud-bg-alt)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},title:"Browse folders",children:"📁"})]}),s.jsx("div",{className:"text-[10px] mt-1",style:{color:"var(--terminal-text-muted)"},children:"Where your AI company files will be created."}),V&&s.jsx(wc,{onSelect:we=>{A(we),_(!0),G(!1)},onClose:()=>G(!1)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-xs font-medium block mb-1",style:{color:"var(--terminal-text-secondary)"},children:"AI Response Language"}),s.jsxs("select",{className:En,value:j,onChange:we=>E(we.target.value),children:[s.jsx("option",{value:"auto",children:"Auto"}),s.jsx("option",{value:"en",children:"English"}),s.jsx("option",{value:"ko",children:"한국어"}),s.jsx("option",{value:"ja",children:"日本語"})]})]})]}),$e==="project"&&s.jsxs("div",{className:"space-y-4",children:[s.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:"Project Setup"}),s.jsxs("div",{className:sn(T==="fresh"),onClick:()=>{U("fresh"),K(null)},children:[s.jsxs("div",{className:"font-medium text-sm",children:["🌱"," Start Fresh"]}),s.jsx("div",{className:"text-xs opacity-70 mt-1",children:"Create a new AI company from scratch with clean directory structure."})]}),s.jsxs("div",{className:sn(T==="existing"),onClick:()=>U("existing"),children:[s.jsxs("div",{className:"font-medium text-sm",children:["📂"," Connect Existing Project"]}),s.jsx("div",{className:"text-xs opacity-70 mt-1",children:"Add AI company structure to an existing codebase or knowledge base."}),T==="existing"&&s.jsxs("div",{className:"mt-3",onClick:we=>we.stopPropagation(),children:[s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{className:`${En} flex-1`,placeholder:"/path/to/your/project",value:O,onChange:we=>{J(we.target.value),K(null)},autoFocus:!0}),s.jsx("button",{onClick:()=>Se(!me),className:"px-3 py-2 rounded text-xs font-medium transition-colors",style:{background:"var(--hud-bg-alt)",color:"var(--terminal-text)"},title:"Browse folders",children:"📁"}),s.jsx("button",{onClick:It,disabled:I||!O.trim(),className:"px-3 py-2 rounded text-xs font-medium transition-colors",style:{background:"var(--accent)",color:"#fff",opacity:I||!O.trim()?.5:1},children:I?"...":"Verify"})]}),ne===!0&&s.jsxs("div",{className:"text-xs mt-2",style:{color:"var(--active-green)"},children:["✅"," Path verified: ",O]}),ne===!1&&s.jsxs("div",{className:"text-xs mt-2",style:{color:"#EF4444"},children:["❌"," Invalid path"]}),me&&s.jsx(wc,{onSelect:we=>{J(we),K(!0),Se(!1)},onClose:()=>Se(!1)})]})]})]}),$e==="knowledge"&&s.jsxs("div",{className:"space-y-3",children:[s.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:"Knowledge Strategy"}),s.jsx("p",{className:"text-xs",style:{color:"var(--terminal-text-secondary)"},children:"How should AI handle your knowledge base?"}),s.jsxs("div",{className:sn(D==="skip"),onClick:()=>F("skip"),children:[s.jsxs("div",{className:"font-medium text-sm",children:["🌱"," Start Fresh"]}),s.jsx("div",{className:"text-xs opacity-70 mt-1",children:"Empty knowledge base. Add documents later from the office."})]}),s.jsxs("div",{className:sn(D==="import"),onClick:()=>F("import"),children:[s.jsxs("div",{className:"font-medium text-sm",children:["📚"," Import & Build"]}),s.jsx("div",{className:"text-xs opacity-70 mt-1",children:"Select folders with documents — AI reads, summarizes, and organizes them."}),D==="import"&&s.jsxs("div",{className:"mt-3 space-y-2",onClick:we=>we.stopPropagation(),children:[s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{className:`${En} flex-1`,placeholder:"/path/to/docs",value:ce,onChange:we=>Ee(we.target.value),onKeyDown:we=>{we.key==="Enter"&&(we.preventDefault(),Nt())},autoFocus:!0}),s.jsx("button",{onClick:()=>Ae(!ge),className:"px-3 py-2 rounded text-xs font-medium transition-colors",style:{background:"var(--hud-bg-alt)",color:"var(--terminal-text)"},title:"Browse folders",children:"📁"}),s.jsx("button",{onClick:Nt,disabled:!ce.trim(),className:"px-3 py-2 rounded text-xs font-medium",style:{background:"var(--accent)",color:"#fff",opacity:ce.trim()?1:.5},children:"Add"})]}),ge&&s.jsx(wc,{onSelect:we=>{Q.includes(we)||z([...Q,we]),Ae(!1)},onClose:()=>Ae(!1)}),Q.length>0&&s.jsx("div",{className:"space-y-1",children:Q.map((we,Wt)=>s.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},children:[s.jsx("span",{className:"flex-1 truncate",style:{fontFamily:"var(--pixel-font)"},children:we}),s.jsx("button",{onClick:()=>z(Q.filter((Sa,fl)=>fl!==Wt)),className:"opacity-50 hover:opacity-100",children:"✕"})]},Wt))}),Q.length===0&&s.jsx("div",{className:"text-[10px] text-center py-2",style:{color:"var(--terminal-text-muted)"},children:"Add at least one folder to import."})]})]}),s.jsxs("div",{className:sn(D==="existing-akb"),onClick:()=>F("existing-akb"),children:[s.jsxs("div",{className:"font-medium text-sm",children:["🔗"," Connect Existing AKB"]}),s.jsx("div",{className:"text-xs opacity-70 mt-1",children:"Connect a directory that already has CLAUDE.md and AKB structure."}),D==="existing-akb"&&s.jsxs("div",{className:"mt-3",onClick:we=>we.stopPropagation(),children:[s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{className:`${En} flex-1`,placeholder:"/path/to/your/akb",value:De,onChange:we=>{He(we.target.value),We(null)},autoFocus:!0}),s.jsx("button",{onClick:()=>Ce(!be),className:"px-3 py-2 rounded text-xs font-medium transition-colors",style:{background:"var(--hud-bg-alt)",color:"var(--terminal-text)"},title:"Browse folders",children:"📁"}),s.jsx("button",{onClick:an,disabled:de||!De.trim(),className:"px-3 py-2 rounded text-xs font-medium transition-colors",style:{background:"var(--accent)",color:"#fff",opacity:de||!De.trim()?.5:1},children:de?"...":"Verify"})]}),ye===!0&&s.jsxs("div",{className:"text-xs mt-2",style:{color:"var(--active-green)"},children:["✅"," Valid AKB found: ",De]}),ye===!1&&s.jsxs("div",{className:"text-xs mt-2",style:{color:"#EF4444"},children:["❌"," No valid AKB (CLAUDE.md required)"]}),be&&s.jsx(wc,{onSelect:we=>{He(we),We(null),Ce(!1)},onClose:()=>Ce(!1)})]})]})]}),$e==="team"&&s.jsxs("div",{className:"space-y-4",children:[s.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:"Team Template"}),s.jsx("p",{className:"text-xs",style:{color:"var(--terminal-text-secondary)"},children:"Choose a starting team. You can add or remove roles later."}),ze.map(we=>s.jsxs("div",{className:sn(Me===we.id),onClick:()=>ve(we.id),children:[s.jsx("div",{className:"font-medium text-sm capitalize",children:we.id}),s.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:we.roles.map(Wt=>s.jsx("span",{className:"px-2 py-0.5 rounded text-[10px]",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},children:Wt.name},Wt.id))})]},we.id)),s.jsxs("div",{className:sn(Me==="custom"),onClick:()=>ve("custom"),children:[s.jsx("div",{className:"font-medium text-sm",children:"Custom"}),s.jsx("div",{className:"text-xs opacity-70 mt-1",children:"Start with no pre-built roles. Hire them from the office."})]})]}),$e==="create"&&s.jsxs("div",{className:"space-y-4",children:[s.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:jt?D==="existing-akb"?"AKB Connected!":"Company Created!":"Review & Create"}),!jt&&!Oe&&!xe&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"rounded-lg p-4 space-y-2 text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:D==="existing-akb"?s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Mode:"})," Connect Existing AKB"]}),s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Path:"})," ",De]}),s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Engine:"})," ",u==="claude-cli"?"Claude Code CLI":"Direct API"]})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Company:"})," ",y]}),s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Location:"})," ",C||"(default)"]}),s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Engine:"})," ",u==="claude-cli"?"Claude Code CLI":"Direct API"]}),s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Project:"})," ",T==="fresh"?"Start Fresh":`Existing (${O})`]}),s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Knowledge:"})," ",D==="skip"?"Fresh (empty)":`Import ${Q.length} source(s)`]}),s.jsxs("div",{children:[s.jsx("span",{className:"opacity-50",children:"Team:"})," ",Me]}),D==="import"&&Q.length>0&&s.jsx("div",{className:"text-[10px] mt-1",style:{color:"var(--idle-amber)"},children:"Knowledge import will run in the background after entering the office."})]})}),yt&&s.jsx("div",{className:"text-xs p-3 rounded",style:{background:"rgba(220,38,38,0.15)",color:"#f87171"},children:yt})]}),(Oe||xe)&&s.jsxs("div",{className:"flex flex-col items-center py-8 gap-3",children:[s.jsx("div",{className:"w-8 h-8 border-2 rounded-full animate-spin",style:{borderColor:"var(--terminal-border)",borderTopColor:"var(--accent)"}}),s.jsx("div",{className:"text-sm",style:{color:"var(--terminal-text-secondary)"},children:xe?"Connecting to AKB...":"Scaffolding your company..."})]}),jt&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"text-center py-4 text-4xl",children:"🏢"}),Fe&&s.jsxs("div",{className:"rounded-lg p-3 text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:[s.jsx("span",{className:"opacity-50",children:"Location:"})," ",Fe]}),s.jsx("div",{className:"rounded-lg p-4 text-xs max-h-40 overflow-y-auto",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:re.map((we,Wt)=>s.jsxs("div",{className:"py-0.5",children:[s.jsx("span",{style:{color:"var(--active-green)"},children:"✓"})," ",we]},Wt))}),D==="import"&&Q.length>0&&s.jsx("div",{className:"text-xs p-3 rounded",style:{background:"var(--accent)",color:"#fff",opacity:.9},children:"Knowledge import will start in the background after entering the office."})]})]})]}),s.jsxs("div",{className:"px-6 py-4 flex justify-between items-center",style:{borderTop:"1px solid var(--terminal-border)"},children:[s.jsx("div",{children:l>0&&!jt&&s.jsx("button",{onClick:Qe,className:"px-4 py-2 rounded text-sm transition-colors",style:{color:"var(--terminal-text-secondary)",border:"1px solid var(--terminal-border)"},children:"Back"})}),s.jsxs("div",{className:"text-xs",style:{color:"var(--terminal-text-muted)"},children:[l+1," / ",Te.length]}),s.jsx("div",{children:jt?s.jsx("button",{onClick:ir,className:"px-5 py-2 rounded text-sm font-medium transition-colors",style:{background:"var(--active-green)",color:"#fff"},children:"Enter Office"}):s.jsx("button",{onClick:mt,disabled:!Ke()||Oe||xe,className:"px-5 py-2 rounded text-sm font-medium transition-colors",style:{background:Ke()?"var(--accent)":"var(--terminal-border)",color:"#fff",opacity:Ke()&&!Oe&&!xe?1:.5},children:$e==="create"?Oe||xe?xe?"Connecting...":"Creating...":D==="existing-akb"?"Connect AKB":"Create Company":"Next"})})]})]})})}function yN(){const[t,l]=k.useState(null),[r,i]=k.useState(!0),[c,u]=k.useState(null),d=k.useCallback(async()=>{i(!0),u(null);try{const m=await Ne.getStatus();l(m)}catch(m){u(m instanceof Error?m.message:"Failed to fetch status")}finally{i(!1)}},[]);return k.useEffect(()=>{d()},[d]),{initialized:(t==null?void 0:t.initialized)??!1,companyName:(t==null?void 0:t.companyName)??null,engine:(t==null?void 0:t.engine)??"none",companyRoot:(t==null?void 0:t.companyRoot)??"",loading:r,error:c,refetch:d}}const gN=k.lazy(()=>J2(()=>import("./preview-app-Bl6BvDdj.js"),[]));function _g(){return s.jsx("div",{className:"h-full flex items-center justify-center",style:{background:"var(--floor-dark)"},children:s.jsxs("div",{className:"text-center",children:[s.jsx("div",{className:"w-10 h-10 mx-auto border-2 rounded-full animate-spin",style:{borderColor:"var(--terminal-border)",borderTopColor:"var(--accent)"}}),s.jsx("div",{className:"mt-4 text-sm",style:{color:"var(--terminal-text-secondary)",fontFamily:"var(--pixel-font)"},children:"Loading..."})]})})}function bN(){var t;try{const l=localStorage.getItem("tycono-theme"),r=l&&l in Yr?l:"default",i=(t=Yr[r])==null?void 0:t.vars;if(!i)return;const c=document.documentElement;for(const[u,d]of Object.entries(i))c.style.setProperty(u,d)}catch{}}function vN(){const{initialized:t,loading:l,refetch:r}=yN(),[i,c]=k.useState(null);k.useEffect(()=>{bN()},[]);const u=d=>{d&&c(d),r()};return l?s.jsx(_g,{}):t?s.jsx(mN,{importJob:i,onImportDone:()=>c(null)}):s.jsx(pN,{onComplete:u})}function wN(){const t=new URLSearchParams(window.location.search).has("sprite-preview");return s.jsx(P2,{children:t?s.jsx(k.Suspense,{fallback:s.jsx(_g,{}),children:s.jsx(gN,{})}):s.jsx(vN,{})})}W2.createRoot(document.getElementById("root")).render(s.jsx(k.StrictMode,{children:s.jsx(wN,{})}));export{pg as H,gg as P,bg as S,SN as a,yg as b,xg as c,Wf as d,Tj as e,Dj as f,jN as g,zj as h,s as j,k as r};