@fugood/bricks-cli 2.23.0-beta.29 → 2.23.0-beta.52

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.
@@ -0,0 +1 @@
1
+ export const __webpack_esm_id__=153;export const __webpack_esm_ids__=[153];export const __webpack_esm_modules__={7153:(e,i,t)=>{t.r(i),t.d(i,{initProject:()=>A});var n,l,o,s=t(9436),r=t(147),a=t(6928),c=t(9896),u=t(5317),d=t(8568),g=t(9790),p=t(5250),y=t(637),f=t(8765),m=t(7742),h=function(e){try{return(0,u.execSync)(`which ${e}`,{stdio:"ignore"}),!0}catch(e){return!1}},b=function(e,i,t){return new Promise(function(n,l){var o=[e].concat(r(i)).join(" "),s=(0,u.spawn)(o,[],{cwd:t,stdio:"pipe",shell:!0});s.on("close",function(e){0===e?n():l(new Error(`Command failed with code ${e}`))}),s.on("error",l)})},v=(n=s(function*(e,i){try{var n=yield Promise.resolve().then(t.bind(t,2785)),l=a.extname(i);if([".ts",".tsx",".js",".jsx"].includes(l))return yield n.format(e,{parser:"typescript",trailingComma:"all",tabWidth:2,semi:!1,singleQuote:!0,printWidth:100});if(".json"===l)return yield n.format(e,{parser:"json"})}catch(e){}return e}),function(e,i){return n.apply(this,arguments)}),j=(l=s(function*(e,i){console.log(d.Ay.bold.cyan(`\nInitialize BRICKS Project: ${i}\n`));var t=yield(0,y.kv)({message:"Select files to include:",choices:[{name:"GitHub Actions workflow (.github/workflows/ci.yml)",value:"githubActions",checked:!1!==e.githubActions},{name:"AGENTS.md",value:"agents",checked:!1!==e.agents},{name:"CLAUDE.md",value:"claude",checked:!1!==e.claude},{name:"GEMINI.md",value:"gemini",checked:!0===e.gemini}]}),n=yield(0,y.kv)({message:"Select post-generation steps:",choices:[{name:"Run bun install",value:"install",checked:!1!==e.install},{name:"Initialize git repository",value:"git",checked:!1!==e.git}]}),l=yield(0,y.hF)({message:"Output directory:",default:e.output||process.cwd()});return{githubActions:t.includes("githubActions"),agents:t.includes("agents"),claude:t.includes("claude"),gemini:t.includes("gemini"),install:n.includes("install"),git:n.includes("git"),output:l}}),function(e,i){return l.apply(this,arguments)}),A=(o=s(function*(e,i,t){var n,l,o=(n=(0,f.getCurrentProfile)(),(l=(0,f.getToken)(n))||(console.error(d.Ay.red("Not logged in. Use `bricks auth login` first.")),process.exit(1)),(0,m.createClient)((0,f.getBaseUrl)(),l)),r=t.json,u=t.yes||r,y="application"===e,A=y?"UNSTABLE_applicationProject":"UNSTABLE_moduleProject",k=y?o.queries.applicationProject:o.queries.moduleProject,w=r?null:(0,g.default)(`Fetching ${e} info...`).start(),S="bricks-project";try{var _=(yield o.query(k,{id:i,buildApplicationOnly:!0}))[A];if(null!=_&&_.files){var x=_.files.find(function(e){return"application.json"===e.name});if(x)try{var $=JSON.parse(x.input);S=p.kebabCase($.name||"bricks-project")}catch(e){}}w&&w.stop()}catch(e){w&&w.stop()}var P,C=Object.assign({},t);if(!u)try{var z=yield j(t,S);C=Object.assign({},t,z)}catch(e){console.log(d.Ay.yellow("\nCancelled")),process.exit(0)}w=r?null:(0,g.default)(`Fetching ${e} project...`).start();try{var I=(yield o.query(k,{id:i,buildApplicationOnly:!1,setupGitHubActions:!1!==C.githubActions,setupAgents:!1!==C.agents,setupClaudeCode:!1!==C.claude,setupGeminiCLI:!0===C.gemini}))[A];null!=I&&I.files||(w?w.fail(`${p.capitalize(e)} project not found`):console.error(JSON.stringify({error:`${p.capitalize(e)} project not found`})),process.exit(1));var N=I.files.find(function(e){return"application.json"===e.name});if(N)try{var O=JSON.parse(N.input);S=p.kebabCase(O.name||"bricks-project")}catch(e){}var E=C.output||process.cwd(),F=a.resolve(E,S);c.existsSync(F)&&(w?w.fail(`Directory already exists: ${F}`):console.error(JSON.stringify({error:`Directory already exists: ${F}`})),process.exit(1)),w&&(w.text="Creating project directory..."),c.mkdirSync(F,{recursive:!0}),w&&(w.text="Writing project files...");var B=yield Promise.all(I.files.map((P=s(function*(e){var i=a.join(F,e.name),t=e.input;return e.formatable&&(t=yield v(t,i)),Object.assign({},e,{filePath:i,content:t})}),function(e){return P.apply(this,arguments)})));B.forEach(function(e){var i=a.dirname(e.filePath);c.existsSync(i)||c.mkdirSync(i,{recursive:!0}),c.writeFileSync(e.filePath,e.content)}),w&&w.succeed(`Project created: ${d.Ay.green(F)} (${I.files.length} files)`);var G=h("bun"),J=h("git"),D=!1,L=!1;if(!1!==C.install&&G){var U=r?null:(0,g.default)("Installing dependencies...").start();try{yield b("bun",["install"],F),D=!0,U&&U.succeed("Dependencies installed")}catch(e){U&&U.fail(`Failed to install dependencies: ${e.message}`)}}else G||!1===C.install||r||(console.log(d.Ay.yellow("\nBun is not installed. Please install Bun and run `bun install` manually.")),console.log(d.Ay.gray(" Install Bun: https://bun.sh/docs/installation")));if(!1!==C.git&&J){var q=r?null:(0,g.default)("Initializing git repository...").start();try{yield b("git",["init"],F),yield b("git",["add","."],F),yield b("git",["-c 'user.name=BRICKS CLI'","-c 'user.email=cli@bricks.tools'","commit","-m 'chore: initialize commit'"],F),L=!0,q&&q.succeed("Git repository initialized")}catch(e){q&&q.fail(`Failed to initialize git: ${e.message}`)}}else J||!1===C.git||r||console.log(d.Ay.yellow("\nGit is not installed. Skipping git initialization."));r?console.log(JSON.stringify({success:!0,path:F,files:I.files.length,bunInstalled:D,gitInitialized:L})):(console.log(""),console.log(d.Ay.bold.green("Project initialized successfully!")),console.log(""),console.log(d.Ay.bold("Next steps:")),console.log(d.Ay.gray(` cd ${S}`)),G||console.log(d.Ay.gray(" bun install")),console.log(d.Ay.gray(" bun preview")),console.log(""),console.log(d.Ay.gray(`For more information, see ${S}/README.md`)))}catch(e){r?console.error(JSON.stringify({error:e.message})):w?w.fail(`Failed to initialize project: ${e.message}`):console.error(d.Ay.red(`Failed to initialize project: ${e.message}`)),process.exit(1)}}),function(e,i,t){return o.apply(this,arguments)})}};
@@ -0,0 +1 @@
1
+ export const __webpack_esm_id__=612;export const __webpack_esm_ids__=[612];export const __webpack_esm_modules__={9612:(e,l,n)=>{n.d(l,{App:()=>De,AppDetail:()=>F,AppList:()=>V,CONTROL_ACTIONS:()=>x,DeviceControl:()=>N,DeviceDetail:()=>M,DeviceList:()=>P,DeviceScreenshot:()=>G,DeviceStatus:()=>b,Footer:()=>D,GroupDetail:()=>Y,GroupList:()=>q,Header:()=>v,Loading:()=>T,MainMenu:()=>O,MediaBoxDetail:()=>X,MediaBoxList:()=>W,MediaFileDetail:()=>K,MediaFileList:()=>J,ModuleDetail:()=>$,ModuleList:()=>H,ONLINE_THRESHOLD_MS:()=>h,ProjectInitView:()=>ve,ShortEditEditor:()=>ie,VIEWS:()=>d,runInteractiveMode:()=>Te}),n.r(l);var t=n(1649),i=n(8498),o=n(9557),r=n(9436),c=n(8832),a=n(7742),s=n(8765),u=n(7336),d={MAIN:"main",DEVICES:"devices",DEVICE_DETAIL:"device_detail",DEVICE_CONTROL:"device_control",DEVICE_SCREENSHOT:"device_screenshot",APPS:"apps",APP_DETAIL:"app_detail",APP_SHORT_EDIT:"app_short_edit",APP_PROJECT_INIT:"app_project_init",MODULES:"modules",MODULE_DETAIL:"module_detail",MODULE_SHORT_EDIT:"module_short_edit",MODULE_PROJECT_INIT:"module_project_init",GROUPS:"groups",GROUP_DETAIL:"group_detail",MEDIA_BOXES:"media_boxes",MEDIA_BOX_DETAIL:"media_box_detail",MEDIA_FILES:"media_files",MEDIA_FILE_DETAIL:"media_file_detail"},x=[{label:"Refresh Application",value:"refresh"},{label:"Clear Cache",value:"clear-cache"},{label:"Take Screenshot",value:"take-screenshot"},{label:"Open System Menu",value:"system-menu-open"},{label:"Close System Menu",value:"system-menu-close"},{label:"Open Debug Panel",value:"debug-panel-open"},{label:"Close Debug Panel",value:"debug-panel-close"},{label:"Enable Logging",value:"logging-on"},{label:"Disable Logging",value:"logging-off"},{label:"← Back",value:"back"}],h=3e5,f=n(7661);const g=function({type:e="dots"}){const[l,n]=(0,t.useState)(0),o=f[e];return(0,t.useEffect)(()=>{const e=setInterval(()=>{n(e=>e===o.frames.length-1?0:e+1)},o.interval);return()=>{clearInterval(e)}},[o]),t.default.createElement(i.Text,null,o.frames[l])};var m=n(1178),p=function(e){var l=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=Math.floor(60),i=(0,t.useState)(n),o=c(i,2),r=o[0],a=o[1],s=(0,t.useState)(null),u=c(s,2),d=u[0],x=u[1],h=(0,t.useRef)(e);(0,t.useEffect)(function(){h.current=e},[e]);var f=(0,t.useCallback)(function(){a(n),x(Date.now())},[n]);return(0,t.useEffect)(function(){if(l){var e=setInterval(function(){a(function(e){return e<=1?(null==h.current||h.current(),x(Date.now()),n):e-1})},1e3);return function(){return clearInterval(e)}}},[l,n]),(0,t.useEffect)(function(){l&&(a(n),x(Date.now()))},[l,n]),{countdown:r,lastRefreshTime:d,resetCountdown:f}},j=function(e){var l=e.countdown,n=e.lastRefreshTime;return(0,m.jsx)(i.Box,{children:(0,m.jsxs)(i.Text,{color:"gray",children:["Next refresh in ",(0,m.jsxs)(i.Text,{color:"cyan",children:[l,"s"]}),n&&(0,m.jsxs)(i.Text,{color:"gray",children:[" (last: ",n?new Date(n).toLocaleTimeString():null,")"]})]})})},v=function(e){var l=e.workspace,n=e.view;return(0,m.jsxs)(i.Box,{flexDirection:"column",marginBottom:1,children:[(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:"BRICKS CLI"}),(0,m.jsx)(i.Text,{color:"gray",children:" - Interactive Mode"})]}),(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{color:"gray",children:"Workspace: "}),(0,m.jsx)(i.Text,{color:"green",children:(null==l?void 0:l.name)||"Not connected"}),(0,m.jsx)(i.Text,{color:"gray",children:" | View: "}),(0,m.jsx)(i.Text,{color:"yellow",children:n})]}),(0,m.jsx)(i.Text,{color:"gray",children:"─".repeat(60)})]})},D=function(){return(0,m.jsxs)(i.Box,{marginTop:1,flexDirection:"column",children:[(0,m.jsx)(i.Text,{color:"gray",children:"─".repeat(60)}),(0,m.jsxs)(i.Text,{color:"gray",children:["Press ",(0,m.jsx)(i.Text,{color:"cyan",children:"q"})," to quit, ",(0,m.jsx)(i.Text,{color:"cyan",children:"Esc"})," to go back"]})]})},T=function(e){var l=e.text;return(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{color:"green",children:(0,m.jsx)(g,{type:"dots"})}),(0,m.jsxs)(i.Text,{children:[" ",l||"Loading..."]})]})},b=function(e){var l=e.lastAliveTime;if(!l)return(0,m.jsx)(i.Text,{color:"gray",children:"○ Unknown"});var n=Date.now()-new Date(l).getTime();if(n<=h)return(0,m.jsx)(i.Text,{color:"green",children:"● Online"});var t=Math.floor(n/6e4);if(t<60)return(0,m.jsxs)(i.Text,{color:"yellow",children:["○ Offline (",t,"m ago)"]});var o=Math.floor(t/60);if(o<24)return(0,m.jsxs)(i.Text,{color:"red",children:["○ Offline (",o,"h ago)"]});var r=Math.floor(o/24);return(0,m.jsxs)(i.Text,{color:"red",children:["○ Offline (",r,"d ago)"]})},_=n(147),y=n(9122);const B={circleQuestionMark:"(?)",questionMarkPrefix:"(?)",square:"█",squareDarkShade:"▓",squareMediumShade:"▒",squareLightShade:"░",squareTop:"▀",squareBottom:"▄",squareLeft:"▌",squareRight:"▐",squareCenter:"■",bullet:"●",dot:"․",ellipsis:"…",pointerSmall:"›",triangleUp:"▲",triangleUpSmall:"▴",triangleDown:"▼",triangleDownSmall:"▾",triangleLeftSmall:"◂",triangleRightSmall:"▸",home:"⌂",heart:"♥",musicNote:"♪",musicNoteBeamed:"♫",arrowUp:"↑",arrowDown:"↓",arrowLeft:"←",arrowRight:"→",arrowLeftRight:"↔",arrowUpDown:"↕",almostEqual:"≈",notEqual:"≠",lessOrEqual:"≤",greaterOrEqual:"≥",identical:"≡",infinity:"∞",subscriptZero:"₀",subscriptOne:"₁",subscriptTwo:"₂",subscriptThree:"₃",subscriptFour:"₄",subscriptFive:"₅",subscriptSix:"₆",subscriptSeven:"₇",subscriptEight:"₈",subscriptNine:"₉",oneHalf:"½",oneThird:"⅓",oneQuarter:"¼",oneFifth:"⅕",oneSixth:"⅙",oneEighth:"⅛",twoThirds:"⅔",twoFifths:"⅖",threeQuarters:"¾",threeFifths:"⅗",threeEighths:"⅜",fourFifths:"⅘",fiveSixths:"⅚",fiveEighths:"⅝",sevenEighths:"⅞",line:"─",lineBold:"━",lineDouble:"═",lineDashed0:"┄",lineDashed1:"┅",lineDashed2:"┈",lineDashed3:"┉",lineDashed4:"╌",lineDashed5:"╍",lineDashed6:"╴",lineDashed7:"╶",lineDashed8:"╸",lineDashed9:"╺",lineDashed10:"╼",lineDashed11:"╾",lineDashed12:"−",lineDashed13:"–",lineDashed14:"‐",lineDashed15:"⁃",lineVertical:"│",lineVerticalBold:"┃",lineVerticalDouble:"║",lineVerticalDashed0:"┆",lineVerticalDashed1:"┇",lineVerticalDashed2:"┊",lineVerticalDashed3:"┋",lineVerticalDashed4:"╎",lineVerticalDashed5:"╏",lineVerticalDashed6:"╵",lineVerticalDashed7:"╷",lineVerticalDashed8:"╹",lineVerticalDashed9:"╻",lineVerticalDashed10:"╽",lineVerticalDashed11:"╿",lineDownLeft:"┐",lineDownLeftArc:"╮",lineDownBoldLeftBold:"┓",lineDownBoldLeft:"┒",lineDownLeftBold:"┑",lineDownDoubleLeftDouble:"╗",lineDownDoubleLeft:"╖",lineDownLeftDouble:"╕",lineDownRight:"┌",lineDownRightArc:"╭",lineDownBoldRightBold:"┏",lineDownBoldRight:"┎",lineDownRightBold:"┍",lineDownDoubleRightDouble:"╔",lineDownDoubleRight:"╓",lineDownRightDouble:"╒",lineUpLeft:"┘",lineUpLeftArc:"╯",lineUpBoldLeftBold:"┛",lineUpBoldLeft:"┚",lineUpLeftBold:"┙",lineUpDoubleLeftDouble:"╝",lineUpDoubleLeft:"╜",lineUpLeftDouble:"╛",lineUpRight:"└",lineUpRightArc:"╰",lineUpBoldRightBold:"┗",lineUpBoldRight:"┖",lineUpRightBold:"┕",lineUpDoubleRightDouble:"╚",lineUpDoubleRight:"╙",lineUpRightDouble:"╘",lineUpDownLeft:"┤",lineUpBoldDownBoldLeftBold:"┫",lineUpBoldDownBoldLeft:"┨",lineUpDownLeftBold:"┥",lineUpBoldDownLeftBold:"┩",lineUpDownBoldLeftBold:"┪",lineUpDownBoldLeft:"┧",lineUpBoldDownLeft:"┦",lineUpDoubleDownDoubleLeftDouble:"╣",lineUpDoubleDownDoubleLeft:"╢",lineUpDownLeftDouble:"╡",lineUpDownRight:"├",lineUpBoldDownBoldRightBold:"┣",lineUpBoldDownBoldRight:"┠",lineUpDownRightBold:"┝",lineUpBoldDownRightBold:"┡",lineUpDownBoldRightBold:"┢",lineUpDownBoldRight:"┟",lineUpBoldDownRight:"┞",lineUpDoubleDownDoubleRightDouble:"╠",lineUpDoubleDownDoubleRight:"╟",lineUpDownRightDouble:"╞",lineDownLeftRight:"┬",lineDownBoldLeftBoldRightBold:"┳",lineDownLeftBoldRightBold:"┯",lineDownBoldLeftRight:"┰",lineDownBoldLeftBoldRight:"┱",lineDownBoldLeftRightBold:"┲",lineDownLeftRightBold:"┮",lineDownLeftBoldRight:"┭",lineDownDoubleLeftDoubleRightDouble:"╦",lineDownDoubleLeftRight:"╥",lineDownLeftDoubleRightDouble:"╤",lineUpLeftRight:"┴",lineUpBoldLeftBoldRightBold:"┻",lineUpLeftBoldRightBold:"┷",lineUpBoldLeftRight:"┸",lineUpBoldLeftBoldRight:"┹",lineUpBoldLeftRightBold:"┺",lineUpLeftRightBold:"┶",lineUpLeftBoldRight:"┵",lineUpDoubleLeftDoubleRightDouble:"╩",lineUpDoubleLeftRight:"╨",lineUpLeftDoubleRightDouble:"╧",lineUpDownLeftRight:"┼",lineUpBoldDownBoldLeftBoldRightBold:"╋",lineUpDownBoldLeftBoldRightBold:"╈",lineUpBoldDownLeftBoldRightBold:"╇",lineUpBoldDownBoldLeftRightBold:"╊",lineUpBoldDownBoldLeftBoldRight:"╉",lineUpBoldDownLeftRight:"╀",lineUpDownBoldLeftRight:"╁",lineUpDownLeftBoldRight:"┽",lineUpDownLeftRightBold:"┾",lineUpBoldDownBoldLeftRight:"╂",lineUpDownLeftBoldRightBold:"┿",lineUpBoldDownLeftBoldRight:"╃",lineUpBoldDownLeftRightBold:"╄",lineUpDownBoldLeftBoldRight:"╅",lineUpDownBoldLeftRightBold:"╆",lineUpDoubleDownDoubleLeftDoubleRightDouble:"╬",lineUpDoubleDownDoubleLeftRight:"╫",lineUpDownLeftDoubleRightDouble:"╪",lineCross:"╳",lineBackslash:"╲",lineSlash:"╱"},S={tick:"✔",info:"ℹ",warning:"⚠",cross:"✘",squareSmall:"◻",squareSmallFilled:"◼",circle:"◯",circleFilled:"◉",circleDotted:"◌",circleDouble:"◎",circleCircle:"ⓞ",circleCross:"ⓧ",circlePipe:"Ⓘ",radioOn:"◉",radioOff:"◯",checkboxOn:"☒",checkboxOff:"☐",checkboxCircleOn:"ⓧ",checkboxCircleOff:"Ⓘ",pointer:"❯",triangleUpOutline:"△",triangleLeft:"◀",triangleRight:"▶",lozenge:"◆",lozengeOutline:"◇",hamburger:"☰",smiley:"㋡",mustache:"෴",star:"★",play:"▶",nodejs:"⬢",oneSeventh:"⅐",oneNinth:"⅑",oneTenth:"⅒"},E={...B,...S},w={...B,tick:"√",info:"i",warning:"‼",cross:"×",squareSmall:"□",squareSmallFilled:"■",circle:"( )",circleFilled:"(*)",circleDotted:"( )",circleDouble:"( )",circleCircle:"(○)",circleCross:"(×)",circlePipe:"(│)",radioOn:"(*)",radioOff:"( )",checkboxOn:"[×]",checkboxOff:"[ ]",checkboxCircleOn:"(×)",checkboxCircleOff:"( )",pointer:">",triangleUpOutline:"∆",triangleLeft:"◄",triangleRight:"►",lozenge:"♦",lozengeOutline:"◊",hamburger:"≡",smiley:"☺",mustache:"┌─┐",star:"✶",play:"►",nodejs:"♦",oneSeventh:"1/7",oneNinth:"1/9",oneTenth:"1/10"},L=(0,y.A)(),I=L?E:w;Object.entries(S);const A=function({isSelected:e=!1}){return t.default.createElement(i.Box,{marginRight:1},e?t.default.createElement(i.Text,{color:"blue"},I.pointer):t.default.createElement(i.Text,null," "))};const C=function({isSelected:e=!1,label:l}){return t.createElement(i.Text,{color:e?"blue":void 0},l)};var R=n(7975);function k(e,l){if(!Array.isArray(e))throw new TypeError(`Expected an array, got \`${typeof e}\`.`);if(!Number.isSafeInteger(l))throw new TypeError(`The \`steps\` parameter must be an integer, got ${l}.`);const{length:n}=e;if(0===n)return[...e];const t=(l%n+n)%n;return 0===t?[...e]:[...e.slice(-t),...e.slice(0,-t)]}const U=function({items:e=[],isFocused:l=!0,initialIndex:n=0,indicatorComponent:o=A,itemComponent:r=C,limit:c,onSelect:a,onHighlight:s}){const u="number"==typeof c&&e.length>c,d=u?Math.min(c,e.length):e.length,x=d-1,[h,f]=(0,t.useState)(n>x?x-n:0),[g,m]=(0,t.useState)(n?n>x?x:n:0),p=(0,t.useRef)(e);(0,t.useEffect)(()=>{(0,R.isDeepStrictEqual)(p.current.map(e=>e.value),e.map(e=>e.value))||(f(0),m(0)),p.current=e},[e]),(0,i.useInput)((0,t.useCallback)((l,n)=>{if("k"===l||n.upArrow){const l=(u?d:e.length)-1,n=0===g,t=n?h+1:h,i=n?u?g:l:g-1;f(t),m(i);const o=u?k(e,t).slice(0,d):e;"function"==typeof s&&s(o[i])}if("j"===l||n.downArrow){const l=g===(u?d:e.length)-1,n=l?h-1:h,t=l?u?g:0:g+1;f(n),m(t);const i=u?k(e,n).slice(0,d):e;"function"==typeof s&&s(i[t])}if(/^[1-9]$/.test(l)){const n=Number.parseInt(l,10)-1,t=u?k(e,h).slice(0,d):e;if(n>=0&&n<t.length){const e=t[n];e&&a?.(e)}}if(n.return){const l=u?k(e,h).slice(0,d):e;"function"==typeof a&&a(l[g])}},[u,d,h,g,e,a,s]),{isActive:l});const j=u?k(e,h).slice(0,d):e;return t.default.createElement(i.Box,{flexDirection:"column"},j.map((e,l)=>{const n=l===g;return t.default.createElement(i.Box,{key:e.key??e.value},t.default.createElement(o,{isSelected:n}),t.default.createElement(r,{...e,isSelected:n}))}))};var O=function(e){var l=e.onSelect,n=e.mediaEnabled,t=[{label:"Devices",value:d.DEVICES},{label:"Applications",value:d.APPS},{label:"Modules",value:d.MODULES},{label:"Device Groups",value:d.GROUPS}].concat(_(n?[{label:"Media Flow",value:d.MEDIA_BOXES}]:[]),[{label:"Exit",value:"exit"}]);return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,marginBottom:1,children:"Main Menu"}),(0,m.jsx)(U,{items:t,onSelect:l})]})},P=function(e){var l=e.devices,n=e.loading,t=e.onSelect,o=e.countdown,r=e.lastRefreshTime;if(n)return(0,m.jsx)(T,{text:"Loading devices..."});if(null==l||!l.length)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{color:"yellow",children:"No devices found"}),(0,m.jsx)(j,{countdown:o,lastRefreshTime:r})]});var c=[].concat(_(l.map(function(e){var l;return{label:`${function(e){if(!e)return"○ Unknown";var l=Date.now()-new Date(e).getTime();if(l<=h)return"● Online";var n=Math.floor(l/6e4);if(n<60)return`○ ${n}m ago`;var t=Math.floor(n/60);return t<24?`○ ${t}h ago`:`○ ${Math.floor(t/24)}d ago`}(null==(l=e.entry_detail)||null==(l=l.watch_dog_timer)?void 0:l.last_alive_time)} - ${e.name||e.device_name}`,value:e._id,device:e}})),[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}]);return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Box,{marginBottom:1,children:[(0,m.jsxs)(i.Text,{bold:!0,children:["Devices (",l.length,")"]}),(0,m.jsx)(i.Text,{color:"gray",children:" - "}),(0,m.jsx)(j,{countdown:o,lastRefreshTime:r})]}),(0,m.jsx)(U,{items:c,onSelect:t})]})},M=function(e){var l,n,t,o,r,c=e.device,a=e.loading,s=e.error,u=e.onSelect,d=e.mediaEnabled,x=e.countdown,h=e.lastRefreshTime;if(a)return(0,m.jsx)(T,{text:"Loading device..."});if(s)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",s]}),(0,m.jsx)(U,{items:[{label:"← Back",value:"back"}],onSelect:u})]});if(!c)return(0,m.jsx)(i.Text,{color:"red",children:"Device not found"});var f=[{label:"Control Device",value:"control"}].concat(_(d?[{label:"View Screenshot",value:"screenshot"}]:[]),[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}]),g=c.entry_detail,p=null==g?void 0:g.screen,v=null==g?void 0:g.update,D=null==g?void 0:g.local_sync;return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:c.name||c.device_name}),(0,m.jsx)(i.Text,{color:"gray",children:" - "}),(0,m.jsx)(j,{countdown:x,lastRefreshTime:h})]}),c.description&&(0,m.jsx)(i.Text,{color:"gray",children:c.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{color:"gray",children:"Status: "}),(0,m.jsx)(b,{lastAliveTime:null==g||null==(l=g.watch_dog_timer)?void 0:l.last_alive_time})]}),(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",c._id]}),(null==(n=c.tags)?void 0:n.length)>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",c.tags.join(", ")]}),(null==g?void 0:g.application)&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Application"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" Name: ",g.application.name]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" Mode: ",g.operation_mode||"N/A"]})]}),p&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Screen"}),p.resolution&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Resolution: ",p.resolution.width,"x",p.resolution.height,p.resolution.scale&&` @${p.resolution.scale}x`]}),p.orientation&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Orientation: ",p.orientation]}),p.touch&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Touch:"," ",p.touch.available?`Yes (${p.touch.touch_point} points)`:"No"]})]}),((null==g?void 0:g.memory_usage)||(null==g?void 0:g.disk_usage))&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"System"}),g.memory_usage&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Memory: ",Math.round(100*g.memory_usage),"%"]}),g.disk_usage&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Disk: ",Math.round(100*g.disk_usage),"%"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Capabilities"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Sound: ",null!=g&&null!=(t=g.sound)&&t.available?"✓":"✗"," | ","Camera: ",null!=g&&null!=(o=g.camera)&&o.available?"✓":"✗"," | ","Audio In: ",null!=g&&null!=(r=g.audio_in)&&r.available?"✓":"✗"]})]}),D&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Local Sync"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Role: ",D.is_main?"Main":"Peer",D.peer_count>0&&` | Peers: ${D.peer_count}`,D.mean_latency&&` | Latency: ${D.mean_latency}ms`]})]}),v&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Update"}),(0,m.jsxs)(i.Text,{color:v.need_update?"yellow":"gray",children:[" ","Status: ",v.need_update?"⚠ Update available":"✓ Up to date"]}),v.current_version&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Version: ",v.current_version]})]})]}),(0,m.jsx)(U,{items:f,onSelect:u})]})},N=function(e){var l=e.device,n=e.onSelect,t=e.controlling,o=e.controlResult;return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,color:"cyan",children:["Control: ",(null==l?void 0:l.name)||(null==l?void 0:l.device_name)]}),t&&(0,m.jsx)(T,{text:"Sending command..."}),o&&(0,m.jsx)(i.Text,{color:o.success?"green":"red",children:o.message}),(0,m.jsx)(i.Box,{marginTop:1,children:(0,m.jsx)(U,{items:x,onSelect:n})})]})},G=function(e){var l,n,t=e.device,r=e.screenshot,c=e.loading,a=e.error,s=e.onSelect,u=null==r||null==(l=r.file)?void 0:l.meta,d=null!=(null==u?void 0:u.originalWidth)&&null!=(null==u?void 0:u.originalHeight),x=null!=(null==u?void 0:u.originalFileSize);return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,color:"cyan",children:["Screenshot: ",(null==t?void 0:t.name)||(null==t?void 0:t.device_name)||"Unknown"]}),c&&(0,m.jsx)(T,{text:"Loading screenshot..."}),a&&(0,m.jsx)(i.Box,{marginY:1,children:(0,m.jsx)(i.Text,{color:"red",children:String(a)})}),!c&&!a&&r&&(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Box,{height:30,children:(0,m.jsx)(o.default,{src:r.path,width:80,alt:"Device screenshot"})}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Screenshot Details"}),(0,m.jsxs)(i.Box,{marginY:1,children:[(0,m.jsx)(i.Text,{color:"green",children:"Screenshot saved to: "}),(0,m.jsx)(i.Text,{color:"cyan",children:String(r.path||"")})]}),d&&(0,m.jsxs)(i.Text,{color:"gray",children:["Size: ",String(u.originalWidth),"x",String(u.originalHeight)]}),x&&(0,m.jsxs)(i.Text,{color:"gray",children:["File: ",(Number(u.originalFileSize)/1024).toFixed(1)," KB"]}),(null==(n=r.file)?void 0:n.updatedAt)&&(0,m.jsxs)(i.Text,{color:"gray",children:["Updated: ",new Date(r.file.updatedAt).toLocaleString()]})]})]}),!c&&!a&&!r&&(0,m.jsx)(i.Box,{marginY:1,children:(0,m.jsx)(i.Text,{color:"yellow",children:"No screenshot available. Try taking a new one."})}),(0,m.jsx)(i.Box,{marginTop:1,children:(0,m.jsx)(U,{items:[{label:"Take New Screenshot",value:"take"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:s})})]})},V=function(e){var l=e.apps,n=e.loading,t=e.onSelect;if(n)return(0,m.jsx)(T,{text:"Loading applications..."});if(null==l||!l.length)return(0,m.jsx)(i.Text,{color:"yellow",children:"No applications found"});var o=[].concat(_(l.map(function(e){return{label:`${e.has_unreleased_changes?"●":"○"} ${e.name}`,value:e._id,app:e}})),[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}]);return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Applications (",l.length,")"]}),(0,m.jsx)(U,{items:o,onSelect:t})]})},F=function(e){var l,n,t,o,r,c,a,s,u,d=e.app,x=e.loading,h=e.error,f=e.onSelect;if(x)return(0,m.jsx)(T,{text:"Loading application..."});if(h)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",h]}),(0,m.jsx)(U,{items:[{label:"← Back",value:"back"}],onSelect:f})]});if(!d)return(0,m.jsx)(i.Text,{color:"red",children:"Application not found"});var g=(null==(l=d.short_edit)?void 0:l.enabled)&&d.short_edit.ref_map,p=[{label:"⚡ Initialize Project",value:"project_init"}].concat(_(g?[{label:"Short Edit",value:"short_edit"}]:[]),[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}]),j=(null==(n=d.devices)?void 0:n.length)||0,v=(null==(t=d.devices)||null==(t=t.filter(function(e){return"online"===e.status}))?void 0:t.length)||0;return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:d.name}),d.description&&(0,m.jsx)(i.Text,{color:"gray",children:d.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",d._id]}),(null==(o=d.tags)?void 0:o.length)>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",d.tags.join(", ")]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Version"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Current: ",d.current_version?`v${d.current_version}`:"N/A"]}),(0,m.jsxs)(i.Text,{color:d.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",d.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]}),d.current_version_details&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Released: v",d.current_version_details.version||"N/A"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Devices"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Total: ",j,j>0&&` (${v} online)`]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Features"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Short Edit: ",null!=(r=d.short_edit)&&r.enabled?"✓ Enabled":"✗ Disabled"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Canvas Control: ",null!=(c=d.canvas_control)&&c.enabled?"✓ Enabled":"✗ Disabled"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Device Control: ",null!=(a=d.device_control)&&a.enabled?"✓ Enabled":"✗ Disabled"]}),(0,m.jsxs)(i.Text,{color:null!=(s=d.lock)&&s.enabled?"yellow":"gray",children:[" ","Lock: ",null!=(u=d.lock)&&u.enabled?"🔒 Locked":"🔓 Unlocked"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),d.create_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(d.create_datetime).toLocaleString()]}),d.last_modify_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Modified: ",new Date(d.last_modify_datetime).toLocaleString()]})]})]}),(0,m.jsx)(U,{items:p,onSelect:f})]})},H=function(e){var l=e.modules,n=e.loading,t=e.onSelect;if(n)return(0,m.jsx)(T,{text:"Loading modules..."});var o=(l||[]).map(function(e){return{label:`${e.current_version?"●":"○"} ${e.name}`,value:e._id,module:e}}),r=[].concat(_(o),[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}]);return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Modules (",(null==l?void 0:l.length)||0,")"]}),!(null!=l&&l.length)&&(0,m.jsx)(i.Text,{color:"yellow",children:"No modules found"}),(0,m.jsx)(U,{items:r,onSelect:t})]})},$=function(e){var l,n,t,o,r,c=e.module,a=e.loading,s=e.error,u=e.onSelect;if(a)return(0,m.jsx)(T,{text:"Loading module..."});if(s)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",s]}),(0,m.jsx)(U,{items:[{label:"← Back",value:"back"}],onSelect:u})]});if(!c)return(0,m.jsx)(i.Text,{color:"red",children:"Module not found"});var d=(null==(l=c.short_edit)?void 0:l.enabled)&&c.short_edit.ref_map,x=[{label:"⚡ Initialize Project",value:"project_init"}].concat(_(d?[{label:"Short Edit",value:"short_edit"}]:[]),[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}]);return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:c.name}),c.description&&(0,m.jsx)(i.Text,{color:"gray",children:c.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",c._id]}),(null==(n=c.tags)?void 0:n.length)>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",c.tags.join(", ")]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Version"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Current: ",c.current_version?`v${c.current_version}`:"N/A"]}),(0,m.jsxs)(i.Text,{color:c.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",c.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Usage"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Used in: ",(null==(t=c.use_count)?void 0:t.total_count)||0," application(s)"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Settings"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Public: ",c.is_public?"✓ Yes":"✗ No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Modifiable: ",c.is_allow_modify?"✓ Yes":"✗ No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Short Edit: ",null!=(o=c.short_edit)&&o.enabled?"✓ Enabled":"✗ Disabled"]})]}),(null==(r=c.expose_properties)?void 0:r.length)>0&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Exposed Properties"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ",c.expose_properties.length," properties exposed"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),c.create_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(c.create_datetime).toLocaleString()]}),c.last_modify_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Modified: ",new Date(c.last_modify_datetime).toLocaleString()]})]})]}),(0,m.jsx)(U,{items:x,onSelect:u})]})},q=function(e){var l=e.groups,n=e.loading,t=e.onSelect,o=e.countdown,r=e.lastRefreshTime;if(n)return(0,m.jsx)(T,{text:"Loading device groups..."});var c=(l||[]).map(function(e){var l;return{label:`📁 ${e.name} (${(null==(l=e.devices)?void 0:l.length)||0} devices)`,value:e._id,group:e}}),a=[].concat(_(c),[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}]);return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Box,{marginBottom:1,children:[(0,m.jsxs)(i.Text,{bold:!0,children:["Device Groups (",(null==l?void 0:l.length)||0,")"]}),(0,m.jsx)(i.Text,{color:"gray",children:" - "}),(0,m.jsx)(j,{countdown:o,lastRefreshTime:r})]}),!(null!=l&&l.length)&&(0,m.jsx)(i.Text,{color:"yellow",children:"No device groups found"}),(0,m.jsx)(U,{items:a,onSelect:t})]})},z=function(e){var l=e.loading,n=e.groupDevices;return l?(0,m.jsx)(T,{text:"Loading devices..."}):null!=n&&n.length?(0,m.jsxs)(m.Fragment,{children:[n.slice(0,10).map(function(e){var l;return(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{color:"gray",children:" "}),(0,m.jsx)(b,{lastAliveTime:null==(l=e.entry_detail)||null==(l=l.watch_dog_timer)?void 0:l.last_alive_time}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ",e.name||e.device_name]}),e.device_target_name&&(0,m.jsxs)(i.Text,{color:"gray",dimColor:!0,children:[" ","(",e.device_target_name,")"]})]},e._id)}),n.length>10&&(0,m.jsxs)(i.Text,{color:"gray",dimColor:!0,children:[" ","... and ",n.length-10," more"]})]}):(0,m.jsx)(i.Text,{color:"gray",children:" No devices in this group"})},Y=function(e){var l,n,t=e.group,o=e.groupDevices,r=e.loading,c=e.error,a=e.onSelect,s=e.countdown,u=e.lastRefreshTime;if(r&&!t)return(0,m.jsx)(T,{text:"Loading device group..."});if(c)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",c]}),(0,m.jsx)(U,{items:[{label:"← Back",value:"back"}],onSelect:a})]});if(!t)return(0,m.jsx)(i.Text,{color:"red",children:"Device group not found"});return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:t.name}),(0,m.jsx)(i.Text,{color:"gray",children:" - "}),(0,m.jsx)(j,{countdown:s,lastRefreshTime:u})]}),t.description&&(0,m.jsx)(i.Text,{color:"gray",children:t.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",t._id]}),(null==(l=t.tags)?void 0:l.length)>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",t.tags.join(", ")]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsxs)(i.Text,{bold:!0,color:"white",children:["Devices (",(null==(n=t.devices)?void 0:n.length)||0,")"]}),(0,m.jsx)(z,{loading:r,groupDevices:o})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),t.create_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(t.create_datetime).toLocaleString()]}),t.last_modify_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Modified: ",new Date(t.last_modify_datetime).toLocaleString()]})]})]}),(0,m.jsx)(U,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:a})]})},W=function(e){var l=e.boxes,n=e.loading,t=e.onSelect;if(n)return(0,m.jsx)(T,{text:"Loading media boxes..."});if(null==l||!l.length)return(0,m.jsx)(i.Text,{color:"yellow",children:"No media boxes found"});var o=[].concat(_(l.map(function(e){return{label:`📦 ${e.name||"Unnamed"}`,value:e.id,box:e}})),[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}]);return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Media Boxes (",l.length,")"]}),(0,m.jsx)(U,{items:o,onSelect:t})]})},X=function(e){var l,n,t=e.box,o=e.loading,r=e.error,c=e.onSelect;if(o&&!t)return(0,m.jsx)(T,{text:"Loading media box..."});if(r)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",r]}),(0,m.jsx)(U,{items:[{label:"← Back",value:"back"}],onSelect:c})]});if(!t)return(0,m.jsx)(i.Text,{color:"red",children:"Media box not found"});return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:t.name||"Unnamed"}),t.description&&(0,m.jsx)(i.Text,{color:"gray",children:t.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",t.id]}),(null==(l=t.tags)?void 0:l.length)>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",t.tags.join(", ")]}),null!=t.size&&(0,m.jsxs)(i.Text,{color:"gray",children:["Size: ",t.size]}),(null==(n=t.passcodes)?void 0:n.length)>0&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsxs)(i.Text,{bold:!0,color:"white",children:["Passcodes (",t.passcodes.length,")"]}),t.passcodes.slice(0,5).map(function(e){return(0,m.jsxs)(i.Text,{color:"gray",children:[" ",e.name||"Passcode",": ",e.code]},e.id)}),t.passcodes.length>5&&(0,m.jsxs)(i.Text,{color:"gray",dimColor:!0,children:[" ","... and ",t.passcodes.length-5," more"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),t.createdAt&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(t.createdAt).toLocaleString()]}),t.updatedAt&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Modified: ",new Date(t.updatedAt).toLocaleString()]})]})]}),(0,m.jsx)(U,{items:[{label:"List Files",value:"files"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:c})]})},J=function(e){var l=e.files,n=e.loading,t=e.onSelect,o=e.box;if(n)return(0,m.jsx)(T,{text:"Loading media files..."});if(null==l||!l.length)return(0,m.jsx)(i.Text,{color:"yellow",children:"No media files found"});var r=[].concat(_(l.map(function(e){return{label:`${l=e.fileType,"Image"===l?"🖼":"Video"===l?"🎞":"Audio"===l?"🎵":"📄"} ${e.name||"Unnamed"}`,value:e.id,file:e};var l})),[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}]);return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Media Files (",l.length,")",null!=o&&o.name?` - ${o.name}`:""]}),(0,m.jsx)(U,{items:r,onSelect:t})]})},K=function(e){var l,n=e.file,t=e.loading,o=e.error,r=e.onSelect;if(t&&!n)return(0,m.jsx)(T,{text:"Loading media file..."});if(o)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",o]}),(0,m.jsx)(U,{items:[{label:"← Back",value:"back"}],onSelect:r})]});if(!n)return(0,m.jsx)(i.Text,{color:"red",children:"Media file not found"});var c=n.meta,a=(0,u.Gu)(n),s=(0,u.Gu)(n,{preferThumbnail:!0}),d=Boolean(s&&s!==a);return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:n.name||"Unnamed"}),n.description&&(0,m.jsx)(i.Text,{color:"gray",children:n.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",n.id]}),(0,m.jsxs)(i.Text,{color:"gray",children:["Box ID: ",n.boxId]}),(0,m.jsxs)(i.Text,{color:"gray",children:["Type: ",n.fileType]}),(null==(l=n.userTags)?void 0:l.length)>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",n.userTags.join(", ")]}),null!=(null==c?void 0:c.originalWidth)&&null!=(null==c?void 0:c.originalHeight)&&(0,m.jsxs)(i.Text,{color:"gray",children:["Size: ",c.originalWidth,"x",c.originalHeight]}),null!=(null==c?void 0:c.originalFileSize)&&(0,m.jsxs)(i.Text,{color:"gray",children:["File: ",(Number(c.originalFileSize)/1024).toFixed(1)," KB"]}),a&&(0,m.jsxs)(i.Text,{color:"gray",children:["Original URL: ",a]}),d&&(0,m.jsxs)(i.Text,{color:"gray",children:["Thumbnail URL: ",s]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),n.createdAt&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(n.createdAt).toLocaleString()]}),n.updatedAt&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Modified: ",new Date(n.updatedAt).toLocaleString()]})]})]}),(0,m.jsx)(U,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:r})]})},Q=n(8568);function Z({value:e,placeholder:l="",focus:n=!0,mask:o,highlightPastedText:r=!1,showCursor:c=!0,onChange:a,onSubmit:s}){const[u,d]=(0,t.useState)({cursorOffset:(e||"").length,cursorWidth:0}),{cursorOffset:x,cursorWidth:h}=u;(0,t.useEffect)(()=>{d(l=>{if(!n||!c)return l;const t=e||"";return l.cursorOffset>t.length-1?{cursorOffset:t.length,cursorWidth:0}:l})},[e,n,c]);const f=r?h:0,g=o?o.repeat(e.length):e;let m=g,p=l?Q.Ay.grey(l):void 0;if(c&&n){p=l.length>0?Q.Ay.inverse(l[0])+Q.Ay.grey(l.slice(1)):Q.Ay.inverse(" "),m=g.length>0?"":Q.Ay.inverse(" ");let e=0;for(const l of g)m+=e>=x-f&&e<=x?Q.Ay.inverse(l):l,e++;g.length>0&&x===g.length&&(m+=Q.Ay.inverse(" "))}return(0,i.useInput)((l,n)=>{if(n.upArrow||n.downArrow||n.ctrl&&"c"===l||n.tab||n.shift&&n.tab)return;if(n.return)return void(s&&s(e));let t=x,i=e,o=0;n.leftArrow?c&&t--:n.rightArrow?c&&t++:n.backspace||n.delete?x>0&&(i=e.slice(0,x-1)+e.slice(x,e.length),t--):(i=e.slice(0,x)+l+e.slice(x,e.length),t+=l.length,l.length>1&&(o=l.length)),x<0&&(t=0),x>e.length&&(t=e.length),d({cursorOffset:t,cursorWidth:o}),i!==e&&a(i)},{isActive:n}),t.default.createElement(i.Text,null,l?g.length>0?m:p:m)}const ee=Z;var le,ne=n(5704),te=["B","C","G","D"],ie=function(e){var l,n,o=e.instanceType,a=e.instance,s=e.client,u=e.onDone,d=e.onCancel,x=(0,i.useApp)().exit,h=(0,t.useState)("select_ref"),f=c(h,2),g=f[0],p=f[1],j=(0,t.useState)(""),v=c(j,2),D=v[0],b=v[1],y=(0,t.useState)("search"),B=c(y,2),S=B[0],E=B[1],w=(0,t.useState)(null),L=c(w,2),I=L[0],A=L[1],C=(0,t.useState)(null),R=c(C,2),k=R[0],O=R[1],P=(0,t.useState)(""),M=c(P,2),N=M[0],G=M[1],V=(0,t.useState)(""),F=c(V,2),H=F[0],$=F[1],q=(0,t.useState)(null),z=c(q,2),Y=z[0],W=z[1],X=(null==a||null==(l=a.short_edit)?void 0:l.ref_map)||{},J=Object.entries(X).filter(function(e){var l=c(e,2)[1];return l&&!l.hide}),K=(0,ne.V)(X,{keyword:D,types:te}),Q=K.flatMap(function(e){return[{label:e.label,value:`__header_${e.prefix}__`,isHeader:!0}].concat(_(e.refs.map(function(e){var l=e.shortId,n=e.ref;return{label:`${n.title||l} (${l})`,value:l,ref:n}})))}),Z=[].concat(_(D?[{label:"↻ Clear Search",value:"__clear_search__"}]:[]),[{label:"← Back",value:"__back__"}]),le=Q.length>0?[].concat(_(Q),_(Z)):Z,ie=le.findIndex(function(e){var l;return!(e.isHeader||null!=(l=e.value)&&l.startsWith("__"))});(0,i.useInput)(function(e,l){l.tab&&"select_ref"===g?E(function(e){return"search"===e?"list":"search"}):(l.escape&&("select_ref"===g&&d(),"input_path"===g&&p("select_ref"),"input_content"===g&&p("input_path"),"confirm"===g&&p("input_content"),"done"===g&&d()),"q"!==e||("input_path"===g||"input_content"===g)||"select_ref"===g&&"search"===S||x())},{isActive:!0});var oe,re=function(e){var l=e.trim();if(""===l)return null;try{return JSON.parse(l)}catch(e){return l}},ce=(oe=r(function*(){if(s&&null!=a&&a._id&&I){p("submitting"),W(null);try{var e,l={shortId:I,path:N.trim(),content:re(H),forwardDataLink:!0};null!=k&&null!=(e=k.inner_ref)&&e.pid&&(l.innerRefParentShortId=k.inner_ref.pid),"application"===o?yield s.shortEditApplication({id:a._id,list:[l]}):yield s.shortEditModule({id:a._id,list:[l]}),yield u(),p("done")}catch(e){W(e.message),p("confirm")}}}),function(){return oe.apply(this,arguments)});return null!=a&&null!=(n=a.short_edit)&&n.enabled?0===J.length?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{color:"yellow",children:"No Short Edit references found."}),(0,m.jsx)(U,{items:[{label:"← Back",value:"back"}],onSelect:d})]}):"select_ref"===g?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,children:"Short Edit References"}),(0,m.jsx)(i.Text,{color:"gray",dimColor:!0,children:"Showing: Brick, Canvas, Generator, Data"}),(0,m.jsxs)(i.Box,{marginTop:1,flexDirection:"column",children:[(0,m.jsx)(i.Text,{color:"gray",children:"Search (title or shortId)"}),(0,m.jsx)(ee,{value:D,placeholder:"type to filter, Enter to focus list",onChange:function(e){return b(e)},onSubmit:function(){return E("list")},focus:"search"===S}),(0,m.jsx)(i.Text,{color:"gray",dimColor:!0,children:"Press Tab to switch focus"})]}),(0,m.jsxs)(i.Box,{marginTop:1,children:[0===K.length&&(0,m.jsx)(i.Text,{color:"yellow",children:"No references match your search."}),(0,m.jsx)(U,{items:le,isFocused:"list"===S,initialIndex:ie>-1?ie:0,indicatorComponent:function(){return null},itemComponent:function(e){var l=e.label,n=e.isSelected;return e.isHeader?(0,m.jsx)(i.Box,{marginTop:1,children:(0,m.jsx)(i.Text,{bold:!0,color:"white",children:l})}):(0,m.jsxs)(i.Text,{color:n?"blue":void 0,children:[n?"❯":" "," ",l]})},onSelect:function(e){if("__back__"!==e.value)return"__clear_search__"===e.value?(b(""),void E("search")):void(e.isHeader||(A(e.value),O(e.ref),p("input_path")));d()}})]})]}):"input_path"===g?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{children:["Reference:"," ",(0,m.jsxs)(i.Text,{color:"cyan",children:[(null==k?void 0:k.title)||I," (",I,")"]})]}),(0,m.jsx)(i.Text,{marginTop:1,children:"Enter property path (e.g. title, property.backgroundColor)"}),Y&&(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",Y]}),(0,m.jsx)(ee,{value:N,placeholder:"path",onChange:function(e){G(e),Y&&W(null)},onSubmit:function(e){var l=e.trim();l?(G(l),p("input_content")):W("Path is required")},focus:!0})]}):"input_content"===g?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{children:["Path: ",(0,m.jsx)(i.Text,{color:"cyan",children:N})]}),(0,m.jsx)(i.Text,{marginTop:1,children:"Enter new content (JSON or plain text). Empty to clear."}),Y&&(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",Y]}),(0,m.jsx)(ee,{value:H,placeholder:"content",onChange:function(e){$(e),Y&&W(null)},onSubmit:function(){return p("confirm")},focus:!0})]}):"submitting"===g?(0,m.jsx)(T,{text:"Applying short edit..."}):"done"===g?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{color:"green",children:"Short edit applied successfully."}),(0,m.jsx)(U,{items:[{label:"Edit another property",value:"again"},{label:"← Back",value:"back"}],onSelect:function(e){"again"===e.value?(p("select_ref"),A(null),O(null),G(""),$(""),W(null)):d()}})]}):(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,marginBottom:1,children:"Confirm Short Edit"}),(0,m.jsxs)(i.Text,{children:["Reference:"," ",(0,m.jsxs)(i.Text,{color:"cyan",children:[(null==k?void 0:k.title)||I," (",I,")"]})]}),(0,m.jsxs)(i.Text,{children:["Path: ",(0,m.jsx)(i.Text,{color:"cyan",children:N})]}),(0,m.jsxs)(i.Text,{children:["Content: ",(0,m.jsx)(i.Text,{color:"cyan",children:H||"<empty>"})]}),Y&&(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",Y]}),(0,m.jsx)(U,{items:[{label:"Apply",value:"apply"},{label:"Edit Path",value:"edit_path"},{label:"Edit Content",value:"edit_content"},{label:"← Back",value:"back"}],onSelect:function(e){"apply"===e.value&&ce(),"edit_path"===e.value&&p("input_path"),"edit_content"===e.value&&p("input_content"),"back"===e.value&&d()}})]}):(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"yellow",children:["Short Edit is not enabled for this ",o,"."]}),(0,m.jsx)(U,{items:[{label:"← Back",value:"back"}],onSelect:d})]})},oe=n(8212),re=n(6928),ce=n(9896),ae=n(5317),se=n(5250),ue="options",de="output_dir",xe="confirm",he="generating",fe="post_install",ge="done",me=function(e){try{return(0,ae.execSync)(`which ${e}`,{stdio:"ignore"}),!0}catch(e){return!1}},pe=function(e,l,n){return new Promise(function(t,i){var o=[e].concat(_(l)).join(" "),r=(0,ae.spawn)(o,[],{cwd:n,stdio:"pipe",shell:!0});r.on("close",function(e){0===e?t():i(new Error(`Command failed with code ${e}`))}),r.on("error",i)})},je=(le=r(function*(e,l){try{var t=yield Promise.resolve().then(n.bind(n,2785)),i=re.extname(l);if([".ts",".tsx",".js",".jsx"].includes(i))return yield t.format(e,{parser:"typescript",trailingComma:"all",tabWidth:2,semi:!1,singleQuote:!0,printWidth:100});if(".json"===i)return yield t.format(e,{parser:"json"})}catch(e){}return e}),function(e,l){return le.apply(this,arguments)}),ve=function(e){var l,n=e.type,o=e.instance,a=e.client,s=e.onDone,u=e.onCancel,d=(0,i.useApp)().exit,x=(0,t.useState)(ue),h=c(x,2),f=h[0],p=h[1],j=(0,t.useState)({setupGitHubActions:!0,setupAgents:!0,setupClaudeCode:!0,setupGeminiCLI:!1,runBunInstall:!0,initGit:!0}),v=c(j,2),D=v[0],T=v[1],b=(0,t.useState)(process.cwd()),_=c(b,2),y=_[0],B=_[1],S=(0,t.useState)(""),E=c(S,2),w=E[0],L=E[1],I=(0,t.useState)(null),A=c(I,2),C=A[0],R=A[1],k=(0,t.useState)(null),O=c(k,2),P=O[0],M=O[1],N=se.kebabCase((null==o?void 0:o.name)||"bricks-project"),G=re.resolve(y,N),V=(0,t.useCallback)(function(e){"back"!==e.value?"continue"!==e.value?T(function(l){return Object.assign({},l,oe({},e.value,!l[e.value]))}):p(de):u()},[u]),F=(0,t.useCallback)(function(){ce.existsSync(G)?R(`Directory already exists: ${G}`):(R(null),p(xe))},[G]),H=(0,t.useCallback)((l=r(function*(e){var l;if("back"!==e.value)if("cancel"!==e.value){if("confirm"===e.value){p(he);try{L("Fetching project from BRICKS...");var t="application"===n,i=t?"UNSTABLE_applicationProject":"UNSTABLE_moduleProject",c=t?a.queries.applicationProject:a.queries.moduleProject,s=(yield a.query(c,{id:o._id,buildApplicationOnly:!1,setupGitHubActions:D.setupGitHubActions,setupAgents:D.setupAgents,setupClaudeCode:D.setupClaudeCode,setupGeminiCLI:D.setupGeminiCLI}))[i];if(null==s||!s.files)throw new Error("Failed to fetch project files");L("Creating project directory..."),ce.mkdirSync(G,{recursive:!0}),L(`Writing ${s.files.length} files...`);var d=yield Promise.all(s.files.map((l=r(function*(e){var l=re.join(G,e.name),n=e.input;return e.formatable&&(n=yield je(n,l)),Object.assign({},e,{filePath:l,content:n})}),function(e){return l.apply(this,arguments)})));d.forEach(function(e){var l=re.dirname(e.filePath);ce.existsSync(l)||ce.mkdirSync(l,{recursive:!0}),ce.writeFileSync(e.filePath,e.content)}),p(fe);var x={path:G,files:s.files.length,bunInstalled:!1,gitInitialized:!1};if(D.runBunInstall&&me("bun")){L("Installing dependencies (bun install)...");try{yield pe("bun",["install"],G),x.bunInstalled=!0}catch(e){}}if(D.initGit&&me("git")){L("Initializing git repository...");try{yield pe("git",["init"],G),yield pe("git",["add","."],G),yield pe("git",["-c 'user.name=BRICKS CLI'","-c 'user.email=cli@bricks.tools'","commit","-m 'chore: initialize commit'"],G),x.gitInitialized=!0}catch(e){}}M(x),p(ge)}catch(e){R(e.message),p(ue)}}}else u();else p(de)}),function(e){return l.apply(this,arguments)}),[a,o,n,D,G,u]),$=(0,t.useCallback)(function(e){"exit"===e.value?d():s()},[d,s]);if(f===ue){var q=[{label:(D.setupGitHubActions?"[x]":"[ ]")+" GitHub Actions workflow",value:"setupGitHubActions"},{label:(D.setupAgents?"[x]":"[ ]")+" AGENTS.md",value:"setupAgents"},{label:(D.setupClaudeCode?"[x]":"[ ]")+" CLAUDE.md",value:"setupClaudeCode"},{label:(D.setupGeminiCLI?"[x]":"[ ]")+" GEMINI.md",value:"setupGeminiCLI"},{label:(D.runBunInstall?"[x]":"[ ]")+" Run bun install after generation",value:"runBunInstall"},{label:(D.initGit?"[x]":"[ ]")+" Initialize git repository",value:"initGit"},{label:"→ Continue",value:"continue"},{label:"← Back",value:"back"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,color:"cyan",children:["Initialize BRICKS Project: ",(null==o?void 0:o.name)||"Untitled"]}),(0,m.jsx)(i.Text,{color:"gray",marginBottom:1,children:"Select options for project generation (press Enter to toggle)"}),C&&(0,m.jsxs)(i.Text,{color:"red",marginBottom:1,children:["Error: ",C]}),(0,m.jsx)(U,{items:q,onSelect:V})]})}if(f===de)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:"Output Directory"}),(0,m.jsx)(i.Text,{color:"gray",marginBottom:1,children:"Enter the parent directory for the project:"}),C&&(0,m.jsx)(i.Text,{color:"red",marginBottom:1,children:C}),(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{children:"Directory: "}),(0,m.jsx)(ee,{value:y,onChange:B,onSubmit:F})]}),(0,m.jsxs)(i.Text,{color:"gray",marginTop:1,children:["Project will be created at: ",G]})]});if(f===xe){return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:"Confirm Project Generation"}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{children:["Name: ",(0,m.jsx)(i.Text,{color:"green",children:(null==o?void 0:o.name)||"Untitled"})]}),(0,m.jsxs)(i.Text,{children:["Type: ",(0,m.jsx)(i.Text,{color:"yellow",children:n})]}),(0,m.jsxs)(i.Text,{children:["Path: ",(0,m.jsx)(i.Text,{color:"cyan",children:G})]}),(0,m.jsx)(i.Text,{color:"gray",marginTop:1,children:"Options:"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - GitHub Actions: ",D.setupGitHubActions?"Yes":"No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - AGENTS.md: ",D.setupAgents?"Yes":"No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - CLAUDE.md: ",D.setupClaudeCode?"Yes":"No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - GEMINI.md: ",D.setupGeminiCLI?"Yes":"No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - Run bun install: ",D.runBunInstall?"Yes":"No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - Initialize git: ",D.initGit?"Yes":"No"]})]}),(0,m.jsx)(U,{items:[{label:"Confirm & Generate",value:"confirm"},{label:"← Change Directory",value:"back"},{label:"Cancel",value:"cancel"}],onSelect:H})]})}if(f===he||f===fe)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:"Generating Project..."}),(0,m.jsxs)(i.Box,{marginY:1,children:[(0,m.jsx)(i.Text,{color:"green",children:(0,m.jsx)(g,{type:"dots"})}),(0,m.jsxs)(i.Text,{children:[" ",w]})]})]});if(f===ge&&P){return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"green",children:"Project initialized successfully!"}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{children:["Path: ",(0,m.jsx)(i.Text,{color:"cyan",children:P.path})]}),(0,m.jsxs)(i.Text,{children:["Files: ",(0,m.jsx)(i.Text,{color:"green",children:P.files})]}),(0,m.jsxs)(i.Text,{children:["Dependencies:"," ",(0,m.jsx)(i.Text,{color:P.bunInstalled?"green":"yellow",children:P.bunInstalled?"Installed":"Not installed (run bun install manually)"})]}),(0,m.jsxs)(i.Text,{children:["Git:"," ",(0,m.jsx)(i.Text,{color:P.gitInitialized?"green":"yellow",children:P.gitInitialized?"Initialized":"Not initialized"})]})]}),(0,m.jsx)(i.Text,{bold:!0,marginY:1,children:"Next steps:"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" cd ",N]}),!P.bunInstalled&&(0,m.jsx)(i.Text,{color:"gray",children:" bun install"}),(0,m.jsx)(i.Text,{color:"gray",children:" bun preview"}),(0,m.jsxs)(i.Text,{color:"gray",marginTop:1,children:["For more information, see ",N,"/README.md"]}),(0,m.jsx)(i.Box,{marginTop:1,children:(0,m.jsx)(U,{items:[{label:"← Back to Detail",value:"back"},{label:"Exit CLI",value:"exit"}],onSelect:$})})]})}return null};const De=function(){var e=(0,i.useApp)().exit,l=(0,t.useState)(d.MAIN),n=c(l,2),o=n[0],x=n[1],h=(0,t.useState)(null),f=c(h,2),g=f[0],j=f[1],b=(0,t.useState)(null),_=c(b,2),y=_[0],B=_[1],S=(0,t.useState)(!0),E=c(S,2),w=E[0],L=E[1],I=(0,t.useState)(null),A=c(I,2),C=A[0],R=A[1],k=(0,t.useState)([]),U=c(k,2),z=U[0],Q=U[1],Z=(0,t.useState)(null),ee=c(Z,2),le=ee[0],ne=ee[1],te=(0,t.useState)([]),oe=c(te,2),re=oe[0],ce=oe[1],ae=(0,t.useState)(null),se=c(ae,2),ue=se[0],de=se[1],xe=(0,t.useState)([]),he=c(xe,2),fe=he[0],ge=he[1],me=(0,t.useState)(null),pe=c(me,2),je=pe[0],De=pe[1],Te=(0,t.useState)([]),be=c(Te,2),_e=be[0],ye=be[1],Be=(0,t.useState)(null),Se=c(Be,2),Ee=Se[0],we=Se[1],Le=(0,t.useState)([]),Ie=c(Le,2),Ae=Ie[0],Ce=Ie[1],Re=(0,t.useState)(!1),ke=c(Re,2),Ue=ke[0],Oe=ke[1],Pe=(0,t.useState)(null),Me=c(Pe,2),Ne=Me[0],Ge=Me[1],Ve=(0,t.useState)(null),Fe=c(Ve,2),He=Fe[0],$e=Fe[1],qe=(0,t.useState)(null),ze=c(qe,2),Ye=ze[0],We=ze[1],Xe=(0,t.useState)(null),Je=c(Xe,2),Ke=Je[0],Qe=Je[1],Ze=(0,t.useState)([]),el=c(Ze,2),ll=el[0],nl=el[1],tl=(0,t.useState)(null),il=c(tl,2),ol=il[0],rl=il[1],cl=(0,t.useState)([]),al=c(cl,2),sl=al[0],ul=al[1],dl=(0,t.useState)(null),xl=c(dl,2),hl=xl[0],fl=xl[1],gl=o===d.DEVICES,ml=o===d.DEVICE_DETAIL,pl=o===d.GROUPS,jl=o===d.GROUP_DETAIL;(0,t.useEffect)(function(){var e=(0,s.getCurrentProfile)(),l=(0,s.getToken)(e);if(!l)return R("Not logged in. Run `bricks auth login` first."),void L(!1);var n=(0,a.createClient)((0,s.getBaseUrl)(),l);j(n),n.workspace().then(function(e){B(e),L(!1)}).catch(function(e){R(e.message),L(!1)})},[]),(0,i.useInput)(function(l,n){"q"===l&&e(),n.escape&&(o===d.DEVICE_CONTROL?(x(d.DEVICE_DETAIL),Ge(null)):o===d.DEVICE_SCREENSHOT?(x(d.DEVICE_DETAIL),We(null),Qe(null)):o===d.DEVICE_DETAIL?(x(d.DEVICES),ne(null)):o===d.APP_DETAIL?(x(d.APPS),de(null)):o===d.MODULE_DETAIL?(x(d.MODULES),De(null)):o===d.GROUP_DETAIL?(x(d.GROUPS),we(null),Ce([])):o===d.MEDIA_FILE_DETAIL?(x(d.MEDIA_FILES),fl(null)):o===d.MEDIA_FILES?(x(d.MEDIA_BOX_DETAIL),fl(null)):o===d.MEDIA_BOX_DETAIL?(x(d.MEDIA_BOXES),rl(null),ul([])):(o===d.MEDIA_BOXES||o!==d.MAIN)&&x(d.MAIN))},{isActive:o!==d.APP_SHORT_EDIT&&o!==d.MODULE_SHORT_EDIT&&o!==d.APP_PROJECT_INIT&&o!==d.MODULE_PROJECT_INIT});var vl,Dl,Tl,bl,_l,yl,Bl,Sl,El=(0,t.useCallback)(r(function*(){if(g){L(!0);try{var e=yield g.devices({});Q(e||[])}catch(e){R(e.message)}L(!1)}}),[g]),wl=(0,t.useCallback)((vl=r(function*(e){if(g){L(!0),$e(null);try{var l=yield g.device({id:e});ne(l)}catch(e){$e(e.message)}L(!1)}}),function(e){return vl.apply(this,arguments)}),[g]),Ll=(0,t.useCallback)(r(function*(){if(g){L(!0);try{var e=yield g.applications({});ce(e||[])}catch(e){R(e.message)}L(!1)}}),[g]),Il=(0,t.useCallback)((Dl=r(function*(e){if(g){L(!0),$e(null);try{var l=yield g.application({id:e});de(l)}catch(e){$e(e.message)}L(!1)}}),function(e){return Dl.apply(this,arguments)}),[g]),Al=(0,t.useCallback)(r(function*(){if(g){L(!0);try{var e=yield g.modules({});ge(e||[])}catch(e){R(e.message)}L(!1)}}),[g]),Cl=(0,t.useCallback)((Tl=r(function*(e){if(g){L(!0),$e(null);try{var l=yield g.module({id:e});De(l)}catch(e){$e(e.message)}L(!1)}}),function(e){return Tl.apply(this,arguments)}),[g]),Rl=(0,t.useCallback)(r(function*(){if(g){L(!0);try{var e=yield g.deviceGroups({});ye(e||[])}catch(e){R(e.message)}L(!1)}}),[g]),kl=(0,t.useCallback)((bl=r(function*(e){if(g){L(!0),$e(null);try{var l=yield Promise.all([g.deviceGroup({id:e}),g.devicesByGroup({id:e})]),n=c(l,2),t=n[0],i=n[1];we(t),Ce(i||[])}catch(e){$e(e.message)}L(!1)}}),function(e){return bl.apply(this,arguments)}),[g]),Ul=(0,t.useCallback)(r(function*(){if(g){L(!0);try{var e=yield g.mediaBoxes();nl(e||[])}catch(e){R(e.message)}L(!1)}}),[g]),Ol=(0,t.useCallback)((_l=r(function*(e){if(g){L(!0),$e(null);try{var l=yield g.mediaBox({id:e});rl(l)}catch(e){$e(e.message)}L(!1)}}),function(e){return _l.apply(this,arguments)}),[g]),Pl=(0,t.useCallback)((yl=r(function*(e){if(g){L(!0);try{var l=yield g.mediaFiles({boxId:e});ul(l||[])}catch(e){R(e.message)}L(!1)}}),function(e){return yl.apply(this,arguments)}),[g]),Ml=(0,t.useCallback)((Bl=r(function*(e){if(g){L(!0),$e(null);try{var l=yield g.mediaFile({id:e});fl(l)}catch(e){$e(e.message)}L(!1)}}),function(e){return Bl.apply(this,arguments)}),[g]),Nl=(0,t.useCallback)((Sl=r(function*(e){if(g&&le){Oe(!0),Ge(null);try{yield g.controlDevice({id:le._id,type:e}),Ge({success:!0,message:`Command sent: ${e}`})}catch(e){Ge({success:!1,message:e.message})}Oe(!1)}}),function(e){return Sl.apply(this,arguments)}),[g,le]),Gl=(0,t.useCallback)(r(function*(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(g&&le&&y){L(!0),Qe(null),We(null);try{e&&(yield g.controlDevice({id:le._id,type:"take-screenshot"}),yield new Promise(function(e){return setTimeout(e,3e3)}));var l=yield(0,u.he)(g,y,le._id,null,{preferThumbnail:!0});l.error?Qe(l.error):We(l)}catch(e){Qe(e.message)}L(!1)}}),[g,le,y]),Vl=p((0,t.useCallback)(function(){g&&El()},[g,El]),gl),Fl=p((0,t.useCallback)(function(){g&&le&&wl(le._id)},[g,le,wl]),ml),Hl=p((0,t.useCallback)(function(){g&&Rl()},[g,Rl]),pl),$l=p((0,t.useCallback)(function(){g&&Ee&&kl(Ee._id)},[g,Ee,kl]),jl);return w&&!y?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(v,{workspace:y,view:o}),(0,m.jsx)(T,{text:"Connecting to workspace..."})]}):C&&!y?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(v,{workspace:y,view:o}),(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",C]}),(0,m.jsx)(D,{})]}):(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(v,{workspace:y,view:o}),o===d.MAIN&&(0,m.jsx)(O,{onSelect:function(l){"exit"!==l.value?(x(l.value),l.value===d.DEVICES?El():l.value===d.APPS?Ll():l.value===d.MODULES?Al():l.value===d.GROUPS?Rl():l.value===d.MEDIA_BOXES&&Ul()):e()},mediaEnabled:(0,u.wR)(y)}),o===d.DEVICES&&(0,m.jsx)(P,{devices:z,loading:w,onSelect:function(e){if("back"!==e.value){if("refresh"===e.value)return El(),void Vl.resetCountdown();ne(null),L(!0),x(d.DEVICE_DETAIL),wl(e.value)}else x(d.MAIN)},countdown:Vl.countdown,lastRefreshTime:Vl.lastRefreshTime}),o===d.DEVICE_DETAIL&&(0,m.jsx)(M,{device:le,loading:w,error:He,onSelect:function(e){return"back"===e.value?(x(d.DEVICES),void ne(null)):"refresh"===e.value?(wl(le._id),void Fl.resetCountdown()):("control"===e.value&&(x(d.DEVICE_CONTROL),Ge(null)),void("screenshot"===e.value&&(x(d.DEVICE_SCREENSHOT),We(null),Qe(null),Gl(!1))))},mediaEnabled:(0,u.wR)(y),countdown:Fl.countdown,lastRefreshTime:Fl.lastRefreshTime}),o===d.DEVICE_CONTROL&&(0,m.jsx)(N,{device:le,onSelect:function(e){if("back"===e.value)return x(d.DEVICE_DETAIL),void Ge(null);Nl(e.value)},controlling:Ue,controlResult:Ne}),o===d.DEVICE_SCREENSHOT&&(0,m.jsx)(G,{device:le,screenshot:Ye,loading:w,error:Ke,onSelect:function(e){if("back"===e.value)return x(d.DEVICE_DETAIL),We(null),void Qe(null);"refresh"!==e.value?"take"===e.value&&Gl(!0):Gl(!1)}}),o===d.APPS&&(0,m.jsx)(V,{apps:re,loading:w,onSelect:function(e){"back"!==e.value?"refresh"!==e.value?(de(null),L(!0),x(d.APP_DETAIL),Il(e.value)):Ll():x(d.MAIN)}}),o===d.APP_DETAIL&&(0,m.jsx)(F,{app:ue,loading:w,error:He,onSelect:function(e){if("back"===e.value)return x(d.APPS),void de(null);"refresh"!==e.value?("short_edit"===e.value&&(x(d.APP_SHORT_EDIT),$e(null)),"project_init"===e.value&&(x(d.APP_PROJECT_INIT),$e(null))):Il(ue._id)}}),o===d.APP_SHORT_EDIT&&(0,m.jsx)(ie,{instanceType:"application",instance:ue,client:g,onDone:r(function*(){return Il(ue._id)}),onCancel:function(){return x(d.APP_DETAIL)}}),o===d.APP_PROJECT_INIT&&(0,m.jsx)(ve,{type:"application",instance:ue,client:g,onDone:function(){return x(d.APP_DETAIL)},onCancel:function(){return x(d.APP_DETAIL)}}),o===d.MODULES&&(0,m.jsx)(H,{modules:fe,loading:w,onSelect:function(e){"back"!==e.value?"refresh"!==e.value?(De(null),L(!0),x(d.MODULE_DETAIL),Cl(e.value)):Al():x(d.MAIN)}}),o===d.MODULE_DETAIL&&(0,m.jsx)($,{module:je,loading:w,error:He,onSelect:function(e){if("back"===e.value)return x(d.MODULES),void De(null);"refresh"!==e.value?("short_edit"===e.value&&(x(d.MODULE_SHORT_EDIT),$e(null)),"project_init"===e.value&&(x(d.MODULE_PROJECT_INIT),$e(null))):Cl(je._id)}}),o===d.MODULE_SHORT_EDIT&&(0,m.jsx)(ie,{instanceType:"module",instance:je,client:g,onDone:r(function*(){return Cl(je._id)}),onCancel:function(){return x(d.MODULE_DETAIL)}}),o===d.MODULE_PROJECT_INIT&&(0,m.jsx)(ve,{type:"module",instance:je,client:g,onDone:function(){return x(d.MODULE_DETAIL)},onCancel:function(){return x(d.MODULE_DETAIL)}}),o===d.GROUPS&&(0,m.jsx)(q,{groups:_e,loading:w,onSelect:function(e){if("back"!==e.value){if("refresh"===e.value)return Rl(),void Hl.resetCountdown();we(null),Ce([]),L(!0),x(d.GROUP_DETAIL),kl(e.value)}else x(d.MAIN)},countdown:Hl.countdown,lastRefreshTime:Hl.lastRefreshTime}),o===d.GROUP_DETAIL&&(0,m.jsx)(Y,{group:Ee,groupDevices:Ae,loading:w,error:He,onSelect:function(e){if("back"===e.value)return x(d.GROUPS),we(null),void Ce([]);"refresh"===e.value&&(kl(Ee._id),$l.resetCountdown())},countdown:$l.countdown,lastRefreshTime:$l.lastRefreshTime}),o===d.MEDIA_BOXES&&(0,m.jsx)(W,{boxes:ll,loading:w,onSelect:function(e){"back"!==e.value?"refresh"!==e.value?(rl(null),ul([]),L(!0),x(d.MEDIA_BOX_DETAIL),Ol(e.value)):Ul():x(d.MAIN)}}),o===d.MEDIA_BOX_DETAIL&&(0,m.jsx)(X,{box:ol,loading:w,error:He,onSelect:function(e){if("back"===e.value)return x(d.MEDIA_BOXES),rl(null),void ul([]);"refresh"!==e.value?"files"===e.value&&(ul([]),fl(null),x(d.MEDIA_FILES),Pl(ol.id)):Ol(ol.id)}}),o===d.MEDIA_FILES&&(0,m.jsx)(J,{files:sl,box:ol,loading:w,onSelect:function(e){if("back"===e.value)return x(d.MEDIA_BOX_DETAIL),void fl(null);"refresh"!==e.value?(fl(null),L(!0),x(d.MEDIA_FILE_DETAIL),Ml(e.value)):Pl(ol.id)}}),o===d.MEDIA_FILE_DETAIL&&(0,m.jsx)(K,{file:hl,loading:w,error:He,onSelect:function(e){if("back"===e.value)return x(d.MEDIA_FILES),void fl(null);"refresh"===e.value&&Ml(hl.id)}}),(0,m.jsx)(D,{})]})};var Te=function(){(0,i.render)((0,m.jsx)(o.TerminalInfoProvider,{children:(0,m.jsx)(De,{})}))}}};