@fugood/bricks-cli 2.24.9 → 2.24.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/779.js CHANGED
@@ -1 +1 @@
1
- export const __webpack_esm_id__=779;export const __webpack_esm_ids__=[779];export const __webpack_esm_modules__={18050:(e,l,r)=>{r.d(l,{BZ:()=>T,KN:()=>j,kU:()=>m,o0:()=>f,oz:()=>p});var t,n,i,o,a=r(99436),s=r(16928),c=r(79896),d=r(35317),x=r(10750),u=e=>{try{return(0,d.execSync)(`which ${e}`,{stdio:"ignore"}),!0}catch{return!1}},h=(e,l,r)=>new Promise((t,n)=>{var i=[e,...l].join(" "),o=(0,d.spawn)(i,[],{cwd:r,stdio:"pipe",shell:!0}),a=[];o.stderr.on("data",e=>a.push(e)),o.on("close",e=>{if(0===e)t();else{var l=Buffer.concat(a).toString().trim();n(new Error(l||`Command failed with code ${e}`))}}),o.on("error",n)}),g=(t=a(function*(e,l){try{var t=(yield Promise.resolve().then(r.bind(r,79491))).format;return(yield t(l,e,{trailingComma:"all",tabWidth:2,semi:!1,singleQuote:!0,printWidth:100})).code}catch{}return e}),function(e,l){return t.apply(this,arguments)}),m=(e=[])=>{var l=e.find(e=>"application.json"===e.name);if(!l)return"bricks-ctor";try{var r=JSON.parse(l.input);return x(r.name||"bricks-ctor")}catch{return"bricks-ctor"}},j=(n=a(function*(e,l){return Promise.all(e.map((r=a(function*(e){var r=s.join(l,e.name),t=e.input;return e.formatable&&(t=yield g(t,r)),{...e,filePath:r,content:t}}),function(e){return r.apply(this,arguments)})));var r}),function(e,l){return n.apply(this,arguments)}),p=e=>{e.forEach(e=>{c.mkdirSync(s.dirname(e.filePath),{recursive:!0}),c.writeFileSync(e.filePath,e.content)})},f=(i=a(function*(e,l={}){var r="function"==typeof l.onStatus?l.onStatus:()=>{},t=!1,n=!1;if(!1!==l.install&&u("bun")){r("Installing dependencies (bun install)...");try{yield h("bun",["install"],e),t=!0}catch{}}if(!1!==l.git&&u("git")){r("Initializing git repository...");try{yield h("git",["init"],e),yield h("git",["add","."],e),yield h("git",["-c 'user.name=BRICKS CLI'","-c 'user.email=cli@bricks.tools'","commit","-m 'chore: initialize commit'"],e),n=!0}catch{}}return{bunInstalled:t,gitInitialized:n}}),function(e){return i.apply(this,arguments)}),T=(o=a(function*(e,l,r){var t=r.client,n=r.output,i=r.outputAsTarget;if(!t)throw new Error("client is required");if(!n)throw new Error("output directory is required");var o=(e=>{for(var l=s.resolve(e);;){if(c.existsSync(s.join(l,"application.json"))||c.existsSync(s.join(l,"module.json")))return l;var r=s.dirname(l);if(r===l)return null;l=r}})(i?s.dirname(s.resolve(n)):n);if(o)throw new Error(`Cannot initialize a new BRICKS project inside an existing project (${o}). Choose a directory outside the project.`);var a="application"===e,d=a?"applicationProject":"moduleProject",x=a?t.queries.applicationProject:t.queries.moduleProject,u=(yield t.query(x,{id:l,buildApplicationOnly:!1,setupGitHubActions:!1!==r.githubActions,setupAgents:!1!==r.agents,setupClaudeCode:!1!==r.claude,setupGeminiCLI:!0===r.gemini}))[d];if(!u?.files)throw new Error(`${e} project not found`);var h=m(u.files),g=i?s.resolve(n):s.resolve(n,h);if(c.existsSync(g))throw new Error(`Directory already exists: ${g}`);c.mkdirSync(g,{recursive:!0});var T=yield j(u.files,g);p(T);var v=yield f(g,r),y=v.bunInstalled,_=v.gitInitialized;return{success:!0,path:g,files:u.files.length,bunInstalled:y,gitInitialized:_}}),function(e,l,r){return o.apply(this,arguments)})},18779:(e,l,r)=>{r.d(l,{App:()=>ne,AppDetail:()=>C,AppList:()=>B,CONTROL_ACTIONS:()=>x,DeviceControl:()=>I,DeviceDetail:()=>E,DeviceList:()=>S,DeviceScreenshot:()=>A,DeviceStatus:()=>v,Footer:()=>f,GroupDetail:()=>O,GroupList:()=>L,Header:()=>p,Loading:()=>T,MainMenu:()=>_,MediaBoxDetail:()=>R,MediaBoxList:()=>M,MediaFileDetail:()=>U,MediaFileList:()=>N,ModuleDetail:()=>k,ModuleList:()=>w,ONLINE_THRESHOLD_MS:()=>u,ProjectInitView:()=>te,ShortEditEditor:()=>Y,VIEWS:()=>d,runInteractiveMode:()=>ae}),r.r(l);var t=r(99436),n=r(51649),i=r(8498),o=r(68832),a=r(50700),s=r(74752),c=r(47336),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",ACTIVITY_LOG:"activity_log"},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"}],u=3e5,h=r(47882),g=r(71178),m=(e,l=!0)=>{var r=Math.floor(60),t=(0,n.useState)(r),i=o(t,2),a=i[0],s=i[1],c=(0,n.useState)(null),d=o(c,2),x=d[0],u=d[1],h=(0,n.useRef)(e);(0,n.useEffect)(()=>{h.current=e},[e]);var g=(0,n.useCallback)(()=>{s(r),u(Date.now())},[r]);return(0,n.useEffect)(()=>{if(l){var e=setInterval(()=>{s(e=>e<=1?(h.current?.(),u(Date.now()),r):e-1)},1e3);return()=>clearInterval(e)}},[l,r]),(0,n.useEffect)(()=>{l&&(s(r),u(Date.now()))},[l,r]),{countdown:a,lastRefreshTime:x,resetCountdown:g}},j=({countdown:e,lastRefreshTime:l})=>(0,g.jsx)(i.Box,{children:(0,g.jsxs)(i.Text,{color:"gray",children:["Next refresh in ",(0,g.jsxs)(i.Text,{color:"cyan",children:[e,"s"]}),l&&(0,g.jsxs)(i.Text,{color:"gray",children:[" (last: ",l?new Date(l).toLocaleTimeString():null,")"]})]})}),p=({workspace:e,view:l})=>(0,g.jsxs)(i.Box,{flexDirection:"column",marginBottom:1,children:[(0,g.jsxs)(i.Box,{children:[(0,g.jsx)(i.Text,{bold:!0,color:"cyan",children:"BRICKS CLI"}),(0,g.jsx)(i.Text,{color:"gray",children:" - Interactive Mode"})]}),(0,g.jsxs)(i.Box,{children:[(0,g.jsx)(i.Text,{color:"gray",children:"Workspace: "}),(0,g.jsx)(i.Text,{color:"green",children:e?.name||"Not connected"}),(0,g.jsx)(i.Text,{color:"gray",children:" | View: "}),(0,g.jsx)(i.Text,{color:"yellow",children:l})]}),(0,g.jsx)(i.Text,{color:"gray",children:"─".repeat(60)})]}),f=()=>(0,g.jsxs)(i.Box,{marginTop:1,flexDirection:"column",children:[(0,g.jsx)(i.Text,{color:"gray",children:"─".repeat(60)}),(0,g.jsxs)(i.Text,{color:"gray",children:["Press ",(0,g.jsx)(i.Text,{color:"cyan",children:"q"})," to quit, ",(0,g.jsx)(i.Text,{color:"cyan",children:"Esc"})," to go back"]})]}),T=({text:e})=>(0,g.jsxs)(i.Box,{children:[(0,g.jsx)(i.Text,{color:"green",children:(0,g.jsx)(h.A,{type:"dots"})}),(0,g.jsxs)(i.Text,{children:[" ",e||"Loading..."]})]}),v=({lastAliveTime:e})=>{if(!e)return(0,g.jsx)(i.Text,{color:"gray",children:"○ Unknown"});var l=Date.now()-new Date(e).getTime();if(l<=u)return(0,g.jsx)(i.Text,{color:"green",children:"● Online"});var r=Math.floor(l/6e4);if(r<60)return(0,g.jsxs)(i.Text,{color:"yellow",children:["○ Offline (",r,"m ago)"]});var t=Math.floor(r/60);if(t<24)return(0,g.jsxs)(i.Text,{color:"red",children:["○ Offline (",t,"h ago)"]});var n=Math.floor(t/24);return(0,g.jsxs)(i.Text,{color:"red",children:["○ Offline (",n,"d ago)"]})},y=r(25291),_=({onSelect:e,mediaEnabled:l,activityLogEnabled:r})=>{var t=[{label:"Devices",value:d.DEVICES},{label:"Applications",value:d.APPS},{label:"Modules",value:d.MODULES},{label:"Device Groups",value:d.GROUPS},...l?[{label:"Media Flow",value:d.MEDIA_BOXES}]:[],...r?[{label:"Activity Log",value:d.ACTIVITY_LOG}]:[],{label:"Exit",value:"exit"}];return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(i.Text,{bold:!0,marginBottom:1,children:"Main Menu"}),(0,g.jsx)(y.Ay,{items:t,onSelect:e})]})},b="1"===process.env.BRICKS_CLI_DISTRIBUTION,D=e=>{var l=(0,n.useState)(null),t=o(l,2),a=t[0],s=t[1];return(0,n.useEffect)(()=>{if(!b){var e=!0;return Promise.resolve().then(r.bind(r,29557)).then(l=>{e&&s(()=>l.default)}).catch(()=>{e&&s(!1)}),()=>{e=!1}}},[]),b||!1===a?(0,g.jsx)(i.Text,{color:"gray",children:"Image preview is not available in this CLI build."}):a?(0,g.jsx)(a,{...e}):(0,g.jsx)(T,{text:"Preparing image preview..."})},S=({devices:e,loading:l,onSelect:r,countdown:t,lastRefreshTime:n})=>{if(l)return(0,g.jsx)(T,{text:"Loading devices..."});if(!e?.length)return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(i.Text,{color:"yellow",children:"No devices found"}),(0,g.jsx)(j,{countdown:t,lastRefreshTime:n})]});var o=[...e.map(e=>({label:`${(e=>{if(!e)return"○ Unknown";var l=Date.now()-new Date(e).getTime();if(l<=u)return"● Online";var r=Math.floor(l/6e4);if(r<60)return`○ ${r}m ago`;var t=Math.floor(r/60);return t<24?`○ ${t}h ago`:`○ ${Math.floor(t/24)}d ago`})(e.entry_detail?.watch_dog_timer?.last_alive_time)} - ${e.name||e.device_name}`,value:e._id,device:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Box,{marginBottom:1,children:[(0,g.jsxs)(i.Text,{bold:!0,children:["Devices (",e.length,")"]}),(0,g.jsx)(i.Text,{color:"gray",children:" - "}),(0,g.jsx)(j,{countdown:t,lastRefreshTime:n})]}),(0,g.jsx)(y.Ay,{items:o,onSelect:r})]})},E=({device:e,loading:l,error:r,onSelect:t,mediaEnabled:n,countdown:o,lastRefreshTime:a})=>{if(l)return(0,g.jsx)(T,{text:"Loading device..."});if(r)return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Text,{color:"red",children:["Error: ",r]}),(0,g.jsx)(y.Ay,{items:[{label:"← Back",value:"back"}],onSelect:t})]});if(!e)return(0,g.jsx)(i.Text,{color:"red",children:"Device not found"});var s=[{label:"Control Device",value:"control"},...n?[{label:"View Screenshot",value:"screenshot"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],c=e.entry_detail,d=c?.screen,x=c?.update,u=c?.local_sync;return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Box,{children:[(0,g.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name||e.device_name}),(0,g.jsx)(i.Text,{color:"gray",children:" - "}),(0,g.jsx)(j,{countdown:o,lastRefreshTime:a})]}),e.description&&(0,g.jsx)(i.Text,{color:"gray",children:e.description}),(0,g.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,g.jsxs)(i.Box,{children:[(0,g.jsx)(i.Text,{color:"gray",children:"Status: "}),(0,g.jsx)(v,{lastAliveTime:c?.watch_dog_timer?.last_alive_time})]}),(0,g.jsxs)(i.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,g.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),c?.application&&(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Application"}),(0,g.jsxs)(i.Text,{color:"gray",children:[" Name: ",c.application.name]}),(0,g.jsxs)(i.Text,{color:"gray",children:[" Mode: ",c.operation_mode||"N/A"]})]}),d&&(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Screen"}),d.resolution&&(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Resolution: ",d.resolution.width,"x",d.resolution.height,d.resolution.scale&&` @${d.resolution.scale}x`]}),d.orientation&&(0,g.jsxs)(i.Text,{color:"gray",children:[" Orientation: ",d.orientation]}),d.touch&&(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Touch:"," ",d.touch.available?`Yes (${d.touch.touch_point} points)`:"No"]})]}),(c?.memory_usage||c?.disk_usage)&&(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"System"}),c.memory_usage&&(0,g.jsxs)(i.Text,{color:"gray",children:[" Memory: ",Math.round(100*c.memory_usage),"%"]}),c.disk_usage&&(0,g.jsxs)(i.Text,{color:"gray",children:[" Disk: ",Math.round(100*c.disk_usage),"%"]})]}),(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Capabilities"}),(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Sound: ",c?.sound?.available?"✓":"✗"," | ","Camera: ",c?.camera?.available?"✓":"✗"," | ","Audio In: ",c?.audio_in?.available?"✓":"✗"]})]}),u&&(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Local Sync"}),(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Role: ",u.is_main?"Main":"Peer",u.peer_count>0&&` | Peers: ${u.peer_count}`,u.mean_latency&&` | Latency: ${u.mean_latency}ms`]})]}),x&&(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Update"}),(0,g.jsxs)(i.Text,{color:x.need_update?"yellow":"gray",children:[" ","Status: ",x.need_update?"⚠ Update available":"✓ Up to date"]}),x.current_version&&(0,g.jsxs)(i.Text,{color:"gray",children:[" Version: ",x.current_version]})]})]}),(0,g.jsx)(y.Ay,{items:s,onSelect:t})]})},I=({device:e,onSelect:l,controlling:r,controlResult:t})=>(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Text,{bold:!0,color:"cyan",children:["Control: ",e?.name||e?.device_name]}),r&&(0,g.jsx)(T,{text:"Sending command..."}),t&&(0,g.jsx)(i.Text,{color:t.success?"green":"red",children:t.message}),(0,g.jsx)(i.Box,{marginTop:1,children:(0,g.jsx)(y.Ay,{items:x,onSelect:l})})]}),A=({device:e,screenshot:l,loading:r,error:t,onSelect:n})=>{var o=l?.file?.meta,a=null!=o?.originalWidth&&null!=o?.originalHeight,s=null!=o?.originalFileSize;return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Text,{bold:!0,color:"cyan",children:["Screenshot: ",e?.name||e?.device_name||"Unknown"]}),r&&(0,g.jsx)(T,{text:"Loading screenshot..."}),t&&(0,g.jsx)(i.Box,{marginY:1,children:(0,g.jsx)(i.Text,{color:"red",children:String(t)})}),!r&&!t&&l&&(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(i.Box,{height:30,children:(0,g.jsx)(D,{src:l.path,width:80,alt:"Device screenshot"})}),(0,g.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Screenshot Details"}),(0,g.jsxs)(i.Box,{marginY:1,children:[(0,g.jsx)(i.Text,{color:"green",children:"Screenshot saved to: "}),(0,g.jsx)(i.Text,{color:"cyan",children:String(l.path||"")})]}),a&&(0,g.jsxs)(i.Text,{color:"gray",children:["Size: ",String(o.originalWidth),"x",String(o.originalHeight)]}),s&&(0,g.jsxs)(i.Text,{color:"gray",children:["File: ",(Number(o.originalFileSize)/1024).toFixed(1)," KB"]}),l.file?.updatedAt&&(0,g.jsxs)(i.Text,{color:"gray",children:["Updated: ",new Date(l.file.updatedAt).toLocaleString()]})]})]}),!r&&!t&&!l&&(0,g.jsx)(i.Box,{marginY:1,children:(0,g.jsx)(i.Text,{color:"yellow",children:"No screenshot available. Try taking a new one."})}),(0,g.jsx)(i.Box,{marginTop:1,children:(0,g.jsx)(y.Ay,{items:[{label:"Take New Screenshot",value:"take"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:n})})]})},B=({apps:e,loading:l,onSelect:r})=>{if(l)return(0,g.jsx)(T,{text:"Loading applications..."});if(!e?.length)return(0,g.jsx)(i.Text,{color:"yellow",children:"No applications found"});var t=[...e.map(e=>({label:`${e.has_unreleased_changes?"●":"○"} ${e.name}`,value:e._id,app:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Applications (",e.length,")"]}),(0,g.jsx)(y.Ay,{items:t,onSelect:r})]})},C=({app:e,loading:l,error:r,onSelect:t})=>{if(l)return(0,g.jsx)(T,{text:"Loading application..."});if(r)return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Text,{color:"red",children:["Error: ",r]}),(0,g.jsx)(y.Ay,{items:[{label:"← Back",value:"back"}],onSelect:t})]});if(!e)return(0,g.jsx)(i.Text,{color:"red",children:"Application not found"});var n=[{label:"⚡ Initialize Project",value:"project_init"},...e.short_edit?.enabled&&e.short_edit.ref_map?[{label:"Short Edit",value:"short_edit"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],o=e.devices?.length||0,a=e.devices?.filter(e=>"online"===e.status)?.length||0;return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name}),e.description&&(0,g.jsx)(i.Text,{color:"gray",children:e.description}),(0,g.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,g.jsxs)(i.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,g.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Version"}),(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Current: ",e.current_version?`v${e.current_version}`:"N/A"]}),(0,g.jsxs)(i.Text,{color:e.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",e.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]}),e.current_version_details&&(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Released: v",e.current_version_details.version||"N/A"]})]}),(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Devices"}),(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Total: ",o,o>0&&` (${a} online)`]})]}),(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Features"}),(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Short Edit: ",e.short_edit?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Canvas Control: ",e.canvas_control?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Device Control: ",e.device_control?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,g.jsxs)(i.Text,{color:e.lock?.enabled?"yellow":"gray",children:[" ","Lock: ",e.lock?.enabled?"🔒 Locked":"🔓 Unlocked"]})]}),(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,g.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,g.jsx)(y.Ay,{items:n,onSelect:t})]})},w=({modules:e,loading:l,onSelect:r})=>{if(l)return(0,g.jsx)(T,{text:"Loading modules..."});var t=[...(e||[]).map(e=>({label:`${e.current_version?"●":"○"} ${e.name}`,value:e._id,module:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Modules (",e?.length||0,")"]}),!e?.length&&(0,g.jsx)(i.Text,{color:"yellow",children:"No modules found"}),(0,g.jsx)(y.Ay,{items:t,onSelect:r})]})},k=({module:e,loading:l,error:r,onSelect:t})=>{if(l)return(0,g.jsx)(T,{text:"Loading module..."});if(r)return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Text,{color:"red",children:["Error: ",r]}),(0,g.jsx)(y.Ay,{items:[{label:"← Back",value:"back"}],onSelect:t})]});if(!e)return(0,g.jsx)(i.Text,{color:"red",children:"Module not found"});var n=[{label:"⚡ Initialize Project",value:"project_init"},...e.short_edit?.enabled&&e.short_edit.ref_map?[{label:"Short Edit",value:"short_edit"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name}),e.description&&(0,g.jsx)(i.Text,{color:"gray",children:e.description}),(0,g.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,g.jsxs)(i.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,g.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Version"}),(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Current: ",e.current_version?`v${e.current_version}`:"N/A"]}),(0,g.jsxs)(i.Text,{color:e.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",e.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]})]}),(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Usage"}),(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Used in: ",e.use_count?.total_count||0," application(s)"]})]}),(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Settings"}),(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Public: ",e.is_public?"✓ Yes":"✗ No"]}),(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Modifiable: ",e.is_allow_modify?"✓ Yes":"✗ No"]}),(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Short Edit: ",e.short_edit?.enabled?"✓ Enabled":"✗ Disabled"]})]}),e.expose_properties?.length>0&&(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Exposed Properties"}),(0,g.jsxs)(i.Text,{color:"gray",children:[" ",e.expose_properties.length," properties exposed"]})]}),(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,g.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,g.jsx)(y.Ay,{items:n,onSelect:t})]})},L=({groups:e,loading:l,onSelect:r,countdown:t,lastRefreshTime:n})=>{if(l)return(0,g.jsx)(T,{text:"Loading device groups..."});var o=[...(e||[]).map(e=>({label:`📁 ${e.name} (${e.devices?.length||0} devices)`,value:e._id,group:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Box,{marginBottom:1,children:[(0,g.jsxs)(i.Text,{bold:!0,children:["Device Groups (",e?.length||0,")"]}),(0,g.jsx)(i.Text,{color:"gray",children:" - "}),(0,g.jsx)(j,{countdown:t,lastRefreshTime:n})]}),!e?.length&&(0,g.jsx)(i.Text,{color:"yellow",children:"No device groups found"}),(0,g.jsx)(y.Ay,{items:o,onSelect:r})]})},P=({loading:e,groupDevices:l})=>e?(0,g.jsx)(T,{text:"Loading devices..."}):l?.length?(0,g.jsxs)(g.Fragment,{children:[l.slice(0,10).map(e=>(0,g.jsxs)(i.Box,{children:[(0,g.jsx)(i.Text,{color:"gray",children:" "}),(0,g.jsx)(v,{lastAliveTime:e.entry_detail?.watch_dog_timer?.last_alive_time}),(0,g.jsxs)(i.Text,{color:"gray",children:[" ",e.name||e.device_name]}),e.device_target_name&&(0,g.jsxs)(i.Text,{color:"gray",dimColor:!0,children:[" ","(",e.device_target_name,")"]})]},e._id)),l.length>10&&(0,g.jsxs)(i.Text,{color:"gray",dimColor:!0,children:[" ","... and ",l.length-10," more"]})]}):(0,g.jsx)(i.Text,{color:"gray",children:" No devices in this group"}),O=({group:e,groupDevices:l,loading:r,error:t,onSelect:n,countdown:o,lastRefreshTime:a})=>{if(r&&!e)return(0,g.jsx)(T,{text:"Loading device group..."});if(t)return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Text,{color:"red",children:["Error: ",t]}),(0,g.jsx)(y.Ay,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,g.jsx)(i.Text,{color:"red",children:"Device group not found"});return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Box,{children:[(0,g.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name}),(0,g.jsx)(i.Text,{color:"gray",children:" - "}),(0,g.jsx)(j,{countdown:o,lastRefreshTime:a})]}),e.description&&(0,g.jsx)(i.Text,{color:"gray",children:e.description}),(0,g.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,g.jsxs)(i.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,g.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsxs)(i.Text,{bold:!0,color:"white",children:["Devices (",e.devices?.length||0,")"]}),(0,g.jsx)(P,{loading:r,groupDevices:l})]}),(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,g.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,g.jsxs)(i.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,g.jsx)(y.Ay,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:n})]})},M=({boxes:e,loading:l,onSelect:r})=>{if(l)return(0,g.jsx)(T,{text:"Loading media boxes..."});if(!e?.length)return(0,g.jsx)(i.Text,{color:"yellow",children:"No media boxes found"});var t=[...e.map(e=>({label:`📦 ${e.name||"Unnamed"}`,value:e.id,box:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Media Boxes (",e.length,")"]}),(0,g.jsx)(y.Ay,{items:t,onSelect:r})]})},R=({box:e,loading:l,error:r,onSelect:t})=>{if(l&&!e)return(0,g.jsx)(T,{text:"Loading media box..."});if(r)return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Text,{color:"red",children:["Error: ",r]}),(0,g.jsx)(y.Ay,{items:[{label:"← Back",value:"back"}],onSelect:t})]});if(!e)return(0,g.jsx)(i.Text,{color:"red",children:"Media box not found"});return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name||"Unnamed"}),e.description&&(0,g.jsx)(i.Text,{color:"gray",children:e.description}),(0,g.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,g.jsxs)(i.Text,{color:"gray",children:["ID: ",e.id]}),e.tags?.length>0&&(0,g.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),null!=e.size&&(0,g.jsxs)(i.Text,{color:"gray",children:["Size: ",e.size]}),e.passcodes?.length>0&&(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsxs)(i.Text,{bold:!0,color:"white",children:["Passcodes (",e.passcodes.length,")"]}),e.passcodes.slice(0,5).map(e=>(0,g.jsxs)(i.Text,{color:"gray",children:[" ",e.name||"Passcode",": ",e.code]},e.id)),e.passcodes.length>5&&(0,g.jsxs)(i.Text,{color:"gray",dimColor:!0,children:[" ","... and ",e.passcodes.length-5," more"]})]}),(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.createdAt&&(0,g.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.createdAt).toLocaleString()]}),e.updatedAt&&(0,g.jsxs)(i.Text,{color:"gray",children:[" Modified: ",new Date(e.updatedAt).toLocaleString()]})]})]}),(0,g.jsx)(y.Ay,{items:[{label:"List Files",value:"files"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:t})]})},N=({files:e,loading:l,onSelect:r,box:t})=>{if(l)return(0,g.jsx)(T,{text:"Loading media files..."});if(!e?.length)return(0,g.jsx)(i.Text,{color:"yellow",children:"No media files found"});var n=[...e.map(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,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Media Files (",e.length,")",t?.name?` - ${t.name}`:""]}),(0,g.jsx)(y.Ay,{items:n,onSelect:r})]})},U=({file:e,loading:l,error:r,onSelect:t})=>{if(l&&!e)return(0,g.jsx)(T,{text:"Loading media file..."});if(r)return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Text,{color:"red",children:["Error: ",r]}),(0,g.jsx)(y.Ay,{items:[{label:"← Back",value:"back"}],onSelect:t})]});if(!e)return(0,g.jsx)(i.Text,{color:"red",children:"Media file not found"});var n=e.meta,o=(0,c.Gu)(e),a=(0,c.Gu)(e,{preferThumbnail:!0}),s=Boolean(a&&a!==o);return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name||"Unnamed"}),e.description&&(0,g.jsx)(i.Text,{color:"gray",children:e.description}),(0,g.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,g.jsxs)(i.Text,{color:"gray",children:["ID: ",e.id]}),(0,g.jsxs)(i.Text,{color:"gray",children:["Box ID: ",e.boxId]}),(0,g.jsxs)(i.Text,{color:"gray",children:["Type: ",e.fileType]}),e.userTags?.length>0&&(0,g.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.userTags.join(", ")]}),null!=n?.originalWidth&&null!=n?.originalHeight&&(0,g.jsxs)(i.Text,{color:"gray",children:["Size: ",n.originalWidth,"x",n.originalHeight]}),null!=n?.originalFileSize&&(0,g.jsxs)(i.Text,{color:"gray",children:["File: ",(Number(n.originalFileSize)/1024).toFixed(1)," KB"]}),o&&(0,g.jsxs)(i.Text,{color:"gray",children:["Original URL: ",o]}),s&&(0,g.jsxs)(i.Text,{color:"gray",children:["Thumbnail URL: ",a]}),(0,g.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,g.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.createdAt&&(0,g.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.createdAt).toLocaleString()]}),e.updatedAt&&(0,g.jsxs)(i.Text,{color:"gray",children:[" Modified: ",new Date(e.updatedAt).toLocaleString()]})]})]}),(0,g.jsx)(y.Ay,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:t})]})},G=r(77146),V=(e,l)=>{if(!e)return"";var r="string"==typeof e?e:JSON.stringify(e);return r.length>l?r.slice(0,l-1)+"…":r},F=({onBack:e})=>{var l=(0,n.useState)([]),r=o(l,2),a=r[0],c=r[1],d=(0,n.useState)(!0),x=o(d,2),u=x[0],h=x[1],m=(0,n.useState)(null),j=o(m,2),p=j[0],f=j[1];(0,n.useEffect)(()=>{var e=(0,s.getCurrentProfile)(),l=(0,s.getToken)(e),r=(0,s.getActivityLogBaseUrl)();if(!l)return f("Not logged in. Run `bricks auth login` first."),void h(!1);if(!r)return f("Activity log URL not configured."),void h(!1);var n,i=(0,G.W)(r,l),o=new Date(Date.now()-36e5).toISOString(),a=(new Date).toISOString(),d=new AbortController;return(n=t(function*(){try{var e=yield i.collectEvents({start_time:o,end_time:a},{limit:50,signal:d.signal});c(e)}catch(e){"AbortError"!==e.name&&f(e.message)}h(!1)}),function(){return n.apply(this,arguments)})(),()=>d.abort()},[]);return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(i.Text,{bold:!0,marginBottom:1,children:"Activity Log (last 1h)"}),u&&(0,g.jsx)(T,{text:"Fetching events..."}),p&&(0,g.jsxs)(i.Text,{color:"red",children:["Error: ",p]}),!u&&!p&&0===a.length&&(0,g.jsx)(i.Text,{color:"yellow",children:"No events found in the last hour"}),!u&&a.length>0&&(0,g.jsxs)(i.Box,{flexDirection:"column",marginBottom:1,children:[(0,g.jsxs)(i.Text,{color:"gray",children:["Timestamp".padEnd(22)," ","Type".padEnd(12)," ","Device".padEnd(14)," ","Event Name".padEnd(24)," Sender"]}),a.map((e,l)=>{return(0,g.jsxs)(i.Text,{children:[(r=e.timestamp,new Date(r).toISOString().replace("T"," ").replace(/\.\d+Z$/,"Z")).padEnd(22)," ",V(e.event_type||"",12).padEnd(12)," ",V(e.device_id||"",14).padEnd(14)," ",V(e.event_name||"",24).padEnd(24)," ",V(e.sender||"",16)]},l);var r}),a.length>=50&&(0,g.jsxs)(i.Text,{color:"yellow",children:["Showing first ",50," events"]})]}),(0,g.jsx)(y.Ay,{items:[{label:"← Back",value:"back"}],onSelect:l=>"back"===l.value&&e()})]})},$=r(29253),H=r(35704),z=["B","C","G","D"],Y=({instanceType:e,instance:l,client:r,onDone:a,onCancel:s})=>{var c=(0,i.useApp)().exit,d=(0,n.useState)("select_ref"),x=o(d,2),u=x[0],h=x[1],m=(0,n.useState)(""),j=o(m,2),p=j[0],f=j[1],v=(0,n.useState)("search"),_=o(v,2),b=_[0],D=_[1],S=(0,n.useState)(null),E=o(S,2),I=E[0],A=E[1],B=(0,n.useState)(null),C=o(B,2),w=C[0],k=C[1],L=(0,n.useState)(""),P=o(L,2),O=P[0],M=P[1],R=(0,n.useState)(""),N=o(R,2),U=N[0],G=N[1],V=(0,n.useState)(null),F=o(V,2),Y=F[0],q=F[1],X=l?.short_edit?.ref_map||{},J=Object.entries(X).filter(([,e])=>e&&!e.hide),K=(0,H.V)(X,{keyword:p,types:z}),W=K.flatMap(e=>[{label:e.label,value:`__header_${e.prefix}__`,isHeader:!0},...e.refs.map(({shortId:e,ref:l})=>({label:`${l.title||e} (${e})`,value:e,ref:l}))]),Z=[...p?[{label:"↻ Clear Search",value:"__clear_search__"}]:[],{label:"← Back",value:"__back__"}],Q=W.length>0?[...W,...Z]:Z,ee=Q.findIndex(e=>!e.isHeader&&!e.value?.startsWith("__"));(0,i.useInput)((e,l)=>{l.tab&&"select_ref"===u?D(e=>"search"===e?"list":"search"):(l.escape&&("select_ref"===u&&s(),"input_path"===u&&h("select_ref"),"input_content"===u&&h("input_path"),"confirm"===u&&h("input_content"),"done"===u&&s()),"q"!==e||("input_path"===u||"input_content"===u)||"select_ref"===u&&"search"===b||c())},{isActive:!0});var le,re=e=>{var l=e.trim();if(""===l)return null;try{return JSON.parse(l)}catch{return l}},te=(le=t(function*(){if(r&&l?._id&&I){h("submitting"),q(null);try{var t={shortId:I,path:O.trim(),content:re(U),forwardDataLink:!0};w?.inner_ref?.pid&&(t.innerRefParentShortId=w.inner_ref.pid),"application"===e?yield r.shortEditApplication({id:l._id,list:[t]}):yield r.shortEditModule({id:l._id,list:[t]}),yield a(),h("done")}catch(e){q(e.message),h("confirm")}}}),function(){return le.apply(this,arguments)});return l?.short_edit?.enabled?0===J.length?(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(i.Text,{color:"yellow",children:"No Short Edit references found."}),(0,g.jsx)(y.Ay,{items:[{label:"← Back",value:"back"}],onSelect:s})]}):"select_ref"===u?(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(i.Text,{bold:!0,children:"Short Edit References"}),(0,g.jsx)(i.Text,{color:"gray",dimColor:!0,children:"Showing: Brick, Canvas, Generator, Data"}),(0,g.jsxs)(i.Box,{marginTop:1,flexDirection:"column",children:[(0,g.jsx)(i.Text,{color:"gray",children:"Search (title or shortId)"}),(0,g.jsx)($.A,{value:p,placeholder:"type to filter, Enter to focus list",onChange:e=>f(e),onSubmit:()=>D("list"),focus:"search"===b}),(0,g.jsx)(i.Text,{color:"gray",dimColor:!0,children:"Press Tab to switch focus"})]}),(0,g.jsxs)(i.Box,{marginTop:1,children:[0===K.length&&(0,g.jsx)(i.Text,{color:"yellow",children:"No references match your search."}),(0,g.jsx)(y.Ay,{items:Q,isFocused:"list"===b,initialIndex:ee>-1?ee:0,indicatorComponent:()=>null,itemComponent:({label:e,isSelected:l,isHeader:r})=>r?(0,g.jsx)(i.Box,{marginTop:1,children:(0,g.jsx)(i.Text,{bold:!0,color:"white",children:e})}):(0,g.jsxs)(i.Text,{color:l?"blue":void 0,children:[l?"❯":" "," ",e]}),onSelect:e=>{if("__back__"!==e.value)return"__clear_search__"===e.value?(f(""),void D("search")):void(e.isHeader||(A(e.value),k(e.ref),h("input_path")));s()}})]})]}):"input_path"===u?(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Text,{children:["Reference:"," ",(0,g.jsxs)(i.Text,{color:"cyan",children:[w?.title||I," (",I,")"]})]}),(0,g.jsx)(i.Text,{marginTop:1,children:"Enter property path (e.g. title, property.backgroundColor)"}),Y&&(0,g.jsxs)(i.Text,{color:"red",children:["Error: ",Y]}),(0,g.jsx)($.A,{value:O,placeholder:"path",onChange:e=>{M(e),Y&&q(null)},onSubmit:e=>{var l=e.trim();l?(M(l),h("input_content")):q("Path is required")},focus:!0})]}):"input_content"===u?(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Text,{children:["Path: ",(0,g.jsx)(i.Text,{color:"cyan",children:O})]}),(0,g.jsx)(i.Text,{marginTop:1,children:"Enter new content (JSON or plain text). Empty to clear."}),Y&&(0,g.jsxs)(i.Text,{color:"red",children:["Error: ",Y]}),(0,g.jsx)($.A,{value:U,placeholder:"content",onChange:e=>{G(e),Y&&q(null)},onSubmit:()=>h("confirm"),focus:!0})]}):"submitting"===u?(0,g.jsx)(T,{text:"Applying short edit..."}):"done"===u?(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(i.Text,{color:"green",children:"Short edit applied successfully."}),(0,g.jsx)(y.Ay,{items:[{label:"Edit another property",value:"again"},{label:"← Back",value:"back"}],onSelect:e=>{"again"===e.value?(h("select_ref"),A(null),k(null),M(""),G(""),q(null)):s()}})]}):(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(i.Text,{bold:!0,marginBottom:1,children:"Confirm Short Edit"}),(0,g.jsxs)(i.Text,{children:["Reference:"," ",(0,g.jsxs)(i.Text,{color:"cyan",children:[w?.title||I," (",I,")"]})]}),(0,g.jsxs)(i.Text,{children:["Path: ",(0,g.jsx)(i.Text,{color:"cyan",children:O})]}),(0,g.jsxs)(i.Text,{children:["Content: ",(0,g.jsx)(i.Text,{color:"cyan",children:U||"<empty>"})]}),Y&&(0,g.jsxs)(i.Text,{color:"red",children:["Error: ",Y]}),(0,g.jsx)(y.Ay,{items:[{label:"Apply",value:"apply"},{label:"Edit Path",value:"edit_path"},{label:"Edit Content",value:"edit_content"},{label:"← Back",value:"back"}],onSelect:e=>{"apply"===e.value&&te(),"edit_path"===e.value&&h("input_path"),"edit_content"===e.value&&h("input_content"),"back"===e.value&&s()}})]}):(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Text,{color:"yellow",children:["Short Edit is not enabled for this ",e,"."]}),(0,g.jsx)(y.Ay,{items:[{label:"← Back",value:"back"}],onSelect:s})]})},q=r(16928),X=r(79896),J=r(10750),K=r(18050),W="options",Z="output_dir",Q="confirm",ee="generating",le="post_install",re="done",te=({type:e,instance:l,client:r,onDone:a,onCancel:s})=>{var c,d=(0,i.useApp)().exit,x=(0,n.useState)(W),u=o(x,2),m=u[0],j=u[1],p=(0,n.useState)({setupGitHubActions:!0,setupAgents:!0,setupClaudeCode:!0,setupGeminiCLI:!1,runBunInstall:!0,initGit:!0}),f=o(p,2),T=f[0],v=f[1],_=(0,n.useState)(process.cwd()),b=o(_,2),D=b[0],S=b[1],E=(0,n.useState)(""),I=o(E,2),A=I[0],B=I[1],C=(0,n.useState)(null),w=o(C,2),k=w[0],L=w[1],P=(0,n.useState)(null),O=o(P,2),M=O[0],R=O[1],N=J(l?.name||"bricks-ctor"),U=q.resolve(D,N),G=(0,n.useCallback)(e=>{"back"!==e.value?"continue"!==e.value?v(l=>({...l,[e.value]:!l[e.value]})):j(Z):s()},[s]),V=(0,n.useCallback)(()=>{X.existsSync(U)?L(`Directory already exists: ${U}`):(L(null),j(Q))},[U]),F=(0,n.useCallback)((c=t(function*(t){if("back"!==t.value)if("cancel"!==t.value){if("confirm"===t.value){j(ee);try{B("Fetching project from BRICKS...");var n="application"===e,i=n?"applicationProject":"moduleProject",o=n?r.queries.applicationProject:r.queries.moduleProject,a=(yield r.query(o,{id:l._id,buildApplicationOnly:!1,setupGitHubActions:T.setupGitHubActions,setupAgents:T.setupAgents,setupClaudeCode:T.setupClaudeCode,setupGeminiCLI:T.setupGeminiCLI}))[i];if(!a?.files)throw new Error("Failed to fetch project files");B("Creating project directory..."),X.mkdirSync(U,{recursive:!0}),B(`Writing ${a.files.length} files...`);var c=yield(0,K.KN)(a.files,U);(0,K.oz)(c),j(le);var d={path:U,files:a.files.length,bunInstalled:!1,gitInitialized:!1};Object.assign(d,yield(0,K.o0)(U,{install:T.runBunInstall,git:T.initGit,onStatus:B})),R(d),j(re)}catch(e){L(e.message),j(W)}}}else s();else j(Z)}),function(e){return c.apply(this,arguments)}),[r,l,e,T,U,s]),H=(0,n.useCallback)(e=>{"exit"===e.value?d():a()},[d,a]);if(m===W){var z=[{label:(T.setupGitHubActions?"[x]":"[ ]")+" GitHub Actions workflow",value:"setupGitHubActions"},{label:(T.setupAgents?"[x]":"[ ]")+" AGENTS.md",value:"setupAgents"},{label:(T.setupClaudeCode?"[x]":"[ ]")+" CLAUDE.md",value:"setupClaudeCode"},{label:(T.setupGeminiCLI?"[x]":"[ ]")+" GEMINI.md",value:"setupGeminiCLI"},{label:(T.runBunInstall?"[x]":"[ ]")+" Run bun install after generation",value:"runBunInstall"},{label:(T.initGit?"[x]":"[ ]")+" Initialize git repository",value:"initGit"},{label:"→ Continue",value:"continue"},{label:"← Back",value:"back"}];return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsxs)(i.Text,{bold:!0,color:"cyan",children:["Initialize BRICKS Project: ",l?.name||"Untitled"]}),(0,g.jsx)(i.Text,{color:"gray",marginBottom:1,children:"Select options for project generation (press Enter to toggle)"}),k&&(0,g.jsxs)(i.Text,{color:"red",marginBottom:1,children:["Error: ",k]}),(0,g.jsx)(y.Ay,{items:z,onSelect:G})]})}if(m===Z)return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(i.Text,{bold:!0,color:"cyan",children:"Output Directory"}),(0,g.jsx)(i.Text,{color:"gray",marginBottom:1,children:"Enter the parent directory for the project:"}),k&&(0,g.jsx)(i.Text,{color:"red",marginBottom:1,children:k}),(0,g.jsxs)(i.Box,{children:[(0,g.jsx)(i.Text,{children:"Directory: "}),(0,g.jsx)($.A,{value:D,onChange:S,onSubmit:V})]}),(0,g.jsxs)(i.Text,{color:"gray",marginTop:1,children:["Project will be created at: ",U]})]});if(m===Q){return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(i.Text,{bold:!0,color:"cyan",children:"Confirm Project Generation"}),(0,g.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,g.jsxs)(i.Text,{children:["Name: ",(0,g.jsx)(i.Text,{color:"green",children:l?.name||"Untitled"})]}),(0,g.jsxs)(i.Text,{children:["Type: ",(0,g.jsx)(i.Text,{color:"yellow",children:e})]}),(0,g.jsxs)(i.Text,{children:["Path: ",(0,g.jsx)(i.Text,{color:"cyan",children:U})]}),(0,g.jsx)(i.Text,{color:"gray",marginTop:1,children:"Options:"}),(0,g.jsxs)(i.Text,{color:"gray",children:[" - GitHub Actions: ",T.setupGitHubActions?"Yes":"No"]}),(0,g.jsxs)(i.Text,{color:"gray",children:[" - AGENTS.md: ",T.setupAgents?"Yes":"No"]}),(0,g.jsxs)(i.Text,{color:"gray",children:[" - CLAUDE.md: ",T.setupClaudeCode?"Yes":"No"]}),(0,g.jsxs)(i.Text,{color:"gray",children:[" - GEMINI.md: ",T.setupGeminiCLI?"Yes":"No"]}),(0,g.jsxs)(i.Text,{color:"gray",children:[" - Run bun install: ",T.runBunInstall?"Yes":"No"]}),(0,g.jsxs)(i.Text,{color:"gray",children:[" - Initialize git: ",T.initGit?"Yes":"No"]})]}),(0,g.jsx)(y.Ay,{items:[{label:"Confirm & Generate",value:"confirm"},{label:"← Change Directory",value:"back"},{label:"Cancel",value:"cancel"}],onSelect:F})]})}if(m===ee||m===le)return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(i.Text,{bold:!0,color:"cyan",children:"Generating Project..."}),(0,g.jsxs)(i.Box,{marginY:1,children:[(0,g.jsx)(i.Text,{color:"green",children:(0,g.jsx)(h.A,{type:"dots"})}),(0,g.jsxs)(i.Text,{children:[" ",A]})]})]});if(m===re&&M){return(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(i.Text,{bold:!0,color:"green",children:"Project initialized successfully!"}),(0,g.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,g.jsxs)(i.Text,{children:["Path: ",(0,g.jsx)(i.Text,{color:"cyan",children:M.path})]}),(0,g.jsxs)(i.Text,{children:["Files: ",(0,g.jsx)(i.Text,{color:"green",children:M.files})]}),(0,g.jsxs)(i.Text,{children:["Dependencies:"," ",(0,g.jsx)(i.Text,{color:M.bunInstalled?"green":"yellow",children:M.bunInstalled?"Installed":"Not installed (run bun install manually)"})]}),(0,g.jsxs)(i.Text,{children:["Git:"," ",(0,g.jsx)(i.Text,{color:M.gitInitialized?"green":"yellow",children:M.gitInitialized?"Initialized":"Not initialized"})]})]}),(0,g.jsx)(i.Text,{bold:!0,marginY:1,children:"Next steps:"}),(0,g.jsxs)(i.Text,{color:"gray",children:[" cd ",N]}),!M.bunInstalled&&(0,g.jsx)(i.Text,{color:"gray",children:" bun install"}),(0,g.jsx)(i.Text,{color:"gray",children:" bun preview"}),(0,g.jsxs)(i.Text,{color:"gray",marginTop:1,children:["For more information, see ",N,"/README.md"]}),(0,g.jsx)(i.Box,{marginTop:1,children:(0,g.jsx)(y.Ay,{items:[{label:"← Back to Detail",value:"back"},{label:"Exit CLI",value:"exit"}],onSelect:H})})]})}return null};const ne=()=>{var e=(0,i.useApp)().exit,l=(0,n.useState)(d.MAIN),r=o(l,2),x=r[0],u=r[1],h=(0,n.useState)(null),j=o(h,2),v=j[0],y=j[1],b=(0,n.useState)(null),D=o(b,2),P=D[0],G=D[1],V=(0,n.useState)(!0),$=o(V,2),H=$[0],z=$[1],q=(0,n.useState)(null),X=o(q,2),J=X[0],K=X[1],W=(0,n.useState)([]),Z=o(W,2),Q=Z[0],ee=Z[1],le=(0,n.useState)(null),re=o(le,2),ne=re[0],ie=re[1],oe=(0,n.useState)([]),ae=o(oe,2),se=ae[0],ce=ae[1],de=(0,n.useState)(null),xe=o(de,2),ue=xe[0],he=xe[1],ge=(0,n.useState)([]),me=o(ge,2),je=me[0],pe=me[1],fe=(0,n.useState)(null),Te=o(fe,2),ve=Te[0],ye=Te[1],_e=(0,n.useState)([]),be=o(_e,2),De=be[0],Se=be[1],Ee=(0,n.useState)(null),Ie=o(Ee,2),Ae=Ie[0],Be=Ie[1],Ce=(0,n.useState)([]),we=o(Ce,2),ke=we[0],Le=we[1],Pe=(0,n.useState)(!1),Oe=o(Pe,2),Me=Oe[0],Re=Oe[1],Ne=(0,n.useState)(null),Ue=o(Ne,2),Ge=Ue[0],Ve=Ue[1],Fe=(0,n.useState)(null),$e=o(Fe,2),He=$e[0],ze=$e[1],Ye=(0,n.useState)(null),qe=o(Ye,2),Xe=qe[0],Je=qe[1],Ke=(0,n.useState)(null),We=o(Ke,2),Ze=We[0],Qe=We[1],el=(0,n.useState)([]),ll=o(el,2),rl=ll[0],tl=ll[1],nl=(0,n.useState)(null),il=o(nl,2),ol=il[0],al=il[1],sl=(0,n.useState)([]),cl=o(sl,2),dl=cl[0],xl=cl[1],ul=(0,n.useState)(null),hl=o(ul,2),gl=hl[0],ml=hl[1],jl=x===d.DEVICES,pl=x===d.DEVICE_DETAIL,fl=x===d.GROUPS,Tl=x===d.GROUP_DETAIL;(0,n.useEffect)(()=>{var e=(0,s.getCurrentProfile)(),l=(0,s.getToken)(e);if(!l)return K("Not logged in. Run `bricks auth login` first."),void z(!1);var r=(0,a.createClient)((0,s.getBaseUrl)(),l);y(r),r.workspace().then(e=>{G(e),z(!1)}).catch(e=>{K(e.message),z(!1)})},[]),(0,i.useInput)((l,r)=>{"q"===l&&e(),r.escape&&(x===d.DEVICE_CONTROL?(u(d.DEVICE_DETAIL),Ve(null)):x===d.DEVICE_SCREENSHOT?(u(d.DEVICE_DETAIL),Je(null),Qe(null)):x===d.DEVICE_DETAIL?(u(d.DEVICES),ie(null)):x===d.APP_DETAIL?(u(d.APPS),he(null)):x===d.MODULE_DETAIL?(u(d.MODULES),ye(null)):x===d.GROUP_DETAIL?(u(d.GROUPS),Be(null),Le([])):x===d.MEDIA_FILE_DETAIL?(u(d.MEDIA_FILES),ml(null)):x===d.MEDIA_FILES?(u(d.MEDIA_BOX_DETAIL),ml(null)):x===d.MEDIA_BOX_DETAIL?(u(d.MEDIA_BOXES),al(null),xl([])):(x===d.MEDIA_BOXES||x!==d.MAIN)&&u(d.MAIN))},{isActive:x!==d.APP_SHORT_EDIT&&x!==d.MODULE_SHORT_EDIT&&x!==d.APP_PROJECT_INIT&&x!==d.MODULE_PROJECT_INIT});var vl,yl,_l,bl,Dl,Sl,El,Il,Al=(0,n.useCallback)(t(function*(){if(v){z(!0);try{var e=yield v.devices({});ee(e||[])}catch(e){K(e.message)}z(!1)}}),[v]),Bl=(0,n.useCallback)((vl=t(function*(e){if(v){z(!0),ze(null);try{var l=yield v.device({id:e});ie(l)}catch(e){ze(e.message)}z(!1)}}),function(e){return vl.apply(this,arguments)}),[v]),Cl=(0,n.useCallback)(t(function*(){if(v){z(!0);try{var e=yield v.applications({});ce(e||[])}catch(e){K(e.message)}z(!1)}}),[v]),wl=(0,n.useCallback)((yl=t(function*(e){if(v){z(!0),ze(null);try{var l=yield v.application({id:e});he(l)}catch(e){ze(e.message)}z(!1)}}),function(e){return yl.apply(this,arguments)}),[v]),kl=(0,n.useCallback)(t(function*(){if(v){z(!0);try{var e=yield v.modules({});pe(e||[])}catch(e){K(e.message)}z(!1)}}),[v]),Ll=(0,n.useCallback)((_l=t(function*(e){if(v){z(!0),ze(null);try{var l=yield v.module({id:e});ye(l)}catch(e){ze(e.message)}z(!1)}}),function(e){return _l.apply(this,arguments)}),[v]),Pl=(0,n.useCallback)(t(function*(){if(v){z(!0);try{var e=yield v.deviceGroups({});Se(e||[])}catch(e){K(e.message)}z(!1)}}),[v]),Ol=(0,n.useCallback)((bl=t(function*(e){if(v){z(!0),ze(null);try{var l=yield Promise.all([v.deviceGroup({id:e}),v.devicesByGroup({id:e})]),r=o(l,2),t=r[0],n=r[1];Be(t),Le(n||[])}catch(e){ze(e.message)}z(!1)}}),function(e){return bl.apply(this,arguments)}),[v]),Ml=(0,n.useCallback)(t(function*(){if(v){z(!0);try{var e=yield v.mediaBoxes();tl(e||[])}catch(e){K(e.message)}z(!1)}}),[v]),Rl=(0,n.useCallback)((Dl=t(function*(e){if(v){z(!0),ze(null);try{var l=yield v.mediaBox({id:e});al(l)}catch(e){ze(e.message)}z(!1)}}),function(e){return Dl.apply(this,arguments)}),[v]),Nl=(0,n.useCallback)((Sl=t(function*(e){if(v){z(!0);try{var l=yield v.mediaFiles({boxId:e});xl(l||[])}catch(e){K(e.message)}z(!1)}}),function(e){return Sl.apply(this,arguments)}),[v]),Ul=(0,n.useCallback)((El=t(function*(e){if(v){z(!0),ze(null);try{var l=yield v.mediaFile({id:e});ml(l)}catch(e){ze(e.message)}z(!1)}}),function(e){return El.apply(this,arguments)}),[v]),Gl=(0,n.useCallback)((Il=t(function*(e){if(v&&ne){Re(!0),Ve(null);try{yield v.controlDevice({id:ne._id,type:e}),Ve({success:!0,message:`Command sent: ${e}`})}catch(e){Ve({success:!1,message:e.message})}Re(!1)}}),function(e){return Il.apply(this,arguments)}),[v,ne]),Vl=(0,n.useCallback)(t(function*(e=!1){if(v&&ne&&P){z(!0),Qe(null),Je(null);try{e&&(yield v.controlDevice({id:ne._id,type:"take-screenshot"}),yield new Promise(e=>setTimeout(e,3e3)));var l=yield(0,c.he)(v,P,ne._id,null,{preferThumbnail:!0});l.error?Qe(l.error):Je(l)}catch(e){Qe(e.message)}z(!1)}}),[v,ne,P]),Fl=m((0,n.useCallback)(()=>{v&&Al()},[v,Al]),jl),$l=m((0,n.useCallback)(()=>{v&&ne&&Bl(ne._id)},[v,ne,Bl]),pl),Hl=m((0,n.useCallback)(()=>{v&&Pl()},[v,Pl]),fl),zl=m((0,n.useCallback)(()=>{v&&Ae&&Ol(Ae._id)},[v,Ae,Ol]),Tl);return H&&!P?(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(p,{workspace:P,view:x}),(0,g.jsx)(T,{text:"Connecting to workspace..."})]}):J&&!P?(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(p,{workspace:P,view:x}),(0,g.jsxs)(i.Text,{color:"red",children:["Error: ",J]}),(0,g.jsx)(f,{})]}):(0,g.jsxs)(i.Box,{flexDirection:"column",children:[(0,g.jsx)(p,{workspace:P,view:x}),x===d.MAIN&&(0,g.jsx)(_,{onSelect:l=>{"exit"!==l.value?(u(l.value),l.value===d.DEVICES?Al():l.value===d.APPS?Cl():l.value===d.MODULES?kl():l.value===d.GROUPS?Pl():l.value===d.MEDIA_BOXES&&Ml()):e()},mediaEnabled:(0,c.wR)(P),activityLogEnabled:!!(0,s.getActivityLogBaseUrl)()}),x===d.DEVICES&&(0,g.jsx)(S,{devices:Q,loading:H,onSelect:e=>{if("back"!==e.value){if("refresh"===e.value)return Al(),void Fl.resetCountdown();ie(null),z(!0),u(d.DEVICE_DETAIL),Bl(e.value)}else u(d.MAIN)},countdown:Fl.countdown,lastRefreshTime:Fl.lastRefreshTime}),x===d.DEVICE_DETAIL&&(0,g.jsx)(E,{device:ne,loading:H,error:He,onSelect:e=>"back"===e.value?(u(d.DEVICES),void ie(null)):"refresh"===e.value?(Bl(ne._id),void $l.resetCountdown()):("control"===e.value&&(u(d.DEVICE_CONTROL),Ve(null)),void("screenshot"===e.value&&(u(d.DEVICE_SCREENSHOT),Je(null),Qe(null),Vl(!1)))),mediaEnabled:(0,c.wR)(P),countdown:$l.countdown,lastRefreshTime:$l.lastRefreshTime}),x===d.DEVICE_CONTROL&&(0,g.jsx)(I,{device:ne,onSelect:e=>{if("back"===e.value)return u(d.DEVICE_DETAIL),void Ve(null);Gl(e.value)},controlling:Me,controlResult:Ge}),x===d.DEVICE_SCREENSHOT&&(0,g.jsx)(A,{device:ne,screenshot:Xe,loading:H,error:Ze,onSelect:e=>{if("back"===e.value)return u(d.DEVICE_DETAIL),Je(null),void Qe(null);"refresh"!==e.value?"take"===e.value&&Vl(!0):Vl(!1)}}),x===d.APPS&&(0,g.jsx)(B,{apps:se,loading:H,onSelect:e=>{"back"!==e.value?"refresh"!==e.value?(he(null),z(!0),u(d.APP_DETAIL),wl(e.value)):Cl():u(d.MAIN)}}),x===d.APP_DETAIL&&(0,g.jsx)(C,{app:ue,loading:H,error:He,onSelect:e=>{if("back"===e.value)return u(d.APPS),void he(null);"refresh"!==e.value?("short_edit"===e.value&&(u(d.APP_SHORT_EDIT),ze(null)),"project_init"===e.value&&(u(d.APP_PROJECT_INIT),ze(null))):wl(ue._id)}}),x===d.APP_SHORT_EDIT&&(0,g.jsx)(Y,{instanceType:"application",instance:ue,client:v,onDone:t(function*(){return wl(ue._id)}),onCancel:()=>u(d.APP_DETAIL)}),x===d.APP_PROJECT_INIT&&(0,g.jsx)(te,{type:"application",instance:ue,client:v,onDone:()=>u(d.APP_DETAIL),onCancel:()=>u(d.APP_DETAIL)}),x===d.MODULES&&(0,g.jsx)(w,{modules:je,loading:H,onSelect:e=>{"back"!==e.value?"refresh"!==e.value?(ye(null),z(!0),u(d.MODULE_DETAIL),Ll(e.value)):kl():u(d.MAIN)}}),x===d.MODULE_DETAIL&&(0,g.jsx)(k,{module:ve,loading:H,error:He,onSelect:e=>{if("back"===e.value)return u(d.MODULES),void ye(null);"refresh"!==e.value?("short_edit"===e.value&&(u(d.MODULE_SHORT_EDIT),ze(null)),"project_init"===e.value&&(u(d.MODULE_PROJECT_INIT),ze(null))):Ll(ve._id)}}),x===d.MODULE_SHORT_EDIT&&(0,g.jsx)(Y,{instanceType:"module",instance:ve,client:v,onDone:t(function*(){return Ll(ve._id)}),onCancel:()=>u(d.MODULE_DETAIL)}),x===d.MODULE_PROJECT_INIT&&(0,g.jsx)(te,{type:"module",instance:ve,client:v,onDone:()=>u(d.MODULE_DETAIL),onCancel:()=>u(d.MODULE_DETAIL)}),x===d.GROUPS&&(0,g.jsx)(L,{groups:De,loading:H,onSelect:e=>{if("back"!==e.value){if("refresh"===e.value)return Pl(),void Hl.resetCountdown();Be(null),Le([]),z(!0),u(d.GROUP_DETAIL),Ol(e.value)}else u(d.MAIN)},countdown:Hl.countdown,lastRefreshTime:Hl.lastRefreshTime}),x===d.GROUP_DETAIL&&(0,g.jsx)(O,{group:Ae,groupDevices:ke,loading:H,error:He,onSelect:e=>{if("back"===e.value)return u(d.GROUPS),Be(null),void Le([]);"refresh"===e.value&&(Ol(Ae._id),zl.resetCountdown())},countdown:zl.countdown,lastRefreshTime:zl.lastRefreshTime}),x===d.ACTIVITY_LOG&&(0,g.jsx)(F,{onBack:()=>u(d.MAIN)}),x===d.MEDIA_BOXES&&(0,g.jsx)(M,{boxes:rl,loading:H,onSelect:e=>{"back"!==e.value?"refresh"!==e.value?(al(null),xl([]),z(!0),u(d.MEDIA_BOX_DETAIL),Rl(e.value)):Ml():u(d.MAIN)}}),x===d.MEDIA_BOX_DETAIL&&(0,g.jsx)(R,{box:ol,loading:H,error:He,onSelect:e=>{if("back"===e.value)return u(d.MEDIA_BOXES),al(null),void xl([]);"refresh"!==e.value?"files"===e.value&&(xl([]),ml(null),u(d.MEDIA_FILES),Nl(ol.id)):Rl(ol.id)}}),x===d.MEDIA_FILES&&(0,g.jsx)(N,{files:dl,box:ol,loading:H,onSelect:e=>{if("back"===e.value)return u(d.MEDIA_BOX_DETAIL),void ml(null);"refresh"!==e.value?(ml(null),z(!0),u(d.MEDIA_FILE_DETAIL),Ul(e.value)):Nl(ol.id)}}),x===d.MEDIA_FILE_DETAIL&&(0,g.jsx)(U,{file:gl,loading:H,error:He,onSelect:e=>{if("back"===e.value)return u(d.MEDIA_FILES),void ml(null);"refresh"===e.value&&Ul(gl.id)}}),(0,g.jsx)(f,{})]})};var ie,oe="1"===process.env.BRICKS_CLI_DISTRIBUTION,ae=(ie=t(function*(){if(oe)(0,i.render)((0,g.jsx)(ne,{}));else{var e=(yield Promise.resolve().then(r.bind(r,29557))).TerminalInfoProvider;(0,i.render)((0,g.jsx)(e,{children:(0,g.jsx)(ne,{})}))}}),function(){return ie.apply(this,arguments)})}};
1
+ export const __webpack_esm_id__=779;export const __webpack_esm_ids__=[336,779];export const __webpack_esm_modules__={18050:(e,r,t)=>{t.d(r,{BZ:()=>j,KN:()=>g,kU:()=>m,o0:()=>v,oz:()=>p});var l,n,i,o,a=t(99436),s=t(16928),c=t(79896),d=t(35317),u=t(10750),x=e=>{try{return(0,d.execSync)(`which ${e}`,{stdio:"ignore"}),!0}catch{return!1}},h=(e,r,t)=>new Promise((l,n)=>{var i=[e,...r].join(" "),o=(0,d.spawn)(i,[],{cwd:t,stdio:"pipe",shell:!0}),a=[];o.stderr.on("data",e=>a.push(e)),o.on("close",e=>{if(0===e)l();else{var r=Buffer.concat(a).toString().trim();n(new Error(r||`Command failed with code ${e}`))}}),o.on("error",n)}),f=(l=a(function*(e,r){try{var l=(yield Promise.resolve().then(t.bind(t,79491))).format;return(yield l(r,e,{trailingComma:"all",tabWidth:2,semi:!1,singleQuote:!0,printWidth:100})).code}catch{}return e}),function(e,r){return l.apply(this,arguments)}),m=(e=[])=>{var r=e.find(e=>"application.json"===e.name);if(!r)return"bricks-ctor";try{var t=JSON.parse(r.input);return u(t.name||"bricks-ctor")}catch{return"bricks-ctor"}},g=(n=a(function*(e,r){return Promise.all(e.map((t=a(function*(e){var t=s.join(r,e.name),l=e.input;return e.formatable&&(l=yield f(l,t)),{...e,filePath:t,content:l}}),function(e){return t.apply(this,arguments)})));var t}),function(e,r){return n.apply(this,arguments)}),p=e=>{e.forEach(e=>{c.mkdirSync(s.dirname(e.filePath),{recursive:!0}),c.writeFileSync(e.filePath,e.content)})},v=(i=a(function*(e,r={}){var t="function"==typeof r.onStatus?r.onStatus:()=>{},l=!1,n=!1;if(!1!==r.install&&x("bun")){t("Installing dependencies (bun install)...");try{yield h("bun",["install"],e),l=!0}catch{}}if(!1!==r.git&&x("git")){t("Initializing git repository...");try{yield h("git",["init"],e),yield h("git",["add","."],e),yield h("git",["-c 'user.name=BRICKS CLI'","-c 'user.email=cli@bricks.tools'","commit","-m 'chore: initialize commit'"],e),n=!0}catch{}}return{bunInstalled:l,gitInitialized:n}}),function(e){return i.apply(this,arguments)}),j=(o=a(function*(e,r,t){var l=t.client,n=t.output,i=t.outputAsTarget;if(!l)throw new Error("client is required");if(!n)throw new Error("output directory is required");var o=(e=>{for(var r=s.resolve(e);;){if(c.existsSync(s.join(r,"application.json"))||c.existsSync(s.join(r,"module.json")))return r;var t=s.dirname(r);if(t===r)return null;r=t}})(i?s.dirname(s.resolve(n)):n);if(o)throw new Error(`Cannot initialize a new BRICKS project inside an existing project (${o}). Choose a directory outside the project.`);var a="application"===e?l.applicationProject:l.moduleProject,d=yield a({id:r,buildApplicationOnly:!1,setupGitHubActions:!1!==t.githubActions,setupAgents:!1!==t.agents,setupClaudeCode:!1!==t.claude,setupGeminiCLI:!0===t.gemini});if(!d?.files)throw new Error(`${e} project not found`);var u=m(d.files),x=i?s.resolve(n):s.resolve(n,u);if(c.existsSync(x))throw new Error(`Directory already exists: ${x}`);c.mkdirSync(x,{recursive:!0});var h=yield g(d.files,x);p(h);var f=yield v(x,t),j=f.bunInstalled,y=f.gitInitialized;return{success:!0,path:x,files:d.files.length,bunInstalled:j,gitInitialized:y}}),function(e,r,t){return o.apply(this,arguments)})},18779:(e,r,t)=>{t.d(r,{App:()=>ne,AppDetail:()=>B,AppList:()=>w,CONTROL_ACTIONS:()=>u,DeviceControl:()=>I,DeviceDetail:()=>E,DeviceList:()=>D,DeviceScreenshot:()=>A,DeviceStatus:()=>y,Footer:()=>v,GroupDetail:()=>P,GroupList:()=>L,Header:()=>p,Loading:()=>j,MainMenu:()=>b,MediaBoxDetail:()=>R,MediaBoxList:()=>M,MediaFileDetail:()=>U,MediaFileList:()=>N,ModuleDetail:()=>k,ModuleList:()=>C,ONLINE_THRESHOLD_MS:()=>x,ProjectInitView:()=>le,ShortEditEditor:()=>Y,VIEWS:()=>d,runInteractiveMode:()=>ae}),t.r(r);var l=t(99436),n=t(51649),i=t(8498),o=t(68832),a=t(50700),s=t(74752),c=t(47336),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",ACTIVITY_LOG:"activity_log"},u=[{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"}],x=3e5,h=t(47882),f=t(71178),m=(e,r=!0)=>{var t=Math.floor(60),l=(0,n.useState)(t),i=o(l,2),a=i[0],s=i[1],c=(0,n.useState)(null),d=o(c,2),u=d[0],x=d[1],h=(0,n.useRef)(e);(0,n.useEffect)(()=>{h.current=e},[e]);var f=(0,n.useCallback)(()=>{s(t),x(Date.now())},[t]);return(0,n.useEffect)(()=>{if(r){var e=setInterval(()=>{s(e=>e<=1?(h.current?.(),x(Date.now()),t):e-1)},1e3);return()=>clearInterval(e)}},[r,t]),(0,n.useEffect)(()=>{r&&(s(t),x(Date.now()))},[r,t]),{countdown:a,lastRefreshTime:u,resetCountdown:f}},g=({countdown:e,lastRefreshTime:r})=>(0,f.jsx)(i.Box,{children:(0,f.jsxs)(i.Text,{color:"gray",children:["Next refresh in ",(0,f.jsxs)(i.Text,{color:"cyan",children:[e,"s"]}),r&&(0,f.jsxs)(i.Text,{color:"gray",children:[" (last: ",r?new Date(r).toLocaleTimeString():null,")"]})]})}),p=({workspace:e,view:r})=>(0,f.jsxs)(i.Box,{flexDirection:"column",marginBottom:1,children:[(0,f.jsxs)(i.Box,{children:[(0,f.jsx)(i.Text,{bold:!0,color:"cyan",children:"BRICKS CLI"}),(0,f.jsx)(i.Text,{color:"gray",children:" - Interactive Mode"})]}),(0,f.jsxs)(i.Box,{children:[(0,f.jsx)(i.Text,{color:"gray",children:"Workspace: "}),(0,f.jsx)(i.Text,{color:"green",children:e?.name||"Not connected"}),(0,f.jsx)(i.Text,{color:"gray",children:" | View: "}),(0,f.jsx)(i.Text,{color:"yellow",children:r})]}),(0,f.jsx)(i.Text,{color:"gray",children:"─".repeat(60)})]}),v=()=>(0,f.jsxs)(i.Box,{marginTop:1,flexDirection:"column",children:[(0,f.jsx)(i.Text,{color:"gray",children:"─".repeat(60)}),(0,f.jsxs)(i.Text,{color:"gray",children:["Press ",(0,f.jsx)(i.Text,{color:"cyan",children:"q"})," to quit, ",(0,f.jsx)(i.Text,{color:"cyan",children:"Esc"})," to go back"]})]}),j=({text:e})=>(0,f.jsxs)(i.Box,{children:[(0,f.jsx)(i.Text,{color:"green",children:(0,f.jsx)(h.A,{type:"dots"})}),(0,f.jsxs)(i.Text,{children:[" ",e||"Loading..."]})]}),y=({lastAliveTime:e})=>{if(!e)return(0,f.jsx)(i.Text,{color:"gray",children:"○ Unknown"});var r=Date.now()-new Date(e).getTime();if(r<=x)return(0,f.jsx)(i.Text,{color:"green",children:"● Online"});var t=Math.floor(r/6e4);if(t<60)return(0,f.jsxs)(i.Text,{color:"yellow",children:["○ Offline (",t,"m ago)"]});var l=Math.floor(t/60);if(l<24)return(0,f.jsxs)(i.Text,{color:"red",children:["○ Offline (",l,"h ago)"]});var n=Math.floor(l/24);return(0,f.jsxs)(i.Text,{color:"red",children:["○ Offline (",n,"d ago)"]})},T=t(25291),b=({onSelect:e,mediaEnabled:r,activityLogEnabled:t})=>{var l=[{label:"Devices",value:d.DEVICES},{label:"Applications",value:d.APPS},{label:"Modules",value:d.MODULES},{label:"Device Groups",value:d.GROUPS},...r?[{label:"Media Flow",value:d.MEDIA_BOXES}]:[],...t?[{label:"Activity Log",value:d.ACTIVITY_LOG}]:[],{label:"Exit",value:"exit"}];return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(i.Text,{bold:!0,marginBottom:1,children:"Main Menu"}),(0,f.jsx)(T.Ay,{items:l,onSelect:e})]})},_="1"===process.env.BRICKS_CLI_DISTRIBUTION,S=e=>{var r=(0,n.useState)(null),l=o(r,2),a=l[0],s=l[1];return(0,n.useEffect)(()=>{if(!_){var e=!0;return Promise.resolve().then(t.bind(t,29557)).then(r=>{e&&s(()=>r.default)}).catch(()=>{e&&s(!1)}),()=>{e=!1}}},[]),_||!1===a?(0,f.jsx)(i.Text,{color:"gray",children:"Image preview is not available in this CLI build."}):a?(0,f.jsx)(a,{...e}):(0,f.jsx)(j,{text:"Preparing image preview..."})},D=({devices:e,loading:r,onSelect:t,countdown:l,lastRefreshTime:n})=>{if(r)return(0,f.jsx)(j,{text:"Loading devices..."});if(!e?.length)return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(i.Text,{color:"yellow",children:"No devices found"}),(0,f.jsx)(g,{countdown:l,lastRefreshTime:n})]});var o=[...e.map(e=>({label:`${(e=>{if(!e)return"○ Unknown";var r=Date.now()-new Date(e).getTime();if(r<=x)return"● Online";var t=Math.floor(r/6e4);if(t<60)return`○ ${t}m ago`;var l=Math.floor(t/60);return l<24?`○ ${l}h ago`:`○ ${Math.floor(l/24)}d ago`})(e.entry_detail?.watch_dog_timer?.last_alive_time)} - ${e.name||e.device_name}`,value:e._id,device:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Box,{marginBottom:1,children:[(0,f.jsxs)(i.Text,{bold:!0,children:["Devices (",e.length,")"]}),(0,f.jsx)(i.Text,{color:"gray",children:" - "}),(0,f.jsx)(g,{countdown:l,lastRefreshTime:n})]}),(0,f.jsx)(T.Ay,{items:o,onSelect:t})]})},E=({device:e,loading:r,error:t,onSelect:l,mediaEnabled:n,countdown:o,lastRefreshTime:a})=>{if(r)return(0,f.jsx)(j,{text:"Loading device..."});if(t)return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Text,{color:"red",children:["Error: ",t]}),(0,f.jsx)(T.Ay,{items:[{label:"← Back",value:"back"}],onSelect:l})]});if(!e)return(0,f.jsx)(i.Text,{color:"red",children:"Device not found"});var s=[{label:"Control Device",value:"control"},...n?[{label:"View Screenshot",value:"screenshot"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],c=e.entry_detail,d=c?.screen,u=c?.update,x=c?.local_sync;return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Box,{children:[(0,f.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name||e.device_name}),(0,f.jsx)(i.Text,{color:"gray",children:" - "}),(0,f.jsx)(g,{countdown:o,lastRefreshTime:a})]}),e.description&&(0,f.jsx)(i.Text,{color:"gray",children:e.description}),(0,f.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,f.jsxs)(i.Box,{children:[(0,f.jsx)(i.Text,{color:"gray",children:"Status: "}),(0,f.jsx)(y,{lastAliveTime:c?.watch_dog_timer?.last_alive_time})]}),(0,f.jsxs)(i.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,f.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),c?.application&&(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Application"}),(0,f.jsxs)(i.Text,{color:"gray",children:[" Name: ",c.application.name]}),(0,f.jsxs)(i.Text,{color:"gray",children:[" Mode: ",c.operation_mode||"N/A"]})]}),d&&(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Screen"}),d.resolution&&(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Resolution: ",d.resolution.width,"x",d.resolution.height,d.resolution.scale&&` @${d.resolution.scale}x`]}),d.orientation&&(0,f.jsxs)(i.Text,{color:"gray",children:[" Orientation: ",d.orientation]}),d.touch&&(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Touch:"," ",d.touch.available?`Yes (${d.touch.touch_point} points)`:"No"]})]}),(c?.memory_usage||c?.disk_usage)&&(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"System"}),c.memory_usage&&(0,f.jsxs)(i.Text,{color:"gray",children:[" Memory: ",Math.round(100*c.memory_usage),"%"]}),c.disk_usage&&(0,f.jsxs)(i.Text,{color:"gray",children:[" Disk: ",Math.round(100*c.disk_usage),"%"]})]}),(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Capabilities"}),(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Sound: ",c?.sound?.available?"✓":"✗"," | ","Camera: ",c?.camera?.available?"✓":"✗"," | ","Audio In: ",c?.audio_in?.available?"✓":"✗"]})]}),x&&(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Local Sync"}),(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Role: ",x.is_main?"Main":"Peer",x.peer_count>0&&` | Peers: ${x.peer_count}`,x.mean_latency&&` | Latency: ${x.mean_latency}ms`]})]}),u&&(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Update"}),(0,f.jsxs)(i.Text,{color:u.need_update?"yellow":"gray",children:[" ","Status: ",u.need_update?"⚠ Update available":"✓ Up to date"]}),u.current_version&&(0,f.jsxs)(i.Text,{color:"gray",children:[" Version: ",u.current_version]})]})]}),(0,f.jsx)(T.Ay,{items:s,onSelect:l})]})},I=({device:e,onSelect:r,controlling:t,controlResult:l})=>(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Text,{bold:!0,color:"cyan",children:["Control: ",e?.name||e?.device_name]}),t&&(0,f.jsx)(j,{text:"Sending command..."}),l&&(0,f.jsx)(i.Text,{color:l.success?"green":"red",children:l.message}),(0,f.jsx)(i.Box,{marginTop:1,children:(0,f.jsx)(T.Ay,{items:u,onSelect:r})})]}),A=({device:e,screenshot:r,loading:t,error:l,onSelect:n})=>{var o=r?.file?.meta,a=null!=o?.originalWidth&&null!=o?.originalHeight,s=null!=o?.originalFileSize;return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Text,{bold:!0,color:"cyan",children:["Screenshot: ",e?.name||e?.device_name||"Unknown"]}),t&&(0,f.jsx)(j,{text:"Loading screenshot..."}),l&&(0,f.jsx)(i.Box,{marginY:1,children:(0,f.jsx)(i.Text,{color:"red",children:String(l)})}),!t&&!l&&r&&(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(i.Box,{height:30,children:(0,f.jsx)(S,{src:r.path,width:80,alt:"Device screenshot"})}),(0,f.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Screenshot Details"}),(0,f.jsxs)(i.Box,{marginY:1,children:[(0,f.jsx)(i.Text,{color:"green",children:"Screenshot saved to: "}),(0,f.jsx)(i.Text,{color:"cyan",children:String(r.path||"")})]}),a&&(0,f.jsxs)(i.Text,{color:"gray",children:["Size: ",String(o.originalWidth),"x",String(o.originalHeight)]}),s&&(0,f.jsxs)(i.Text,{color:"gray",children:["File: ",(Number(o.originalFileSize)/1024).toFixed(1)," KB"]}),r.file?.updatedAt&&(0,f.jsxs)(i.Text,{color:"gray",children:["Updated: ",new Date(r.file.updatedAt).toLocaleString()]})]})]}),!t&&!l&&!r&&(0,f.jsx)(i.Box,{marginY:1,children:(0,f.jsx)(i.Text,{color:"yellow",children:"No screenshot available. Try taking a new one."})}),(0,f.jsx)(i.Box,{marginTop:1,children:(0,f.jsx)(T.Ay,{items:[{label:"Take New Screenshot",value:"take"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:n})})]})},w=({apps:e,loading:r,onSelect:t})=>{if(r)return(0,f.jsx)(j,{text:"Loading applications..."});if(!e?.length)return(0,f.jsx)(i.Text,{color:"yellow",children:"No applications found"});var l=[...e.map(e=>({label:`${e.has_unreleased_changes?"●":"○"} ${e.name}`,value:e._id,app:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Applications (",e.length,")"]}),(0,f.jsx)(T.Ay,{items:l,onSelect:t})]})},B=({app:e,loading:r,error:t,onSelect:l})=>{if(r)return(0,f.jsx)(j,{text:"Loading application..."});if(t)return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Text,{color:"red",children:["Error: ",t]}),(0,f.jsx)(T.Ay,{items:[{label:"← Back",value:"back"}],onSelect:l})]});if(!e)return(0,f.jsx)(i.Text,{color:"red",children:"Application not found"});var n=[{label:"⚡ Initialize Project",value:"project_init"},...e.short_edit?.enabled&&e.short_edit.ref_map?[{label:"Short Edit",value:"short_edit"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],o=e.devices?.length||0,a=e.devices?.filter(e=>"online"===e.status)?.length||0;return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name}),e.description&&(0,f.jsx)(i.Text,{color:"gray",children:e.description}),(0,f.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,f.jsxs)(i.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,f.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Version"}),(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Current: ",e.current_version?`v${e.current_version}`:"N/A"]}),(0,f.jsxs)(i.Text,{color:e.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",e.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]}),e.current_version_details&&(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Released: v",e.current_version_details.version||"N/A"]})]}),(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Devices"}),(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Total: ",o,o>0&&` (${a} online)`]})]}),(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Features"}),(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Short Edit: ",e.short_edit?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Canvas Control: ",e.canvas_control?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Device Control: ",e.device_control?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,f.jsxs)(i.Text,{color:e.lock?.enabled?"yellow":"gray",children:[" ","Lock: ",e.lock?.enabled?"🔒 Locked":"🔓 Unlocked"]})]}),(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,f.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,f.jsx)(T.Ay,{items:n,onSelect:l})]})},C=({modules:e,loading:r,onSelect:t})=>{if(r)return(0,f.jsx)(j,{text:"Loading modules..."});var l=[...(e||[]).map(e=>({label:`${e.current_version?"●":"○"} ${e.name}`,value:e._id,module:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Modules (",e?.length||0,")"]}),!e?.length&&(0,f.jsx)(i.Text,{color:"yellow",children:"No modules found"}),(0,f.jsx)(T.Ay,{items:l,onSelect:t})]})},k=({module:e,loading:r,error:t,onSelect:l})=>{if(r)return(0,f.jsx)(j,{text:"Loading module..."});if(t)return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Text,{color:"red",children:["Error: ",t]}),(0,f.jsx)(T.Ay,{items:[{label:"← Back",value:"back"}],onSelect:l})]});if(!e)return(0,f.jsx)(i.Text,{color:"red",children:"Module not found"});var n=[{label:"⚡ Initialize Project",value:"project_init"},...e.short_edit?.enabled&&e.short_edit.ref_map?[{label:"Short Edit",value:"short_edit"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name}),e.description&&(0,f.jsx)(i.Text,{color:"gray",children:e.description}),(0,f.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,f.jsxs)(i.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,f.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Version"}),(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Current: ",e.current_version?`v${e.current_version}`:"N/A"]}),(0,f.jsxs)(i.Text,{color:e.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",e.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]})]}),(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Usage"}),(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Used in: ",e.use_count?.total_count||0," application(s)"]})]}),(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Settings"}),(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Public: ",e.is_public?"✓ Yes":"✗ No"]}),(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Modifiable: ",e.is_allow_modify?"✓ Yes":"✗ No"]}),(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Short Edit: ",e.short_edit?.enabled?"✓ Enabled":"✗ Disabled"]})]}),e.expose_properties?.length>0&&(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Exposed Properties"}),(0,f.jsxs)(i.Text,{color:"gray",children:[" ",e.expose_properties.length," properties exposed"]})]}),(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,f.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,f.jsx)(T.Ay,{items:n,onSelect:l})]})},L=({groups:e,loading:r,onSelect:t,countdown:l,lastRefreshTime:n})=>{if(r)return(0,f.jsx)(j,{text:"Loading device groups..."});var o=[...(e||[]).map(e=>({label:`📁 ${e.name} (${e.devices?.length||0} devices)`,value:e._id,group:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Box,{marginBottom:1,children:[(0,f.jsxs)(i.Text,{bold:!0,children:["Device Groups (",e?.length||0,")"]}),(0,f.jsx)(i.Text,{color:"gray",children:" - "}),(0,f.jsx)(g,{countdown:l,lastRefreshTime:n})]}),!e?.length&&(0,f.jsx)(i.Text,{color:"yellow",children:"No device groups found"}),(0,f.jsx)(T.Ay,{items:o,onSelect:t})]})},O=({loading:e,groupDevices:r})=>e?(0,f.jsx)(j,{text:"Loading devices..."}):r?.length?(0,f.jsxs)(f.Fragment,{children:[r.slice(0,10).map(e=>(0,f.jsxs)(i.Box,{children:[(0,f.jsx)(i.Text,{color:"gray",children:" "}),(0,f.jsx)(y,{lastAliveTime:e.entry_detail?.watch_dog_timer?.last_alive_time}),(0,f.jsxs)(i.Text,{color:"gray",children:[" ",e.name||e.device_name]}),e.device_target_name&&(0,f.jsxs)(i.Text,{color:"gray",dimColor:!0,children:[" ","(",e.device_target_name,")"]})]},e._id)),r.length>10&&(0,f.jsxs)(i.Text,{color:"gray",dimColor:!0,children:[" ","... and ",r.length-10," more"]})]}):(0,f.jsx)(i.Text,{color:"gray",children:" No devices in this group"}),P=({group:e,groupDevices:r,loading:t,error:l,onSelect:n,countdown:o,lastRefreshTime:a})=>{if(t&&!e)return(0,f.jsx)(j,{text:"Loading device group..."});if(l)return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Text,{color:"red",children:["Error: ",l]}),(0,f.jsx)(T.Ay,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,f.jsx)(i.Text,{color:"red",children:"Device group not found"});return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Box,{children:[(0,f.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name}),(0,f.jsx)(i.Text,{color:"gray",children:" - "}),(0,f.jsx)(g,{countdown:o,lastRefreshTime:a})]}),e.description&&(0,f.jsx)(i.Text,{color:"gray",children:e.description}),(0,f.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,f.jsxs)(i.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,f.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsxs)(i.Text,{bold:!0,color:"white",children:["Devices (",e.devices?.length||0,")"]}),(0,f.jsx)(O,{loading:t,groupDevices:r})]}),(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,f.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,f.jsxs)(i.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,f.jsx)(T.Ay,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:n})]})},M=({boxes:e,loading:r,onSelect:t})=>{if(r)return(0,f.jsx)(j,{text:"Loading media boxes..."});if(!e?.length)return(0,f.jsx)(i.Text,{color:"yellow",children:"No media boxes found"});var l=[...e.map(e=>({label:`📦 ${e.name||"Unnamed"}`,value:e.id,box:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Media Boxes (",e.length,")"]}),(0,f.jsx)(T.Ay,{items:l,onSelect:t})]})},R=({box:e,loading:r,error:t,onSelect:l})=>{if(r&&!e)return(0,f.jsx)(j,{text:"Loading media box..."});if(t)return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Text,{color:"red",children:["Error: ",t]}),(0,f.jsx)(T.Ay,{items:[{label:"← Back",value:"back"}],onSelect:l})]});if(!e)return(0,f.jsx)(i.Text,{color:"red",children:"Media box not found"});return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name||"Unnamed"}),e.description&&(0,f.jsx)(i.Text,{color:"gray",children:e.description}),(0,f.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,f.jsxs)(i.Text,{color:"gray",children:["ID: ",e.id]}),e.tags?.length>0&&(0,f.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),null!=e.size&&(0,f.jsxs)(i.Text,{color:"gray",children:["Size: ",e.size]}),e.passcodes?.length>0&&(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsxs)(i.Text,{bold:!0,color:"white",children:["Passcodes (",e.passcodes.length,")"]}),e.passcodes.slice(0,5).map(e=>(0,f.jsxs)(i.Text,{color:"gray",children:[" ",e.name||"Passcode",": ",e.code]},e.id)),e.passcodes.length>5&&(0,f.jsxs)(i.Text,{color:"gray",dimColor:!0,children:[" ","... and ",e.passcodes.length-5," more"]})]}),(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.createdAt&&(0,f.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.createdAt).toLocaleString()]}),e.updatedAt&&(0,f.jsxs)(i.Text,{color:"gray",children:[" Modified: ",new Date(e.updatedAt).toLocaleString()]})]})]}),(0,f.jsx)(T.Ay,{items:[{label:"List Files",value:"files"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:l})]})},N=({files:e,loading:r,onSelect:t,box:l})=>{if(r)return(0,f.jsx)(j,{text:"Loading media files..."});if(!e?.length)return(0,f.jsx)(i.Text,{color:"yellow",children:"No media files found"});var n=[...e.map(e=>{return{label:`${r=e.fileType,"Image"===r?"🖼":"Video"===r?"🎞":"Audio"===r?"🎵":"📄"} ${e.name||"Unnamed"}`,value:e.id,file:e};var r}),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Media Files (",e.length,")",l?.name?` - ${l.name}`:""]}),(0,f.jsx)(T.Ay,{items:n,onSelect:t})]})},U=({file:e,loading:r,error:t,onSelect:l})=>{if(r&&!e)return(0,f.jsx)(j,{text:"Loading media file..."});if(t)return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Text,{color:"red",children:["Error: ",t]}),(0,f.jsx)(T.Ay,{items:[{label:"← Back",value:"back"}],onSelect:l})]});if(!e)return(0,f.jsx)(i.Text,{color:"red",children:"Media file not found"});var n=e.meta,o=(0,c.buildScreenshotUrl)(e),a=(0,c.buildScreenshotUrl)(e,{preferThumbnail:!0}),s=Boolean(a&&a!==o);return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name||"Unnamed"}),e.description&&(0,f.jsx)(i.Text,{color:"gray",children:e.description}),(0,f.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,f.jsxs)(i.Text,{color:"gray",children:["ID: ",e.id]}),(0,f.jsxs)(i.Text,{color:"gray",children:["Box ID: ",e.boxId]}),(0,f.jsxs)(i.Text,{color:"gray",children:["Type: ",e.fileType]}),e.userTags?.length>0&&(0,f.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.userTags.join(", ")]}),null!=n?.originalWidth&&null!=n?.originalHeight&&(0,f.jsxs)(i.Text,{color:"gray",children:["Size: ",n.originalWidth,"x",n.originalHeight]}),null!=n?.originalFileSize&&(0,f.jsxs)(i.Text,{color:"gray",children:["File: ",(Number(n.originalFileSize)/1024).toFixed(1)," KB"]}),o&&(0,f.jsxs)(i.Text,{color:"gray",children:["Original URL: ",o]}),s&&(0,f.jsxs)(i.Text,{color:"gray",children:["Thumbnail URL: ",a]}),(0,f.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,f.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.createdAt&&(0,f.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.createdAt).toLocaleString()]}),e.updatedAt&&(0,f.jsxs)(i.Text,{color:"gray",children:[" Modified: ",new Date(e.updatedAt).toLocaleString()]})]})]}),(0,f.jsx)(T.Ay,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:l})]})},$=t(77146),G=(e,r)=>{if(!e)return"";var t="string"==typeof e?e:JSON.stringify(e);return t.length>r?t.slice(0,r-1)+"…":t},F=({onBack:e})=>{var r=(0,n.useState)([]),t=o(r,2),a=t[0],c=t[1],d=(0,n.useState)(!0),u=o(d,2),x=u[0],h=u[1],m=(0,n.useState)(null),g=o(m,2),p=g[0],v=g[1];(0,n.useEffect)(()=>{var e=(0,s.getCurrentProfile)(),r=(0,s.getToken)(e),t=(0,s.getActivityLogBaseUrl)();if(!r)return v("Not logged in. Run `bricks auth login` first."),void h(!1);if(!t)return v("Activity log URL not configured."),void h(!1);var n,i=(0,$.createActivityLogClient)(t,r),o=new Date(Date.now()-36e5).toISOString(),a=(new Date).toISOString(),d=new AbortController;return(n=l(function*(){try{var e=yield i.collectEvents({start_time:o,end_time:a},{limit:50,signal:d.signal});c(e)}catch(e){"AbortError"!==e.name&&v(e.message)}h(!1)}),function(){return n.apply(this,arguments)})(),()=>d.abort()},[]);return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(i.Text,{bold:!0,marginBottom:1,children:"Activity Log (last 1h)"}),x&&(0,f.jsx)(j,{text:"Fetching events..."}),p&&(0,f.jsxs)(i.Text,{color:"red",children:["Error: ",p]}),!x&&!p&&0===a.length&&(0,f.jsx)(i.Text,{color:"yellow",children:"No events found in the last hour"}),!x&&a.length>0&&(0,f.jsxs)(i.Box,{flexDirection:"column",marginBottom:1,children:[(0,f.jsxs)(i.Text,{color:"gray",children:["Timestamp".padEnd(22)," ","Type".padEnd(12)," ","Device".padEnd(14)," ","Event Name".padEnd(24)," Sender"]}),a.map((e,r)=>{return(0,f.jsxs)(i.Text,{children:[(t=e.timestamp,new Date(t).toISOString().replace("T"," ").replace(/\.\d+Z$/,"Z")).padEnd(22)," ",G(e.event_type||"",12).padEnd(12)," ",G(e.device_id||"",14).padEnd(14)," ",G(e.event_name||"",24).padEnd(24)," ",G(e.sender||"",16)]},r);var t}),a.length>=50&&(0,f.jsxs)(i.Text,{color:"yellow",children:["Showing first ",50," events"]})]}),(0,f.jsx)(T.Ay,{items:[{label:"← Back",value:"back"}],onSelect:r=>"back"===r.value&&e()})]})},V=t(29253),H=t(35704),z=["B","C","G","D"],Y=({instanceType:e,instance:r,client:t,onDone:a,onCancel:s})=>{var c=(0,i.useApp)().exit,d=(0,n.useState)("select_ref"),u=o(d,2),x=u[0],h=u[1],m=(0,n.useState)(""),g=o(m,2),p=g[0],v=g[1],y=(0,n.useState)("search"),b=o(y,2),_=b[0],S=b[1],D=(0,n.useState)(null),E=o(D,2),I=E[0],A=E[1],w=(0,n.useState)(null),B=o(w,2),C=B[0],k=B[1],L=(0,n.useState)(""),O=o(L,2),P=O[0],M=O[1],R=(0,n.useState)(""),N=o(R,2),U=N[0],$=N[1],G=(0,n.useState)(null),F=o(G,2),Y=F[0],q=F[1],J=r?.short_edit?.ref_map||{},K=Object.entries(J).filter(([,e])=>e&&!e.hide),W=(0,H.V)(J,{keyword:p,types:z}),X=W.flatMap(e=>[{label:e.label,value:`__header_${e.prefix}__`,isHeader:!0},...e.refs.map(({shortId:e,ref:r})=>({label:`${r.title||e} (${e})`,value:e,ref:r}))]),Q=[...p?[{label:"↻ Clear Search",value:"__clear_search__"}]:[],{label:"← Back",value:"__back__"}],Z=X.length>0?[...X,...Q]:Q,ee=Z.findIndex(e=>!e.isHeader&&!e.value?.startsWith("__"));(0,i.useInput)((e,r)=>{r.tab&&"select_ref"===x?S(e=>"search"===e?"list":"search"):(r.escape&&("select_ref"===x&&s(),"input_path"===x&&h("select_ref"),"input_content"===x&&h("input_path"),"confirm"===x&&h("input_content"),"done"===x&&s()),"q"!==e||("input_path"===x||"input_content"===x)||"select_ref"===x&&"search"===_||c())},{isActive:!0});var re,te=e=>{var r=e.trim();if(""===r)return null;try{return JSON.parse(r)}catch{return r}},le=(re=l(function*(){if(t&&r?._id&&I){h("submitting"),q(null);try{var l={shortId:I,path:P.trim(),content:te(U),forwardDataLink:!0};C?.inner_ref?.pid&&(l.innerRefParentShortId=C.inner_ref.pid),"application"===e?yield t.shortEditApplication({id:r._id,list:[l]}):yield t.shortEditModule({id:r._id,list:[l]}),yield a(),h("done")}catch(e){q(e.message),h("confirm")}}}),function(){return re.apply(this,arguments)});return r?.short_edit?.enabled?0===K.length?(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(i.Text,{color:"yellow",children:"No Short Edit references found."}),(0,f.jsx)(T.Ay,{items:[{label:"← Back",value:"back"}],onSelect:s})]}):"select_ref"===x?(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(i.Text,{bold:!0,children:"Short Edit References"}),(0,f.jsx)(i.Text,{color:"gray",dimColor:!0,children:"Showing: Brick, Canvas, Generator, Data"}),(0,f.jsxs)(i.Box,{marginTop:1,flexDirection:"column",children:[(0,f.jsx)(i.Text,{color:"gray",children:"Search (title or shortId)"}),(0,f.jsx)(V.A,{value:p,placeholder:"type to filter, Enter to focus list",onChange:e=>v(e),onSubmit:()=>S("list"),focus:"search"===_}),(0,f.jsx)(i.Text,{color:"gray",dimColor:!0,children:"Press Tab to switch focus"})]}),(0,f.jsxs)(i.Box,{marginTop:1,children:[0===W.length&&(0,f.jsx)(i.Text,{color:"yellow",children:"No references match your search."}),(0,f.jsx)(T.Ay,{items:Z,isFocused:"list"===_,initialIndex:ee>-1?ee:0,indicatorComponent:()=>null,itemComponent:({label:e,isSelected:r,isHeader:t})=>t?(0,f.jsx)(i.Box,{marginTop:1,children:(0,f.jsx)(i.Text,{bold:!0,color:"white",children:e})}):(0,f.jsxs)(i.Text,{color:r?"blue":void 0,children:[r?"❯":" "," ",e]}),onSelect:e=>{if("__back__"!==e.value)return"__clear_search__"===e.value?(v(""),void S("search")):void(e.isHeader||(A(e.value),k(e.ref),h("input_path")));s()}})]})]}):"input_path"===x?(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Text,{children:["Reference:"," ",(0,f.jsxs)(i.Text,{color:"cyan",children:[C?.title||I," (",I,")"]})]}),(0,f.jsx)(i.Text,{marginTop:1,children:"Enter property path (e.g. title, property.backgroundColor)"}),Y&&(0,f.jsxs)(i.Text,{color:"red",children:["Error: ",Y]}),(0,f.jsx)(V.A,{value:P,placeholder:"path",onChange:e=>{M(e),Y&&q(null)},onSubmit:e=>{var r=e.trim();r?(M(r),h("input_content")):q("Path is required")},focus:!0})]}):"input_content"===x?(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Text,{children:["Path: ",(0,f.jsx)(i.Text,{color:"cyan",children:P})]}),(0,f.jsx)(i.Text,{marginTop:1,children:"Enter new content (JSON or plain text). Empty to clear."}),Y&&(0,f.jsxs)(i.Text,{color:"red",children:["Error: ",Y]}),(0,f.jsx)(V.A,{value:U,placeholder:"content",onChange:e=>{$(e),Y&&q(null)},onSubmit:()=>h("confirm"),focus:!0})]}):"submitting"===x?(0,f.jsx)(j,{text:"Applying short edit..."}):"done"===x?(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(i.Text,{color:"green",children:"Short edit applied successfully."}),(0,f.jsx)(T.Ay,{items:[{label:"Edit another property",value:"again"},{label:"← Back",value:"back"}],onSelect:e=>{"again"===e.value?(h("select_ref"),A(null),k(null),M(""),$(""),q(null)):s()}})]}):(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(i.Text,{bold:!0,marginBottom:1,children:"Confirm Short Edit"}),(0,f.jsxs)(i.Text,{children:["Reference:"," ",(0,f.jsxs)(i.Text,{color:"cyan",children:[C?.title||I," (",I,")"]})]}),(0,f.jsxs)(i.Text,{children:["Path: ",(0,f.jsx)(i.Text,{color:"cyan",children:P})]}),(0,f.jsxs)(i.Text,{children:["Content: ",(0,f.jsx)(i.Text,{color:"cyan",children:U||"<empty>"})]}),Y&&(0,f.jsxs)(i.Text,{color:"red",children:["Error: ",Y]}),(0,f.jsx)(T.Ay,{items:[{label:"Apply",value:"apply"},{label:"Edit Path",value:"edit_path"},{label:"Edit Content",value:"edit_content"},{label:"← Back",value:"back"}],onSelect:e=>{"apply"===e.value&&le(),"edit_path"===e.value&&h("input_path"),"edit_content"===e.value&&h("input_content"),"back"===e.value&&s()}})]}):(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Text,{color:"yellow",children:["Short Edit is not enabled for this ",e,"."]}),(0,f.jsx)(T.Ay,{items:[{label:"← Back",value:"back"}],onSelect:s})]})},q=t(16928),J=t(79896),K=t(10750),W=t(18050),X="options",Q="output_dir",Z="confirm",ee="generating",re="post_install",te="done",le=({type:e,instance:r,client:t,onDone:a,onCancel:s})=>{var c,d=(0,i.useApp)().exit,u=(0,n.useState)(X),x=o(u,2),m=x[0],g=x[1],p=(0,n.useState)({setupGitHubActions:!0,setupAgents:!0,setupClaudeCode:!0,setupGeminiCLI:!1,runBunInstall:!0,initGit:!0}),v=o(p,2),j=v[0],y=v[1],b=(0,n.useState)(process.cwd()),_=o(b,2),S=_[0],D=_[1],E=(0,n.useState)(""),I=o(E,2),A=I[0],w=I[1],B=(0,n.useState)(null),C=o(B,2),k=C[0],L=C[1],O=(0,n.useState)(null),P=o(O,2),M=P[0],R=P[1],N=K(r?.name||"bricks-ctor"),U=q.resolve(S,N),$=(0,n.useCallback)(e=>{"back"!==e.value?"continue"!==e.value?y(r=>({...r,[e.value]:!r[e.value]})):g(Q):s()},[s]),G=(0,n.useCallback)(()=>{J.existsSync(U)?L(`Directory already exists: ${U}`):(L(null),g(Z))},[U]),F=(0,n.useCallback)((c=l(function*(l){if("back"!==l.value)if("cancel"!==l.value){if("confirm"===l.value){g(ee);try{w("Fetching project from BRICKS...");var n="application"===e,i=n?"applicationProject":"moduleProject",o=n?t.queries.applicationProject:t.queries.moduleProject,a=(yield t.query(o,{id:r._id,buildApplicationOnly:!1,setupGitHubActions:j.setupGitHubActions,setupAgents:j.setupAgents,setupClaudeCode:j.setupClaudeCode,setupGeminiCLI:j.setupGeminiCLI}))[i];if(!a?.files)throw new Error("Failed to fetch project files");w("Creating project directory..."),J.mkdirSync(U,{recursive:!0}),w(`Writing ${a.files.length} files...`);var c=yield(0,W.KN)(a.files,U);(0,W.oz)(c),g(re);var d={path:U,files:a.files.length,bunInstalled:!1,gitInitialized:!1};Object.assign(d,yield(0,W.o0)(U,{install:j.runBunInstall,git:j.initGit,onStatus:w})),R(d),g(te)}catch(e){L(e.message),g(X)}}}else s();else g(Q)}),function(e){return c.apply(this,arguments)}),[t,r,e,j,U,s]),H=(0,n.useCallback)(e=>{"exit"===e.value?d():a()},[d,a]);if(m===X){var z=[{label:(j.setupGitHubActions?"[x]":"[ ]")+" GitHub Actions workflow",value:"setupGitHubActions"},{label:(j.setupAgents?"[x]":"[ ]")+" AGENTS.md",value:"setupAgents"},{label:(j.setupClaudeCode?"[x]":"[ ]")+" CLAUDE.md",value:"setupClaudeCode"},{label:(j.setupGeminiCLI?"[x]":"[ ]")+" GEMINI.md",value:"setupGeminiCLI"},{label:(j.runBunInstall?"[x]":"[ ]")+" Run bun install after generation",value:"runBunInstall"},{label:(j.initGit?"[x]":"[ ]")+" Initialize git repository",value:"initGit"},{label:"→ Continue",value:"continue"},{label:"← Back",value:"back"}];return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsxs)(i.Text,{bold:!0,color:"cyan",children:["Initialize BRICKS Project: ",r?.name||"Untitled"]}),(0,f.jsx)(i.Text,{color:"gray",marginBottom:1,children:"Select options for project generation (press Enter to toggle)"}),k&&(0,f.jsxs)(i.Text,{color:"red",marginBottom:1,children:["Error: ",k]}),(0,f.jsx)(T.Ay,{items:z,onSelect:$})]})}if(m===Q)return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(i.Text,{bold:!0,color:"cyan",children:"Output Directory"}),(0,f.jsx)(i.Text,{color:"gray",marginBottom:1,children:"Enter the parent directory for the project:"}),k&&(0,f.jsx)(i.Text,{color:"red",marginBottom:1,children:k}),(0,f.jsxs)(i.Box,{children:[(0,f.jsx)(i.Text,{children:"Directory: "}),(0,f.jsx)(V.A,{value:S,onChange:D,onSubmit:G})]}),(0,f.jsxs)(i.Text,{color:"gray",marginTop:1,children:["Project will be created at: ",U]})]});if(m===Z){return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(i.Text,{bold:!0,color:"cyan",children:"Confirm Project Generation"}),(0,f.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,f.jsxs)(i.Text,{children:["Name: ",(0,f.jsx)(i.Text,{color:"green",children:r?.name||"Untitled"})]}),(0,f.jsxs)(i.Text,{children:["Type: ",(0,f.jsx)(i.Text,{color:"yellow",children:e})]}),(0,f.jsxs)(i.Text,{children:["Path: ",(0,f.jsx)(i.Text,{color:"cyan",children:U})]}),(0,f.jsx)(i.Text,{color:"gray",marginTop:1,children:"Options:"}),(0,f.jsxs)(i.Text,{color:"gray",children:[" - GitHub Actions: ",j.setupGitHubActions?"Yes":"No"]}),(0,f.jsxs)(i.Text,{color:"gray",children:[" - AGENTS.md: ",j.setupAgents?"Yes":"No"]}),(0,f.jsxs)(i.Text,{color:"gray",children:[" - CLAUDE.md: ",j.setupClaudeCode?"Yes":"No"]}),(0,f.jsxs)(i.Text,{color:"gray",children:[" - GEMINI.md: ",j.setupGeminiCLI?"Yes":"No"]}),(0,f.jsxs)(i.Text,{color:"gray",children:[" - Run bun install: ",j.runBunInstall?"Yes":"No"]}),(0,f.jsxs)(i.Text,{color:"gray",children:[" - Initialize git: ",j.initGit?"Yes":"No"]})]}),(0,f.jsx)(T.Ay,{items:[{label:"Confirm & Generate",value:"confirm"},{label:"← Change Directory",value:"back"},{label:"Cancel",value:"cancel"}],onSelect:F})]})}if(m===ee||m===re)return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(i.Text,{bold:!0,color:"cyan",children:"Generating Project..."}),(0,f.jsxs)(i.Box,{marginY:1,children:[(0,f.jsx)(i.Text,{color:"green",children:(0,f.jsx)(h.A,{type:"dots"})}),(0,f.jsxs)(i.Text,{children:[" ",A]})]})]});if(m===te&&M){return(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(i.Text,{bold:!0,color:"green",children:"Project initialized successfully!"}),(0,f.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,f.jsxs)(i.Text,{children:["Path: ",(0,f.jsx)(i.Text,{color:"cyan",children:M.path})]}),(0,f.jsxs)(i.Text,{children:["Files: ",(0,f.jsx)(i.Text,{color:"green",children:M.files})]}),(0,f.jsxs)(i.Text,{children:["Dependencies:"," ",(0,f.jsx)(i.Text,{color:M.bunInstalled?"green":"yellow",children:M.bunInstalled?"Installed":"Not installed (run bun install manually)"})]}),(0,f.jsxs)(i.Text,{children:["Git:"," ",(0,f.jsx)(i.Text,{color:M.gitInitialized?"green":"yellow",children:M.gitInitialized?"Initialized":"Not initialized"})]})]}),(0,f.jsx)(i.Text,{bold:!0,marginY:1,children:"Next steps:"}),(0,f.jsxs)(i.Text,{color:"gray",children:[" cd ",N]}),!M.bunInstalled&&(0,f.jsx)(i.Text,{color:"gray",children:" bun install"}),(0,f.jsx)(i.Text,{color:"gray",children:" bun preview"}),(0,f.jsxs)(i.Text,{color:"gray",marginTop:1,children:["For more information, see ",N,"/README.md"]}),(0,f.jsx)(i.Box,{marginTop:1,children:(0,f.jsx)(T.Ay,{items:[{label:"← Back to Detail",value:"back"},{label:"Exit CLI",value:"exit"}],onSelect:H})})]})}return null};const ne=()=>{var e=(0,i.useApp)().exit,r=(0,n.useState)(d.MAIN),t=o(r,2),u=t[0],x=t[1],h=(0,n.useState)(null),g=o(h,2),y=g[0],T=g[1],_=(0,n.useState)(null),S=o(_,2),O=S[0],$=S[1],G=(0,n.useState)(!0),V=o(G,2),H=V[0],z=V[1],q=(0,n.useState)(null),J=o(q,2),K=J[0],W=J[1],X=(0,n.useState)([]),Q=o(X,2),Z=Q[0],ee=Q[1],re=(0,n.useState)(null),te=o(re,2),ne=te[0],ie=te[1],oe=(0,n.useState)([]),ae=o(oe,2),se=ae[0],ce=ae[1],de=(0,n.useState)(null),ue=o(de,2),xe=ue[0],he=ue[1],fe=(0,n.useState)([]),me=o(fe,2),ge=me[0],pe=me[1],ve=(0,n.useState)(null),je=o(ve,2),ye=je[0],Te=je[1],be=(0,n.useState)([]),_e=o(be,2),Se=_e[0],De=_e[1],Ee=(0,n.useState)(null),Ie=o(Ee,2),Ae=Ie[0],we=Ie[1],Be=(0,n.useState)([]),Ce=o(Be,2),ke=Ce[0],Le=Ce[1],Oe=(0,n.useState)(!1),Pe=o(Oe,2),Me=Pe[0],Re=Pe[1],Ne=(0,n.useState)(null),Ue=o(Ne,2),$e=Ue[0],Ge=Ue[1],Fe=(0,n.useState)(null),Ve=o(Fe,2),He=Ve[0],ze=Ve[1],Ye=(0,n.useState)(null),qe=o(Ye,2),Je=qe[0],Ke=qe[1],We=(0,n.useState)(null),Xe=o(We,2),Qe=Xe[0],Ze=Xe[1],er=(0,n.useState)([]),rr=o(er,2),tr=rr[0],lr=rr[1],nr=(0,n.useState)(null),ir=o(nr,2),or=ir[0],ar=ir[1],sr=(0,n.useState)([]),cr=o(sr,2),dr=cr[0],ur=cr[1],xr=(0,n.useState)(null),hr=o(xr,2),fr=hr[0],mr=hr[1],gr=u===d.DEVICES,pr=u===d.DEVICE_DETAIL,vr=u===d.GROUPS,jr=u===d.GROUP_DETAIL;(0,n.useEffect)(()=>{var e=(0,s.getCurrentProfile)(),r=(0,s.getToken)(e);if(!r)return W("Not logged in. Run `bricks auth login` first."),void z(!1);var t=(0,a.createClient)((0,s.getBaseUrl)(),r);T(t),t.workspace().then(e=>{$(e),z(!1)}).catch(e=>{W(e.message),z(!1)})},[]),(0,i.useInput)((r,t)=>{"q"===r&&e(),t.escape&&(u===d.DEVICE_CONTROL?(x(d.DEVICE_DETAIL),Ge(null)):u===d.DEVICE_SCREENSHOT?(x(d.DEVICE_DETAIL),Ke(null),Ze(null)):u===d.DEVICE_DETAIL?(x(d.DEVICES),ie(null)):u===d.APP_DETAIL?(x(d.APPS),he(null)):u===d.MODULE_DETAIL?(x(d.MODULES),Te(null)):u===d.GROUP_DETAIL?(x(d.GROUPS),we(null),Le([])):u===d.MEDIA_FILE_DETAIL?(x(d.MEDIA_FILES),mr(null)):u===d.MEDIA_FILES?(x(d.MEDIA_BOX_DETAIL),mr(null)):u===d.MEDIA_BOX_DETAIL?(x(d.MEDIA_BOXES),ar(null),ur([])):(u===d.MEDIA_BOXES||u!==d.MAIN)&&x(d.MAIN))},{isActive:u!==d.APP_SHORT_EDIT&&u!==d.MODULE_SHORT_EDIT&&u!==d.APP_PROJECT_INIT&&u!==d.MODULE_PROJECT_INIT});var yr,Tr,br,_r,Sr,Dr,Er,Ir,Ar=(0,n.useCallback)(l(function*(){if(y){z(!0);try{var e=yield y.devices({});ee(e||[])}catch(e){W(e.message)}z(!1)}}),[y]),wr=(0,n.useCallback)((yr=l(function*(e){if(y){z(!0),ze(null);try{var r=yield y.device({id:e});ie(r)}catch(e){ze(e.message)}z(!1)}}),function(e){return yr.apply(this,arguments)}),[y]),Br=(0,n.useCallback)(l(function*(){if(y){z(!0);try{var e=yield y.applications({});ce(e||[])}catch(e){W(e.message)}z(!1)}}),[y]),Cr=(0,n.useCallback)((Tr=l(function*(e){if(y){z(!0),ze(null);try{var r=yield y.application({id:e});he(r)}catch(e){ze(e.message)}z(!1)}}),function(e){return Tr.apply(this,arguments)}),[y]),kr=(0,n.useCallback)(l(function*(){if(y){z(!0);try{var e=yield y.modules({});pe(e||[])}catch(e){W(e.message)}z(!1)}}),[y]),Lr=(0,n.useCallback)((br=l(function*(e){if(y){z(!0),ze(null);try{var r=yield y.module({id:e});Te(r)}catch(e){ze(e.message)}z(!1)}}),function(e){return br.apply(this,arguments)}),[y]),Or=(0,n.useCallback)(l(function*(){if(y){z(!0);try{var e=yield y.deviceGroups({});De(e||[])}catch(e){W(e.message)}z(!1)}}),[y]),Pr=(0,n.useCallback)((_r=l(function*(e){if(y){z(!0),ze(null);try{var r=yield Promise.all([y.deviceGroup({id:e}),y.devicesByGroup({id:e})]),t=o(r,2),l=t[0],n=t[1];we(l),Le(n||[])}catch(e){ze(e.message)}z(!1)}}),function(e){return _r.apply(this,arguments)}),[y]),Mr=(0,n.useCallback)(l(function*(){if(y){z(!0);try{var e=yield y.mediaBoxes();lr(e||[])}catch(e){W(e.message)}z(!1)}}),[y]),Rr=(0,n.useCallback)((Sr=l(function*(e){if(y){z(!0),ze(null);try{var r=yield y.mediaBox({id:e});ar(r)}catch(e){ze(e.message)}z(!1)}}),function(e){return Sr.apply(this,arguments)}),[y]),Nr=(0,n.useCallback)((Dr=l(function*(e){if(y){z(!0);try{var r=yield y.mediaFiles({boxId:e});ur(r||[])}catch(e){W(e.message)}z(!1)}}),function(e){return Dr.apply(this,arguments)}),[y]),Ur=(0,n.useCallback)((Er=l(function*(e){if(y){z(!0),ze(null);try{var r=yield y.mediaFile({id:e});mr(r)}catch(e){ze(e.message)}z(!1)}}),function(e){return Er.apply(this,arguments)}),[y]),$r=(0,n.useCallback)((Ir=l(function*(e){if(y&&ne){Re(!0),Ge(null);try{yield y.controlDevice({id:ne._id,type:e}),Ge({success:!0,message:`Command sent: ${e}`})}catch(e){Ge({success:!1,message:e.message})}Re(!1)}}),function(e){return Ir.apply(this,arguments)}),[y,ne]),Gr=(0,n.useCallback)(l(function*(e=!1){if(y&&ne&&O){z(!0),Ze(null),Ke(null);try{e&&(yield y.controlDevice({id:ne._id,type:"take-screenshot"}),yield new Promise(e=>setTimeout(e,3e3)));var r=yield(0,c.fetchAndSaveScreenshot)(y,O,ne._id,null,{preferThumbnail:!0});r.error?Ze(r.error):Ke(r)}catch(e){Ze(e.message)}z(!1)}}),[y,ne,O]),Fr=m((0,n.useCallback)(()=>{y&&Ar()},[y,Ar]),gr),Vr=m((0,n.useCallback)(()=>{y&&ne&&wr(ne._id)},[y,ne,wr]),pr),Hr=m((0,n.useCallback)(()=>{y&&Or()},[y,Or]),vr),zr=m((0,n.useCallback)(()=>{y&&Ae&&Pr(Ae._id)},[y,Ae,Pr]),jr);return H&&!O?(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(p,{workspace:O,view:u}),(0,f.jsx)(j,{text:"Connecting to workspace..."})]}):K&&!O?(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(p,{workspace:O,view:u}),(0,f.jsxs)(i.Text,{color:"red",children:["Error: ",K]}),(0,f.jsx)(v,{})]}):(0,f.jsxs)(i.Box,{flexDirection:"column",children:[(0,f.jsx)(p,{workspace:O,view:u}),u===d.MAIN&&(0,f.jsx)(b,{onSelect:r=>{"exit"!==r.value?(x(r.value),r.value===d.DEVICES?Ar():r.value===d.APPS?Br():r.value===d.MODULES?kr():r.value===d.GROUPS?Or():r.value===d.MEDIA_BOXES&&Mr()):e()},mediaEnabled:(0,c.isMediaEnabled)(O),activityLogEnabled:!!(0,s.getActivityLogBaseUrl)()}),u===d.DEVICES&&(0,f.jsx)(D,{devices:Z,loading:H,onSelect:e=>{if("back"!==e.value){if("refresh"===e.value)return Ar(),void Fr.resetCountdown();ie(null),z(!0),x(d.DEVICE_DETAIL),wr(e.value)}else x(d.MAIN)},countdown:Fr.countdown,lastRefreshTime:Fr.lastRefreshTime}),u===d.DEVICE_DETAIL&&(0,f.jsx)(E,{device:ne,loading:H,error:He,onSelect:e=>"back"===e.value?(x(d.DEVICES),void ie(null)):"refresh"===e.value?(wr(ne._id),void Vr.resetCountdown()):("control"===e.value&&(x(d.DEVICE_CONTROL),Ge(null)),void("screenshot"===e.value&&(x(d.DEVICE_SCREENSHOT),Ke(null),Ze(null),Gr(!1)))),mediaEnabled:(0,c.isMediaEnabled)(O),countdown:Vr.countdown,lastRefreshTime:Vr.lastRefreshTime}),u===d.DEVICE_CONTROL&&(0,f.jsx)(I,{device:ne,onSelect:e=>{if("back"===e.value)return x(d.DEVICE_DETAIL),void Ge(null);$r(e.value)},controlling:Me,controlResult:$e}),u===d.DEVICE_SCREENSHOT&&(0,f.jsx)(A,{device:ne,screenshot:Je,loading:H,error:Qe,onSelect:e=>{if("back"===e.value)return x(d.DEVICE_DETAIL),Ke(null),void Ze(null);"refresh"!==e.value?"take"===e.value&&Gr(!0):Gr(!1)}}),u===d.APPS&&(0,f.jsx)(w,{apps:se,loading:H,onSelect:e=>{"back"!==e.value?"refresh"!==e.value?(he(null),z(!0),x(d.APP_DETAIL),Cr(e.value)):Br():x(d.MAIN)}}),u===d.APP_DETAIL&&(0,f.jsx)(B,{app:xe,loading:H,error:He,onSelect:e=>{if("back"===e.value)return x(d.APPS),void he(null);"refresh"!==e.value?("short_edit"===e.value&&(x(d.APP_SHORT_EDIT),ze(null)),"project_init"===e.value&&(x(d.APP_PROJECT_INIT),ze(null))):Cr(xe._id)}}),u===d.APP_SHORT_EDIT&&(0,f.jsx)(Y,{instanceType:"application",instance:xe,client:y,onDone:l(function*(){return Cr(xe._id)}),onCancel:()=>x(d.APP_DETAIL)}),u===d.APP_PROJECT_INIT&&(0,f.jsx)(le,{type:"application",instance:xe,client:y,onDone:()=>x(d.APP_DETAIL),onCancel:()=>x(d.APP_DETAIL)}),u===d.MODULES&&(0,f.jsx)(C,{modules:ge,loading:H,onSelect:e=>{"back"!==e.value?"refresh"!==e.value?(Te(null),z(!0),x(d.MODULE_DETAIL),Lr(e.value)):kr():x(d.MAIN)}}),u===d.MODULE_DETAIL&&(0,f.jsx)(k,{module:ye,loading:H,error:He,onSelect:e=>{if("back"===e.value)return x(d.MODULES),void Te(null);"refresh"!==e.value?("short_edit"===e.value&&(x(d.MODULE_SHORT_EDIT),ze(null)),"project_init"===e.value&&(x(d.MODULE_PROJECT_INIT),ze(null))):Lr(ye._id)}}),u===d.MODULE_SHORT_EDIT&&(0,f.jsx)(Y,{instanceType:"module",instance:ye,client:y,onDone:l(function*(){return Lr(ye._id)}),onCancel:()=>x(d.MODULE_DETAIL)}),u===d.MODULE_PROJECT_INIT&&(0,f.jsx)(le,{type:"module",instance:ye,client:y,onDone:()=>x(d.MODULE_DETAIL),onCancel:()=>x(d.MODULE_DETAIL)}),u===d.GROUPS&&(0,f.jsx)(L,{groups:Se,loading:H,onSelect:e=>{if("back"!==e.value){if("refresh"===e.value)return Or(),void Hr.resetCountdown();we(null),Le([]),z(!0),x(d.GROUP_DETAIL),Pr(e.value)}else x(d.MAIN)},countdown:Hr.countdown,lastRefreshTime:Hr.lastRefreshTime}),u===d.GROUP_DETAIL&&(0,f.jsx)(P,{group:Ae,groupDevices:ke,loading:H,error:He,onSelect:e=>{if("back"===e.value)return x(d.GROUPS),we(null),void Le([]);"refresh"===e.value&&(Pr(Ae._id),zr.resetCountdown())},countdown:zr.countdown,lastRefreshTime:zr.lastRefreshTime}),u===d.ACTIVITY_LOG&&(0,f.jsx)(F,{onBack:()=>x(d.MAIN)}),u===d.MEDIA_BOXES&&(0,f.jsx)(M,{boxes:tr,loading:H,onSelect:e=>{"back"!==e.value?"refresh"!==e.value?(ar(null),ur([]),z(!0),x(d.MEDIA_BOX_DETAIL),Rr(e.value)):Mr():x(d.MAIN)}}),u===d.MEDIA_BOX_DETAIL&&(0,f.jsx)(R,{box:or,loading:H,error:He,onSelect:e=>{if("back"===e.value)return x(d.MEDIA_BOXES),ar(null),void ur([]);"refresh"!==e.value?"files"===e.value&&(ur([]),mr(null),x(d.MEDIA_FILES),Nr(or.id)):Rr(or.id)}}),u===d.MEDIA_FILES&&(0,f.jsx)(N,{files:dr,box:or,loading:H,onSelect:e=>{if("back"===e.value)return x(d.MEDIA_BOX_DETAIL),void mr(null);"refresh"!==e.value?(mr(null),z(!0),x(d.MEDIA_FILE_DETAIL),Ur(e.value)):Nr(or.id)}}),u===d.MEDIA_FILE_DETAIL&&(0,f.jsx)(U,{file:fr,loading:H,error:He,onSelect:e=>{if("back"===e.value)return x(d.MEDIA_FILES),void mr(null);"refresh"===e.value&&Ur(fr.id)}}),(0,f.jsx)(v,{})]})};var ie,oe="1"===process.env.BRICKS_CLI_DISTRIBUTION,ae=(ie=l(function*(){if(oe)(0,i.render)((0,f.jsx)(ne,{}));else{var e=(yield Promise.resolve().then(t.bind(t,29557))).TerminalInfoProvider;(0,i.render)((0,f.jsx)(e,{children:(0,f.jsx)(ne,{})}))}}),function(){return ie.apply(this,arguments)})},47336:(e,r,t)=>{t.r(r),t.d(r,{buildScreenshotUrl:()=>f,downloadScreenshot:()=>m,fetchAndSaveScreenshot:()=>g,getDeviceScreenshot:()=>h,getSystemMediaBoxId:()=>x,isMediaEnabled:()=>u});var l,n,i,o=t(99436),a=t(79657),s=t(73024),c=t(76760),d=t(48161),u=e=>!0===e?.media_resource?.enable_media_workspace,x=e=>u(e)&&e.media_resource?.system_media_box_id||null,h=(l=o(function*(e,r,t){var l=yield e.mediaFiles({boxId:r,userTags:[`bricks_screenshot_${t}`],limit:1});return l?.[0]||null}),function(e,r,t){return l.apply(this,arguments)}),f=(e,{preferThumbnail:r=!1}={})=>{if(!e?.meta?.storageEndpoint)return null;var t=e.meta,l=t.storageEndpoint,n=t.originalFileKey,i=r?(e=>{var r=e?.meta;if(!r)return null;if("Video"===e.fileType&&r.videoThumbOriginalFileKey)return r.videoThumbOriginalFileKey;var t=r.imageVersions||[];if(!Array.isArray(t)||0===t.length)return null;var l=t.filter(e=>"BOUNDED"===e?.strategy&&"number"==typeof e.width).sort((e,r)=>e.width-r.width);return(l[0]||t[0])?.key||null})(e):null,o=i||n;return o?`${l}/${o}`:null},m=(n=o(function*(e,r=null){var t=yield(0,a.Ay)(e);if(!t.ok)throw new Error(`Failed to download screenshot: ${t.statusText}`);var l=yield t.buffer(),n=r||c.join(d.tmpdir(),`bricks-screenshot-${Date.now()}.png`),i=c.dirname(n);return s.existsSync(i)||s.mkdirSync(i,{recursive:!0}),s.writeFileSync(n,l),n}),function(e){return n.apply(this,arguments)}),g=(i=o(function*(e,r,t,l=null,n={}){var i=x(r);if(!i)return{error:"Media workspace not enabled for this workspace"};var o=yield h(e,i,t);if(!o)return{error:"No screenshot available for this device"};var a=f(o,n);return a?{path:yield m(a,l),file:o,url:a}:{error:"Could not build screenshot URL"}}),function(e,r,t){return i.apply(this,arguments)})},77146:(e,r,t)=>{t.d(r,{ActivityLogClient:()=>y,createActivityLogClient:()=>T}),t.r(r);var l=t(99436),n=t(5018),i=t(44668),o=t(4275),a=t(32235),s=t(62192),c=t(79657),d=t(64007);function u(e){var r,t,l,n=2;for("undefined"!=typeof Symbol&&(t=Symbol.asyncIterator,l=Symbol.iterator);n--;){if(t&&null!=(r=e[t]))return r.call(e);if(l&&null!=(r=e[l]))return new x(r.call(e));t="@@asyncIterator",l="@@iterator"}throw new TypeError("Object is not async iterable")}function x(e){function r(e){if(Object(e)!==e)return Promise.reject(new TypeError(e+" is not an object."));var r=e.done;return Promise.resolve(e.value).then(function(e){return{value:e,done:r}})}return x=function(e){this.s=e,this.n=e.next},x.prototype={s:null,n:null,next:function(){return r(this.n.apply(this.s,arguments))},return:function(e){var t=this.s.return;return void 0===t?Promise.resolve({value:e,done:!0}):r(t.apply(this.s,arguments))},throw:function(e){var t=this.s.return;return void 0===t?Promise.reject(e):r(t.apply(this.s,arguments))}},new x(e)}function*h(e){if(e.errors?.length)throw new Error(e.errors.map(e=>e.message).join("\n"));if(e.data)for(var r of Object.values(e.data))if(Array.isArray(r))for(var t of r)yield t;if(Array.isArray(e.incremental))for(var l of e.incremental)if(Array.isArray(l.items))for(var n of l.items)yield n}function f(){return(f=o(function*(e){var r=e.headers.get("content-type")||"";if(r.includes("application/json")){var t=yield a(e.json());if(t.errors?.length)throw new Error(t.errors.map(e=>e.message).join("\n"));var l=Object.keys(t.data||{})[0];if(l&&Array.isArray(t.data[l]))for(var n of t.data[l])yield n}else{var i=r.match(/boundary="?([^";]+)"?/),o=`--${i?i[1]:"-"}`,c="",d=!1,x=new TextDecoder,f=e=>{for(var r=0;-1!==(r=e.indexOf(o,r));){if(0===r||"\n"===e[r-1])return r;r+=o.length}return-1},m=function*(){for(var e;-1!==(e=f(c));){var r=c.slice(0,e);(c=c.slice(e+o.length)).startsWith("\r\n")?c=c.slice(2):c.startsWith("\n")&&(c=c.slice(1));var t=r.indexOf("\r\n\r\n"),l=-1!==t?r.slice(t+4).trim():r.trim();if(l){var n=void 0;try{n=JSON.parse(l)}catch{continue}if(yield*h(n),!1===n.hasNext)return void(d=!0)}}};try{var g,p=!1,v=!1;try{for(var j,y=u(e.body);p=!(j=yield a(y.next())).done;p=!1){var T=j.value;if(c+=x.decode(T,{stream:!0}),yield*s(u(m()),a),d)break}}catch(e){v=!0,g=e}finally{try{p&&null!=y.return&&(yield a(y.return()))}finally{if(v)throw g}}}catch(e){if(!e.message?.includes("Premature close")||!d)throw e}if(!d&&c.trim()){var b=c.indexOf("\r\n\r\n"),_=-1!==b?c.slice(b+4).trim():c.trim();if(_&&!_.startsWith("--")){var S;try{S=JSON.parse(_)}catch{}S&&(yield*s(u(h(S)),a),!1===S.hasNext&&(d=!0))}}e.body?.destroy()}})).apply(this,arguments)}function m(e){var r,t,l,n=2;for("undefined"!=typeof Symbol&&(t=Symbol.asyncIterator,l=Symbol.iterator);n--;){if(t&&null!=(r=e[t]))return r.call(e);if(l&&null!=(r=e[l]))return new g(r.call(e));t="@@asyncIterator",l="@@iterator"}throw new TypeError("Object is not async iterable")}function g(e){function r(e){if(Object(e)!==e)return Promise.reject(new TypeError(e+" is not an object."));var r=e.done;return Promise.resolve(e.value).then(function(e){return{value:e,done:r}})}return g=function(e){this.s=e,this.n=e.next},g.prototype={s:null,n:null,next:function(){return r(this.n.apply(this.s,arguments))},return:function(e){var t=this.s.return;return void 0===t?Promise.resolve({value:e,done:!0}):r(t.apply(this.s,arguments))},throw:function(e){var t=this.s.return;return void 0===t?Promise.reject(e):r(t.apply(this.s,arguments))}},new g(e)}var p,v,j,y=i(function e(r,t){n(this,e),this.baseUrl=r,this.token=t,this.graphqlUrl=`${r}/api/graphql`,this.fetch=function(e){var r=process.env.HTTPS_PROXY||process.env.https_proxy;if(!r||!e.startsWith("https://"))return c.Ay;var t=new d(r);return(e,r={})=>(0,c.Ay)(e,{...r,agent:t})}(r)},[{key:"streamQuery",value:function(e,r){var t=this;return o(function*(e,r,{signal:l}={}){var n=yield a(t.fetch(t.graphqlUrl,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t.token}`,Accept:'multipart/mixed; boundary="-", application/json'},body:JSON.stringify({query:e,variables:r}),signal:l}));if(!n.ok){var i=yield a(n.text().catch(()=>""));throw new Error(`Activity-log query failed (${n.status}): ${i}`)}yield*s(m(function(e){return f.apply(this,arguments)}(n)),a)}).apply(this,arguments)}},{key:"events",value:function(e,r){var t=this;return o(function*(){yield*s(m(t.streamQuery("\n query AL_events($filter: EventsFilter!) {\n events(filter: $filter) @stream {\n device_id\n event_type\n event_name\n subspace_id\n sender\n payload\n timestamp\n }\n }\n",{filter:e},r)),a)})()}},{key:"screenshots",value:function(e,r){var t=this;return o(function*(){yield*s(m(t.streamQuery("\n query AL_screenshots($filter: ScreenshotFilter!) {\n screenshots(filter: $filter) @stream {\n timestamp\n }\n }\n",{filter:e},r)),a)})()}},{key:"collectEvents",value:(j=l(function*(e,{limit:r,signal:t}={}){var l,n=[],i=!1,o=!1;try{for(var a,s=m(this.events(e,{signal:t}));i=!(a=yield s.next()).done;i=!1){var c=a.value;if(n.push(c),r&&n.length>=r)break}}catch(e){o=!0,l=e}finally{try{i&&null!=s.return&&(yield s.return())}finally{if(o)throw l}}return n}),function(e){return j.apply(this,arguments)})},{key:"collectScreenshots",value:(v=l(function*(e,{signal:r}={}){var t,l=[],n=!1,i=!1;try{for(var o,a=m(this.screenshots(e,{signal:r}));n=!(o=yield a.next()).done;n=!1){var s=o.value;l.push(s)}}catch(e){i=!0,t=e}finally{try{n&&null!=a.return&&(yield a.return())}finally{if(i)throw t}}return l}),function(e){return v.apply(this,arguments)})},{key:"downloadScreenshot",value:(p=l(function*(e,r,t,{signal:l}={}){var n=`${this.baseUrl}/api/v1/${encodeURIComponent(e)}/${encodeURIComponent(r)}/screenshot?ts=${encodeURIComponent(t)}`,i=yield this.fetch(n,{headers:{Authorization:`Bearer ${this.token}`},signal:l});if(!i.ok){var o=yield i.text().catch(()=>"");throw new Error(`Screenshot fetch failed (${i.status}): ${o}`)}return Buffer.from(yield i.arrayBuffer())}),function(e,r,t){return p.apply(this,arguments)})}]),T=(e,r)=>new y(e,r)}};